简体   繁体   中英

OpenCL, Is it possible write directly to local memory?

I am new to OpenCL. Now I trying to understand the local and shared memory. I am doing a sample code, there I am trying to upload a filter of size 4x4 into local memory from CPU, but I am getting the error -52 CL_INVALID_KERNEL_ARGS. The sample code:

void __kernel filter( const __global float* in, __global float* out, const __local float* coeff )
{
    //filtering
}

CPU part:

ret = kernel.setArg(0, input);
ret = kernel.setArg(1, out);
ret = kernel.setArg(2, 16*sizeof(float), &coeff );

the enqueueNDRangeKernel will return -52 error.

If I give NULL instaed of "coeff", no error

ret = kernel.setArg(0, input);
ret = kernel.setArg(1, out);
ret = kernel.setArg(2, 16*sizeof(float), NULL );

Is it possible to write directly to local memory?, I did not find any help in OpenCL books. Please share your experience, if anybody tried this.

Thanks

No, the host CPU does not have the ability to directly access local memory in this manner. All local memory allocations must be initialised inside a kernel running on the device.

In my experience, small filters for image processing are usually better off in constant memory - simply allocate a buffer as you would for global memory but declare the argument with __constant instead of __global . If possible, you may see further performance improvements by embedding your filter into the OpenCL kernel source as a compile-time constant, eg:

__constant float filter[] = {
  -0.000000f, -0.055556f, -0.055556f, 
  -0.055556f, -0.111111f, -0.222222f, 
  -0.222222f, -0.277778f, -0.444444f, 
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM