OpenCL: Difference between revisions
No edit summary |
|||
(9 intermediate revisions by the same user not shown) | |||
Line 6: | Line 6: | ||
===Linux=== | ===Linux=== | ||
https://gist.github.com/Brainiarc7/dc80b023af5b4e0d02b33923de7ba1ed | https://gist.github.com/Brainiarc7/dc80b023af5b4e0d02b33923de7ba1ed | ||
<pre> | |||
sudo apt install ocl-icd-opencl-dev opencl-headers | |||
sudo apt install opencl-c-headers opencl-clhpp-headers | |||
</pre> | |||
==Getting Started== | ==Getting Started== | ||
Line 142: | Line 146: | ||
===C++=== | ===C++=== | ||
[https://github.khronos.org/OpenCL-CLHPP/index.html#intro C++ Bindings]<br> | [https://github.khronos.org/OpenCL-CLHPP/index.html#intro C++ Bindings]<br> | ||
While you can use the C bindings in your C++ application, Khronos also provides a set of C++ bindings in <code>CL/cl.hpp</code> (or <code>CL/cl2.hpp</code>) which are much easier to use alongside std containers such as <code>std::vector</code>. When using C++ bindings, you also do not need to worry about releasing buffers since these are reference-counted. | While you can use the C bindings in your C++ application, Khronos also provides a set of C++ bindings in <code>CL/cl.hpp</code> (or <code>CL/cl2.hpp</code>) which are much easier to use alongside std containers such as <code>std::vector</code>. | ||
When using C++ bindings, you also do not need to worry about releasing buffers since these are reference-counted. | |||
{{hidden | C++ example | | {{hidden | C++ example | | ||
<syntaxhighlight lang="cpp"> | <syntaxhighlight lang="cpp"> | ||
Line 241: | Line 246: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
}} | }} | ||
===Python=== | |||
See [https://documen.tician.de/pyopencl/index.html pyopencl]. | |||
===Julia=== | ===Julia=== | ||
Line 262: | Line 270: | ||
==OpenGL Interop== | ==OpenGL Interop== | ||
Setting up OpenCL/OpenGL interop is fairly complicated and very hard to debug. | |||
You will also need to manage synchronizing OpenGL/OpenCL so they do not access the same memory at the same time. | |||
If you can, just use OpenGL compute shaders rather than OpenCL to simplify your life. | |||
===Textures=== | ===Textures=== | ||
Line 267: | Line 278: | ||
In C++, you can use [https://github.khronos.org/OpenCL-CLHPP/classcl_1_1_image_g_l.html <code>cl::ImageGL</code>] to access textures in OpenGL. | In C++, you can use [https://github.khronos.org/OpenCL-CLHPP/classcl_1_1_image_g_l.html <code>cl::ImageGL</code>] to access textures in OpenGL. | ||
Note that <code>cl::Image</code> and <code>cl::Buffer</code> are not the same thing | Note that <code>cl::Image</code> and <code>cl::Buffer</code> are not the same thing. Interchanging them will result in <code>CL_INVALID_MEM_OBJECT</code> errors or similar. | ||
I recommend writing to a separate buffer and copying to images. | I recommend writing to a separate buffer and copying to images. | ||
See [https://www.khronos.org/registry/OpenCL/sdk/2.2/docs/man/html/clCreateFromGLTexture.html clCreateFromGLTexture] to get a list of compatible pixel formats. | |||
If in doubt, use <code>GL_RGBA8</code> which is the most likely format to be supported. | |||
===Buffers=== | ===Buffers=== | ||
Line 276: | Line 290: | ||
==Advanced Topics== | ==Advanced Topics== | ||
====Local Memory v. Global Memory==== | ====Local Memory v. Global Memory==== | ||
[[Category:Programming languages]] | |||
[[Category:GPU Programming languages]] |