我的内核如下所示:
# compile device.cu
mod = SourceModule('''
#include<stdio.h>
__global__ void test(unsigned int* tab, unsigned int compteurInit)
{
unsigned int gID = threadIdx.x + blockDim.x * (threadIdx.y + blockDim.y * (blockIdx.x + blockIdx.y * gridDim.x));
tab[gID] = compteurInit;
printf("%d ",tab[gID]);
}''',
nvcc='/opt/cuda65/bin/nvcc',
)
这是我的主持人计划
kern = mod.get_function("test")
XGRID = 256
YGRID = 1
XBLOCK = 256
YBLOCK = 1
etat=np.zeros(XBLOCK * YBLOCK * XGRID * YGRID,dtype=np.uint)
etat_gpu= gpuarray.to_gpu(etat)
kern(etat_gpu,np.uint(10),block=(XBLOCK,YBLOCK,1),grid=(XGRID,YGRID,1))
print etat_gpu.get()
当我打印结果时,我有一些奇怪的值,而
像这样:[42949672970 42949672970 42949672970 ..., 0 0
0]
但是当我检查内核中的打印值时似乎很好