CUDA里面GRID, BLOCK 边界检测

来源:互联网 发布:windows回滚工具 编辑:程序博客网 时间:2024/06/05 13:27
dim3 block(BLOCK_X, BLOCK_Y);dim3 grid((roi.width + block.x - 1) / block.x, (roi.height + block.y - 1) / block.y);int y = blockIdx.y * blockDim.y + threadIdx.y;//索引从0开始int x = blockIdx.x * blockDim.x + threadIdx.x;if (y >= roi.height || x >= roi.width) {return;}




block定义它的维数, 每维有多少个thread


grid定义每维有多少个grid


roi是原本的数据, 由于原本数据不一定会刚好是block的整数倍, 所以我们需要把超出边界的thread屏蔽掉




x,y为GPU上每个thread的坐标

如果该坐标超出了原本数据在每维的边界,则直接返回.




0 0