本文主要是介绍cuda 入门 threadIdx,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
cuda threadIdx 访问唯一数组下标
- 三维 grid block
- 访问下标
三维 grid block
dim3 block(2, 2, 2);
dim3 grid(2, 2, 2);
访问下标
__global__ void mem_trans(int* input)
{int threadId_3D = threadIdx.x + threadIdx.y * blockDim.x +threadIdx.z * blockDim.x * blockDim.y;int blockId_3D = blockIdx.x + blockIdx.y * gridDim.x +blockIdx.z * gridDim.x * gridDim.y;int gid = threadId_3D + (blockDim.x * blockDim.y * blockDim.z) * blockId_3D;printf("tid : %d, gid : %d, value : %d\n",threadIdx.x, gid, input[gid]);
}
这篇关于cuda 入门 threadIdx的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!