Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCUDA Passing variable by value to kernel

Should be simple enough; I literally want to send an int to the a SourceModule kernel declaration, where the C function

__global__......(int value,.....)

with the value being declared and called...

value = 256
...
...
func(value,...)

But I'm getting a variety of errors from pycuda that I'm using the wrong type.

like image 903
Bolster Avatar asked Apr 19 '11 01:04

Bolster


1 Answers

The standard PyCUDA function interface requires argument have numpy dtypes, because it internally does mapping to C types under the hood. So for scalar arguments which are passed by value, you need to "cast" to a suitable numpy dtype first. Something like

value = 256
va = numpy.int32(value)

func(va)

should work. If you are passing single precision floating point values or arrays, make sure to explicitly use a dtype of np.float32, because numpy uses double precision by default and you will wind up with similar errors.

like image 142
talonmies Avatar answered Oct 17 '22 04:10

talonmies