Created
October 14, 2014 15:58
-
-
Save kewitz/63995fcd92402ec02e27 to your computer and use it in GitHub Desktop.
CUDA Snippets.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Calculate the thread global position, taken it's thread position within the block. | |
__device__ __inline__ uint3 __getGlobalPosition (uint3 blockIdx, dim3 blockDim, uint3 threadIdx) { | |
return make_uint3(blockIdx.x * blockDim.x + threadIdx.x, blockIdx.y * blockDim.y + threadIdx.y, blockIdx.z * blockDim.z + threadIdx.z); | |
}; | |
// Device function to return the index of a given thread within a block. | |
__device__ __inline__ unsigned int __tIndex(uint3 b, dim3 bd, uint3 t) { | |
return t.x + t.y*bd.x + t.z*bd.x*bd.z; | |
}; | |
// Return thread global index on a 2D space, given its global position and number of rows. | |
__device__ __inline__ unsigned int __tIndex2D(uint3 globalPosition, unsigned int rows){ | |
return globalPosition.y * rows + globalPosition.x; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment