Copying memory of zero size


I have a kernel that gets some lightsource arrays as input parameters (directional, point and spot). The number of each light source array could also be 0. If the size is zero, I get an error when allocating mem on the gpu for that array. Since that doesn’t work, I tried to pass the kernel NULL as the light source array if the ammount is 0. But then I also get an error from the clSetKernelArg-function. How to avoid that and make the programm run properly?


You should be able to pass a NULL value for a kernel argument declared as a __global pointer to a type. Another option would be to pass a count variable as an argument which could be set to 0. The kernel could check this value to see if it is non-zero.