variable length array declaration not allowed in OpenCL - why?

后端 未结 2 1768
我寻月下人不归
我寻月下人不归 2021-01-12 04:02

I want to create a local array inside my OpenCL kernel, whose size depends on a parameter of the kernel. It seems that\'s not allowed - at least with AMD APP.

Is you

2条回答
  •  无人及你
    2021-01-12 04:42

    You can dynamically allocate the size of a local block. You need to take it as a parameter to your kernel, and define its size when you call clSetKernelArg.

    definition example:

    __kernel void kernelName(__local float* myLocalFloats, ...)
    

    host code:

    clSetKernelArg(kernel, 0, myLocalFloatCount * sizeof(float), NULL); // <-- set the size to the correct number of bytes to allocate, but use NULL for the data.
    

    Make sure you know what the limit for local memory is on your device before you do this. Call clGetDeviceInfo, and poll for the 'CL_DEVICE_LOCAL_MEM_SIZE' value.

提交回复
热议问题