Hi Andreas,

    There are import errors with the following code (due to pycuda driver
"from pycuda.compiler import SourceModule as _SourceModule"); switching the
import compiler and import driver lines in the example makes it work. I'm
not sure why, but I usually just avoid the "from ... import" statement
altogether and use fully qualified names; everything works better.

import numpy
import pycuda.compiler as compiler
import pycuda.driver as drv

drv.init()
ctx = drv.Device(0).make_context()

module = compiler.SourceModule("""
__global__ void inc_arr(float *arr) {
    arr[threadIdx.x] += 1;
}""")
fcn = module.get_function("inc_arr")

arr = drv.to_device(numpy.zeros(300, numpy.float32))
fcn.prepare("P", block=(300, 1, 1))
fcn.prepared_call((1, 1), arr)
print(drv.from_device(arr, 300, numpy.float32))

ctx.pop()

regards,
Nicholas
_______________________________________________
PyCuda mailing list
[email protected]
http://tiker.net/mailman/listinfo/pycuda_tiker.net

Reply via email to