从hos获取变量时出现奇怪的值

2024-10-03 00:26:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我的内核如下:

# 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]

但是当我检查内核中的打印值时,它看起来很好


Tags: testmodgpunp内核tabintxblock