faq.qbk 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. [/===========================================================================
  2. Copyright (c) 2013-2015 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. Distributed under the Boost Software License, Version 1.0
  4. See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt
  6. =============================================================================/]
  7. [section:faq Frequently Asked Questions]
  8. [h3 How do I report a bug, issue, or feature request?]
  9. Please submit an issue on the GitHub issue tracker at
  10. [@https://github.com/boostorg/compute/issues].
  11. [h3 Where can I find more documentation?]
  12. * The main documentation is here: [@http://boostorg.github.io/compute/]
  13. * The README is here: [@https://github.com/boostorg/compute/blob/master/README.md]
  14. * The wiki is here: [@https://github.com/boostorg/compute/wiki]
  15. * The contributor guide is here: [@https://github.com/boostorg/compute/blob/master/CONTRIBUTING.md]
  16. * The reference is here: [@http://boostorg.github.io/compute/compute/reference.html]
  17. [h3 Where is the best place to ask questions about the library?]
  18. The mailing list at [@https://groups.google.com/forum/#!forum/boost-compute].
  19. [h3 What compute devices (e.g. GPUs) are supported?]
  20. Any device which implements the OpenCL standard is supported. This includes
  21. GPUs from NVIDIA, AMD, and Intel as well as CPUs from AMD and Intel and other
  22. accelerator cards such as the Xeon Phi.
  23. [h3 Can you compare Boost.Compute to other GPGPU libraries such as Thrust,
  24. Bolt and VexCL?]
  25. Thrust implements a C++ STL-like API for GPUs and CPUs. It is built
  26. with multiple backends. NVIDIA GPUs use the CUDA backend and
  27. multi-core CPUs can use the Intel TBB or OpenMP backends. However,
  28. thrust will not work with AMD graphics cards or other lesser-known
  29. accelerators. I feel Boost.Compute is superior in that it uses the
  30. vendor-neutral OpenCL library to achieve portability across all types
  31. of compute devices.
  32. Bolt is an AMD specific C++ wrapper around the OpenCL API which
  33. extends the C99-based OpenCL language to support C++ features (most
  34. notably templates). It is similar to NVIDIA's Thrust library and
  35. shares the same failure, lack of portability.
  36. VexCL is an expression-template based linear-algebra library for
  37. OpenCL. The aims and scope are a bit different from the Boost Compute
  38. library. VexCL is closer in nature to the Eigen library while
  39. Boost.Compute is closer to the C++ standard library. I don't feel that
  40. Boost.Compute really fills the same role as VexCL. In fact, the recent versions
  41. of VexCL allow to use Boost.Compute as one of the backends, which makes
  42. the interaction between the two libraries a breeze.
  43. Also see this StackOverflow question:
  44. [@http://stackoverflow.com/questions/20154179/differences-between-vexcl-thrust-and-boost-compute]
  45. [h3 Why not write just write a new OpenCL back-end for Thrust?]
  46. It would not be possible to provide the same API that Thrust expects
  47. for OpenCL. The fundamental reason is that functions/functors passed
  48. to Thrust algorithms are actual compiled C++ functions whereas for
  49. Boost.Compute these form expression objects which are then translated
  50. into C99 code which is then compiled for OpenCL.
  51. [h3 Why not target CUDA and/or support multiple back-ends?]
  52. CUDA and OpenCL are two very different technologies. OpenCL works by
  53. compiling C99 code at run-time to generate kernel objects which can
  54. then be executed on the GPU. CUDA, on the other hand, works by
  55. compiling its kernels using a special compiler (nvcc) which then
  56. produces binaries which can executed on the GPU.
  57. OpenCL already has multiple implementations which allow it to be used
  58. on a variety of platforms (e.g. NVIDIA GPUs, Intel CPUs, etc.). I feel
  59. that adding another abstraction level within Boost.Compute would only
  60. complicate and bloat the library.
  61. [h3 Is it possible to use ordinary C++ functions/functors or C++11
  62. lambdas with Boost.Compute?]
  63. Unfortunately no. OpenCL relies on having C99 source code available at
  64. run-time in order to execute code on the GPU. Thus compiled C++
  65. functions or C++11 lambdas cannot simply be passed to the OpenCL
  66. environment to be executed on the GPU.
  67. This is the reason why I wrote the Boost.Compute lambda library.
  68. Basically it takes C++ lambda expressions (e.g. _1 * sqrt(_1) + 4) and
  69. transforms them into C99 source code fragments (e.g. “input[i] *
  70. sqrt(input[i]) + 4)”) which are then passed to the Boost.Compute
  71. STL-style algorithms for execution. While not perfect, it allows the
  72. user to write code closer to C++ that still can be executed through
  73. OpenCL.
  74. Also check out the BOOST_COMPUTE_FUNCTION() macro which allows OpenCL
  75. functions to be defined inline with C++ code. An example can be found in
  76. the monte_carlo example code.
  77. [h3 What is the command_queue argument that appears in all of the algorithms?]
  78. Command queues specify the context and device for the algorithm's
  79. execution. For all of the standard algorithms the command_queue
  80. parameter is optional. If not provided, a default command_queue will
  81. be created for the default GPU device and the algorithm will be
  82. executed there.
  83. [h3 How can I print out the contents of a buffer/vector on the GPU?]
  84. This can be accompilshed easily using the generic boost::compute::copy()
  85. algorithm along with std::ostream_iterator<T>. For example:
  86. [import ../example/print_vector.cpp]
  87. [print_vector_example]
  88. [h3 Does Boost.Compute support zero-copy memory?]
  89. Zero-copy memory allows OpenCL kernels to directly operate on regions of host
  90. memory (if supported by the platform).
  91. Boost.Compute supports zero-copy memory in multiple ways. The low-level
  92. interface is provided by allocating [classref boost::compute::buffer buffer]
  93. objects with the `CL_MEM_USE_HOST_PTR` flag. The high-level interface is
  94. provided by the [classref boost::compute::mapped_view mapped_view<T>] class
  95. which provides a std::vector-like interface to a region of host-memory and can
  96. be used directly with all of the Boost.Compute algorithms.
  97. [h3 Is Boost.Compute thread-safe?]
  98. The low-level Boost.Compute APIs offer the same thread-safety guarantees as
  99. the underyling OpenCL library implementation. However, the high-level APIs
  100. make use of a few global static objects for features such as automatic program
  101. caching which makes them not thread-safe by default.
  102. To compile Boost.Compute in thread-safe mode define `BOOST_COMPUTE_THREAD_SAFE`
  103. before including any of the Boost.Compute headers. By default this will require
  104. linking your application/library with the Boost.Thread library.
  105. [h3 What applications/libraries use Boost.Compute?]
  106. Boost.Compute is used by a number of open-source libraries and applications
  107. including:
  108. * ArrayFire ([@http://arrayfire.com])
  109. * Ceemple ([@http://www.ceemple.com])
  110. * Odeint ([@http://headmyshoulder.github.io/odeint-v2])
  111. * VexCL ([@https://github.com/ddemidov/vexcl])
  112. If you use Boost.Compute in your project and would like it to be listed here
  113. please send an email to Kyle Lutz (kyle.r.lutz@gmail.com).
  114. [h3 How can I contribute?]
  115. We are actively seeking additional C++ developers with experience in
  116. GPGPU and parallel-computing.
  117. Please send an email to Kyle Lutz (kyle.r.lutz@gmail.com) for more information.
  118. Also see the
  119. [@https://github.com/boostorg/compute/blob/master/CONTRIBUTING.md contributor guide]
  120. and check out the list of issues at:
  121. [@https://github.com/boostorg/compute/issues].
  122. [endsect] [/ faq ]