How to create __local memory variable in pyopencl?

in my OpenCL code, I use clSetKernelArgto create a memory "variable size" __localfor use in my kernels, which is not in OpenCL per se. See my example:

clSetKernelArg(clKernel, ArgCounter++, sizeof(cl_mem), (void *)&d_B);
...
clSetKernelArg(clKernel, ArgCounter++, sizeof(float)*block_size*block_size, NULL);
...
kernel="    
    matrixMul(__global float* C,
                   ...
              __local float* A_temp,
                  ...
             )"
{...

Now my question is, how to do the same in pyopencl?

I looked at the examples that came with pyopencl, but the only thing I could find was the template approach, which seems to me like I understood it as brute force. See an example.

kernel = """
        __kernel void matrixMul(__global float* C,...){
                     ... 
            __local float A_temp[ %(mem_size) ];
                     ...
        }

What do you recommend?

+3
source share
2 answers

It is similar to C. You pass it a fixed-size array as local. Here is an example from the genus Enja radix. Note that the last argument is an array of local memory.

 def naive_scan(self, num):
    nhist = num/2/self.cta_size*16
    global_size = (nhist,)
    local_size = (nhist,)
    extra_space = nhist / 16 #NUM_BANKS defined as 16 in RadixSort.cpp
    shared_mem_size = self.uintsz * (nhist + extra_space)
    scan_args = (   self.mCountersSum,
                    self.mCounters,
                    np.uint32(nhist),
                    cl.LocalMemory(2*shared_mem_size)
                )
    self.radix_prg.scanNaive(self.queue, global_size, local_size, *(scan_args)).wait()
+5

Python OpenCL, ( , ):

__kernel void matrixMul(...) {

    __local float A_templ[1024];

}

1024 :

#define SIZE 1024    
__kernel void matrixMul(...) {

        __local float A_templ[SIZE];

    }

, cLBuildProgram clCreateProgramWithSource.

EDIT: - Google;-): http://www.google.com/url?sa=t&source=web&cd=4&ved=0CC8QFjAD&url=http%3A%2F%2Flinksceem.eu%2Fjoomla%2Ffiles%2FPRACE_Winter_School%2FLinkSCEMM_pyOpenCL.pdf&rct=j&q=Pyopencl%20__local%20memory&ei=BTbETbWhOsvBswadp62ODw&usg=AFQjCNG6rXEEkDpE1304pmQDu3GFdRA0BQ&sig2=vHOGOqwA1HHUl10c6HO8WQ&cad=rja

+3

All Articles