OpenCL: Store pointer to global memory in local memory?

后端 未结 3 1649
小鲜肉
小鲜肉 2021-01-03 11:40

any solutions?

Is that even possible?

__global *float abc; // pointer to global memory stored in private memory

I want abc to be st

相关标签:
3条回答
  • 2021-01-03 12:12

    I think this is clarified here List 5.2:

    __global int global_data[128];  // 128 integers allocated on global memory
    __local float *lf;  // pointer placed on the private memory, which points to a single-precision float located on the local memory
    __global char * __local lgc[8];  // 8 pointers stored on the local memory that points to a char located on the global memory
    

    As I understand for pointers: [where they point] type * [where to store] name;

    0 讨论(0)
  • 2021-01-03 12:32

    This is legal:

    global uint *globalPtr=&ptr[tid]
    
    0 讨论(0)
  • 2021-01-03 12:33

    Well, I have also encountered a similar problem as you before, as I explored, I think it works in such a way: in OpenCL kernel, variables inside a kernel without an address qualifier (__local, __global, etc) will be automatically considered to be stored in __private memory space. For pointers which are not declared with space qualifier, it will also be considered to point to __private space. Here is an example code snippet:

    __kernel void foo(__global uint *ptr)
    {
        uint tid = get_global_id(0);
        uint * localPtr = ptr;
        uint   var= *(localPtr + tid);
        ... ...
    }
    

    In the above code snippet, the localPtr is an uint type pointer which has no memory space qualifier, so it will be automatically considered to point to _private memory space. In OpenCL, a pointer to address space A (_global, for example) can only be assigned to a pointer to the same address space (__global). So in the above example, a pointer to __private address space cannot be assigned with a pointer (ptr) which points to __global address. (For this point, you can also refer to OpenCL Spec in the section "Address Space Qualifiers"). Hope this can be helpful!

    0 讨论(0)
提交回复
热议问题