How do I use local memory in OpenCL?

后端 未结 3 1237
刺人心
刺人心 2020-12-05 03:52

I\'ve been playing with OpenCL recently, and I\'m able to write simple kernels that use only global memory. Now I\'d like to start using local memory, but I can\'t seem to f

3条回答
  •  感动是毒
    2020-12-05 04:37

    Check out the samples in the NVIDIA or AMD SDKs, they should point you in the right direction. Matrix transpose would use local memory for example.

    Using your squaring kernel, you could stage the data in an intermediate buffer. Remember to pass in the additional parameter.

    __kernel square(
        __global float *input,
        __global float *output,
        __local float *temp,
        const unsigned int count)
    {
        int gtid = get_global_id(0);
        int ltid = get_local_id(0);
        if (gtid < count)
        {
            temp[ltid] = input[gtid];
            // if the threads were reading data from other threads, then we would
            // want a barrier here to ensure the write completes before the read
            output[gtid] =  temp[ltid] * temp[ltid];
        }
    }
    

提交回复
热议问题