According to the documentation the kernal_name
function needs 3 API params:
program.kernel_name(queue, shape, None, kernal-params...)
but it is not documented, what None
and shape
parameters are used for. As far as I understand, the third parameter is the kernel function itself and could be just None
, but what is the second parameter shape
used for?
according to the book "OpenCL in Action" the parameters are:
The kernel function is selected by the name of what you called kernel_name in your code. E.g. if you have a kernel function named "__kernel void foo(...)", then just call program.foo(...) in Python. The global_size specifies how many work-items are used and the local size specifies the size of a work-group. The parameters of the kernel are passed in the order they appear in the kernel function, which is denoted by *args.
Here is an example from the mentioned book:
program.mult(queue, (25,), (25,), scalar, float_buffer, lm)
.
From the program, the kernel with name "mult" is created, global and local size is set to 25, i.e. it is a 1D task, and the arguments scalar (of type numpy.float32), float_buffer (of type cl.Buffer) and lm (of type cl.LocalMemory) are passed to the kernel.
The corresponding kernel is:
__kernel void mult(float num, __global float *global_floats, __local float4 *local_floats) {...}
You can, of course, also do it the way it is done in pure C. This needs more typing, but the advantage is that it is very clear to see what happens: