pyCUDA can't print result

♀尐吖头ヾ 提交于 2019-12-10 18:16:36

问题


Recently, I use pip to install the pyCUDA for my python3.4.3. But I found when I test the sample code(https://documen.tician.de/pycuda/tutorial.html#getting-started), it can't print the result without any error message,the program can end. I can't understand what's wrong with this code or my python,thank you all for answer.This is my code:

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)

来源:https://stackoverflow.com/questions/45788847/pycuda-cant-print-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!