-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path6_test_print
40 lines (30 loc) · 1.35 KB
/
6_test_print
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <cuda_runtime.h>
__global__ void Check(){
//Block index
int bx = blockIdx.x;
int by = blockIdx.y;
//thread index
int tx = threadIdx.x;
int ty = threadIdx.y;
printf("threadIdx:(%d, %d, %d) | blockIdx:(%d, %d, %d) | blockDim: (%d, %d, %d) | gridDim(%d, %d, %d)\n", threadIdx.x, threadIdx.y, threadIdx.z, blockIdx.x, blockIdx.y, blockIdx.z, blockDim.x, blockDim.y, blockDim.z, gridDim.x, gridDim.y, gridDim.z);
}
int main(){
int nElem = 6;
dim3 dimBlock(3);
dim3 dimGrid((nElem + dimBlock.x - 1)/dimBlock.x);
printf("grid.x %d; grid.y %d; grid.z %d; \n", dimGrid.x, dimGrid.y, dimGrid.z);
printf("block.x %d; block.y %d; block.z %d; \n", dimBlock.x, dimBlock.y, dimBlock.z);
Check<<<dimGrid, dimBlock>>>();
cudaDeviceReset();
}
///
grid.x 2; grid.y 1; grid.z 1;
block.x 3; block.y 1; block.z 1;
threadIdx:(0, 0, 0) | blockIdx:(0, 0, 0) | blockDim: (3, 1, 1) | gridDim(2, 1, 1)
threadIdx:(1, 0, 0) | blockIdx:(0, 0, 0) | blockDim: (3, 1, 1) | gridDim(2, 1, 1)
threadIdx:(2, 0, 0) | blockIdx:(0, 0, 0) | blockDim: (3, 1, 1) | gridDim(2, 1, 1)
threadIdx:(0, 0, 0) | blockIdx:(1, 0, 0) | blockDim: (3, 1, 1) | gridDim(2, 1, 1)
threadIdx:(1, 0, 0) | blockIdx:(1, 0, 0) | blockDim: (3, 1, 1) | gridDim(2, 1, 1)
threadIdx:(2, 0, 0) | blockIdx:(1, 0, 0) | blockDim: (3, 1, 1) | gridDim(2, 1, 1)
////