Search code examples
openclpyopencl

Writing OpenCl Kernels in Python using PyOpenCl


When I write code in PyOpenCl, do I still need to write the kernels in C, or can I write them somehow in Python?


Solution

  • Yes, you still need to write the kernels in C.

    It really is not much of a pain to deal with. And if you want a bit more abstraction, you can create a domain specific language with Python that maps to parts of C kernels.

    The reason C is required for writing kernels is because OpenCL exists to create extremely performant applications. In order to make the most out of a GPU, you need to control the exact on-chip operations that the application does (such as bitwise operations), and how the application allocates the GPU's memory spaces (global, shared, and local). C is a great language for having that sort of control.