multi_dim.md 620 字节
Newer Older
K
Ken He  
Ken He 已提交
1 2 3 4 5 6 7 8 9 10 11 12
# 多维网格
以下代码调用kernel函数, 对于多维Grid中每个线程在***全局***中的索引(x, y)正确的是?
```C++
dim3 gridDim = (blocksPerGrid, blocksPerGrid);
dim3 blockDim = (threadsPerBlock, threadsPerBlock);
....
kernel<<<gridDim, blockDim>>>(a,b,c)
....

```

## 答案
F
feilong 已提交
13

K
Ken He  
Ken He 已提交
14 15 16 17 18 19 20 21
```C++
x = threadIdx.x + blockIdx.x * blockDim.x;
y = threadIdx.y + blockIdx.y * blockDim.y;
```

## 选项

### A
F
feilong 已提交
22

K
Ken He  
Ken He 已提交
23 24 25 26 27 28
```C++
x = threadIdx.x + blockIdx.x ;
y = threadIdx.y + blockIdx.y ;
```

### B
F
feilong 已提交
29

K
Ken He  
Ken He 已提交
30 31 32 33 34 35
```C++
x = threadIdx.x * blockDim.x ;
y = threadIdx.y * blockDim.y ;
```

### C
F
feilong 已提交
36

K
Ken He  
Ken He 已提交
37 38 39 40
```C++
x = threadIdx.x ;
y = threadIdx.y ;
```