# 多维网格 以下代码调用kernel函数, 对于多维Grid中每个线程在***全局***中的索引(x, y)正确的是? ```C++ dim3 gridDim = (blocksPerGrid, blocksPerGrid); dim3 blockDim = (threadsPerBlock, threadsPerBlock); .... kernel<<<gridDim, blockDim>>>(a,b,c) .... ``` ## 答案 ```C++ x = threadIdx.x + blockIdx.x * blockDim.x; y = threadIdx.y + blockIdx.y * blockDim.y; ``` ## 选项 ### A ```C++ x = threadIdx.x + blockIdx.x ; y = threadIdx.y + blockIdx.y ; ``` ### B ```C++ x = threadIdx.x * blockDim.x ; y = threadIdx.y * blockDim.y ; ``` ### C ```C++ x = threadIdx.x ; y = threadIdx.y ; ```