1 import pycuda.driver as drv
   2 import pycuda.tools
   3 import pycuda.autoinit
   4 import numpy
   5 import numpy.linalg as la
   6 from pycuda.compiler import SourceModule
   7 
   8 mod = SourceModule("""
   9 __global__ void dot(int *result, int *a, int *b)
  10 {
  11   const int i = threadIdx.x;
  12   result = result+ a[i] * b[i];
  13 }
  14 """)
  15 
  16 multiply_them = mod.get_function("dot")
  17 
  18 a = numpy.random.randint(1,20,5)
  19 b = numpy.random.randint(1,20,5) 
  20 result = 0
  21 dot(
  22         drv.Out(result), drv.In(a), drv.In(b),
  23         block=(5,1,1))
  24 
  25 print result

PyCuda/Examples/HelloGpu (last edited 2018-12-27 19:17:38 by 86)