3

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)
  • 1
    The code is working fine on my system. I am using Python 3.5.2. One thing I will suggest to convert "a" into numpy array and please share your error message. "a =np.array([random.randint(0,20) for i in range(20)])" . Thanks – Rajat Gupta Aug 21 '17 at 10:16
  • 1
    There is no error message,and no print.It ends after 2 seconds – Winnie.Xiong Aug 21 '17 at 10:57
  • Have you tried type casting 'a' to Numpy array. – Rajat Gupta Aug 21 '17 at 10:58
  • 1
    yes,I have tried. There is still no result – Winnie.Xiong Aug 21 '17 at 11:38
  • It seems that the problem happened first three lines, the three import.If we use these modules,we can't print anything wherever we put "print".But my pyCUDA was installed by pip, there should be no problem. – Winnie.Xiong Aug 21 '17 at 11:44

0 Answers0