作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 CUDA 中,为了覆盖多个 block ,从而增加数组索引的范围,我们做了这样的事情:
主机端代码:
dim3 dimgrid(9,1)// total 9 blocks will be launched
dim3 dimBlock(16,1)// each block is having 16 threads // total no. of threads in
// the grid is thus 16 x9= 144.
设备端代码
...
...
idx=blockIdx.x*blockDim.x+threadIdx.x;// idx will range from 0 to 143
a[idx]=a[idx]*a[idx];
...
...
在 OpenCL 中实现上述情况的等效项是什么?
最佳答案
在主机上,当您使用 clEnqueueNDRangeKernel
对内核进行排队时,您必须指定全局和本地工作大小。例如:
size_t global_work_size[1] = { 144 }; // 16 * 9 == 144
size_t local_work_size[1] = { 16 };
clEnqueueNDRangeKernel(cmd_queue, kernel, 1, NULL,
global_work_size, local_work_size,
0, NULL, NULL);
在你的内核中,使用:
size_t get_global_size(uint dim);
size_t get_global_id(uint dim);
size_t get_local_size(uint dim);
size_t get_local_id(uint dim);
分别检索全局和局部工作大小和索引,其中 dim
为 0
for x
,1
y
和 2
z
。
因此,您的 idx
的等效项将是 size_t idx = get_global_id(0);
关于cuda - OpenCl 相当于在 CUDA 中查找连续索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10393390/
我是一名优秀的程序员,十分优秀!