二维的线程号到底怎么算啊?

#include <cuda.h>
#include <stdio.h>
global void cuda_one(int *ds, int *dt)
{
int x = blockIdx.x * blockDim.x + threadIdx.y * 16 + threadIdx.x;
int y = blockIdx.y * blockDim.y + threadIdx.y;

ds[x] = x;
dt[y] = y;

}

int main(void)
{
int *ds, *dt;
cudaMalloc( (void **)&dt, sizeof(int)10244);
cudaMemset(dt, 0, sizeof(int)10244);
cudaMalloc( (void **)&ds, sizeof(int)10244);
cudaMemset(ds, 0, sizeof(int)10244);
int *s, *t;
s = (int *)malloc(sizeof(int)10244);
t = (int *)malloc(sizeof(int)10244);

dim3 DimBlock(16, 16);
cuda_one<<<16, DimBlock>>>(ds,dt);
cudaMemcpy(s, ds, sizeof(int)10244, cudaMemcpyDeviceToHost);
cudaMemcpy(t, dt, sizeof(int)10244, cudaMemcpyDeviceToHost);

int i;
for(i = 0; i < 41024; i++)
printf(“\t%d”, s[i]);
printf(“\n88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888\n”);
for(i = 0; i < 4
1024; i++)
printf(“\t%d”, t[i]);
return 0;
}

我将
调用改成 cuda_one<<<16, 256>>>(ds, dt);
ds 打印出的数据是 0到4095
dt 打印出的数据是 0
这个都可以理解,
但是改成
dim3 DimBlock(16,16);
cuda_one<<<16, DimBlock>>>(ds, dt)
ds 和dt都打印的是0,为什么是这种结果?

这里应该怎么改,才能得出正确的线程号?

[ 本帖最后由 leon_wen 于 2010-7-5 14:30 编辑 ]

怎么上传图片:eek:

要先解决一个问题:什么才是正确的线程号
如果不知道要得到什么样的结果才是需要的,是不能简单的说应该是怎么样的

int x=blockIdx.xblockDim.x+threadIdx.x;
int y=blockIdx.y
blockDim.y+threadIdx.y;
dim3 DimBlock(16, 16);
dim3 DimGrid(4,4);
cuda_one<<<DimGrid, DimBlock>>>(ds,dt);
试试,都不知道你要干啥

dt[y] = y;
这一句应该是
dt = y;

如果按照楼上的改法,也要相应的修改写出去的时候的地址

建议楼主看一编程指南第三章