Help me understand and learn this. Calculations of global threadID 1D grid of 1D blocks:…
- User
Help me understand and learn this.
Calculations of global threadID 1D grid of 1D blocks: __device__int getGlobalID_1D_1D(){ return blockIdx.x *blockDim.x + threadIdx.x; } 1D grid of 2D blocks: __device__int getGlobalID_1D_2D(){ return blockIdx.x * blockDim.x * blockDim.y + threadIdx.y * blockDim.x + threadIdx.x; } 1D grid of 3D blocks: __device__int getGlobalID_1D_3D(){ return blockIdx.x * blockDim.x * blockDim.y * blockDim.z + threadIdx.z * blockDim.y * blockDim.x + threadIdx.y * blockDim.x + threadIdx.x; }
2D grid of 1D blocks: device int getGlobalID_2D_1D(){ int blockId = blockIdx.y * gridDim.x + blockIdx.x; int threadId = blockId * blockDim.x + threadIdx.x; return threadId; } 2D grid of 2D blocks: __device__int getGlobalID_2D_2D(){ int blockId = blockIdx.x + blockIdx.y * gridDim.x; int threadId = blockId * (blockDim.x * blockDim.y) + (threadIdx.y * blockDim.x) + threadIdx.x; return threadId; } 2D grid of 3D blocks: __device__int getGlobalID_2D_3D(){ int blockId = blockIdx.x + blockIdx.y * gridDim.x; int threadId = blockId * (blockDim.x * blockDim.y * blockDim.z) + (threadIdx.z * (blockDim.x * blockDim.y)) + (threadIdx.y * blockDim.x) + threadIdx.x; return threadId; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.