So, I have to pass some data to a OpenCL kernel using PyOpenCL or some workaround using Python. The data is readed in the kernel-side as a struct and I can't change the kernel cuz it is working fine and is a part of a much bigger project that my code must work with.
The kernel looks like that:
typedef struct VglClStrEl{
float data[VGL_ARR_CLSTREL_SIZE];
int ndim;
int shape[VGL_ARR_SHAPE_SIZE];
int offset[VGL_ARR_SHAPE_SIZE];
int size;
} VglClStrEl;
typedef struct VglClShape{
int ndim;
int shape[VGL_ARR_SHAPE_SIZE];
int offset[VGL_ARR_SHAPE_SIZE];
int size;
} VglClShape;
__kernel void kernel(__global unsigned char* img_input,
__global unsigned char* img_output,
__constant VglClShape* img_shape,
__constant VglClStrEl* window)
{
// do what is needed
}
So, as you can see, the VglClShape and VglClStrEl structures, have different type arrays and static-bitsize variables.
The [1] workaround supports structs with only one type arrays(or I tragically failed to get a way to do it with multiple array types).
The [2] workaround is the PyOpenCL documentation reference for how pass Python data to a OpenCL kernel struct. This approach don't support arrays at all.
So, how can I pass the python data as the OpenCL kernel can read? I already have all the data on Python-side, and I just need to know how to pass it from the Python to the kernel.
Before you ask: I am using Python 3 and I CAN NOT CHANGE THE KERNEL.
And yes, the array sizes are static. You can assume something like that:
VGL_ARR_CLSTREL_SIZE=256;
VGL_ARR_SHAPE_SIZE=20;
[1] Passing struct with pointer members to OpenCL kernel using PyOpenCL
[2] https://documen.tician.de/pyopencl/howto.html#how-to-use-struct-types-with-pyopencl