![]() This is especially revlevant if you're working with 1D arrays. With that said, it's common to only use the x-dimension of the blocks and grids, which is what it looks like the code in your question is doing. In turn, each block is a 3-dimensional cube of threads. Each of its elements is a block, such that a grid declared as dim3 grid(10, 10, 2) would have 10*10*2 total blocks. You seem to be a bit confused about the thread hierachy that CUDA has in a nutshell, for a kernel there will be 1 grid, (which I always visualize as a 3-dimensional cube). ThreadIdx: This variable contains the thread index within the block. ![]() GridDim: This variable contains the dimensions of the grid.īlockIdx: This variable contains the block index within the grid.īlockDim: This variable and contains the dimensions of the block. Paraphrased from the CUDA Programming Guide: It would be 4 hours well spent, if you want to understand these concepts better. You might want to consider taking an introductory CUDA webinars For example, the first 4 units. This topic, sometimes called a "grid-striding loop", is further discussed in this blog article. In this case, after processing one loop iteration, each thread must then move to the next unprocessed location, which is given by tid+=blockDim.x*gridDim.x In effect, the entire grid of threads is jumping through the 1-D array of data, a grid-width at a time. In particular, when the total threads in the x-dimension ( gridDim.x*blockDim.x) is less than the size of the array I wish to process, then it's common practice to create a loop and have the grid of threads move through the entire array. In the CUDA documentation, these variables are defined here It's common practice when handling 1-D data to only create 1-D blocks and grids. blockDim.x * gridDim.x gives the number of threads in a grid (in the x direction, in this case)īlock and grid variables can be 1, 2, or 3 dimensional.gridDim.x,y,z gives the number of blocks in a grid, in the.blockDim.x,y,z gives the number of threads in a block, in the. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |