OpenCL: Store pointer to global memory in local memory?

狂风中的少年 提交于 2019-12-18 17:58:43

问题


any solutions?

Is that even possible?

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

I want abc to be stored in local memory instead of private memory.


回答1:


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;




回答2:


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!




回答3:


This is legal:

global uint *globalPtr=&ptr[tid]


来源:https://stackoverflow.com/questions/11978024/opencl-store-pointer-to-global-memory-in-local-memory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!