OpenCL:Why Pointer to a pointer cannot be passed as an argument to a kernel function?

时光怂恿深爱的人放手 提交于 2019-12-13 14:41:39

问题


Hi, I just want some clarification on Why we can not pass the 2D array pointer as argument to the kernel . Why it is not allowed . What will happen if I use this as argument (Internally??as I know the code will give some error) .

Please do the needful .


回答1:


Because in OpenCL 1.x the device has a separate address space. Kernels executing on the device wouldn't know what to do with a pointer that is only useful in host address space.

Note that in OpenCL 2.0 Shared Virtual Memory (SVM) removes this restriction and allows buffers containing pointers to be used on both host and device side.




回答2:


To be a little more concrete, let's say I have a kernel with a pointer to a pointer as a parameter: kernel void foo(global float * global *a){...}

The runtime in this case knows that it has a private pointer to an array of global pointers to global floats.

When I pass a buffer to the runtime: clSetKernelArg(fooKernel, 0, sizeof(cl_mem), &aBuffer);

The runtime knows it expects a pointer. As this is OpenCL 1.x it knows then it must have had the arg set to a pointer. It knows the that the pointer it received is a pointer to a cl_mem. It can look at that cl_mem, find the address it has been allocated in device memory, pass that address into the device and launch the kernel. However, it does not know (in general) which buffer you are trying to point to for the pointers inside the buffer. Even if it did know that they pointed to the same buffer, it would have to go through the entire buffer updating every pointer field. If the pointers were nested it would have to have a lot more information. It just isn't feasible in the general case.

OpenCL 2.0 supports shared virtual memory, which means the addresses are fixed, and the same on the host and device (even if the memory isn't necessarily directly shared). There is no need to do the conversion and hence it becomes possible.



来源:https://stackoverflow.com/questions/26138835/openclwhy-pointer-to-a-pointer-cannot-be-passed-as-an-argument-to-a-kernel-func

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