PyOpenCL
OpenCL, or Open Computing Language in its full form, is a low-level API for heterogeneous computing that runs on CUDA-powered GPUs. PyOpenCL
represents the Python implementation of this API that enables us to write Python applications that leverage the power of a whole range of different platforms from CPUs, GPUs, DSPs and FPGAs.
Note
The official documentation for the PyOpenCL
library can be found athttps://documen.tician.de/pyopencl/.
Example
Let's dissect the example that comes in the official documentation. This will act as a perfect starting point, which we can expand upon later.
We will first import all the necessary modules at the top and alias NumPy and PyOpenCL as np
and cl
, respectively. We will then generate two random numbers of type numpy.float32
. We will then create some context within our PyOpenCL
program, by calling this with no parameters. This function will interactively allow you to choose what platforms and devices that your program should run on top of, which is...