最近,我使用pip为我的python3.4.3安装pyCUDA。但是当我测试示例代码(https://documen.tician.de/pycuda/tutorial.html#getting-started)时,我发现它无法在没有任何错误消息的情况下打印结果,程序可以结束。我无法理解这段代码或我的python有什么问题,谢谢大家的回答。这是我的代码:
import pycuda.driver as cuda
import pycuda.autoinit
from pycuda.compiler import SourceModule
import numpy
import random
a =[random.randint(0,20) for i in range(20)]
a = a.astype(numpy.float32)
a_gpu = cuda.mem_alloc(a.nbytes)
cuda.memcpy_htod(a_gpu, a)
mod = SourceModule("""
__global__ void doublify(float *a)
{
int idx = threadIdx.x + threadIdx.y*4;
a[idx] *= 2;
}
""")
func = mod.get_function("doublify")
func(a_gpu, block=(4,4,1))
a_doubled = numpy.empty_like(a)
cuda.memcpy_dtoh(a_doubled, a_gpu)
print(a_doubled)
print(a)