Created
January 10, 2013 12:49
-
-
Save ugovaretto/4501831 to your computer and use it in GitHub Desktop.
Compute number of CUDA blocks given grid size and number of threads per block.
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
int compute_blocks(int length, int threads_per_block) { | |
//integer division: | |
//if length is evenly divisable by the number of threads | |
//is equivalent to length / threads_per_block, if not | |
//it is equivalent to length / threads_per_block + 1 | |
return (length + threads_per_block - 1) / threads_per_block; | |
} | |
dim3 compute_blocks(int xsize, int ysize, int zsize, | |
int threads_per_block_x, | |
int threads_per_block_y, | |
int threads_per_block_z) { | |
return dim3(compute_blocks(xsize, threads_per_block_x), | |
compute_blocks(ysize, threads_per_block_y), | |
compute_blocks(zsize, threads_per_block_z)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment