[PyCuda] Questions about copying values into cubins

2008-11-25 Thread Brad Zima
Hello,

I've been working with the tutorial on using pycuda for doubling an array.
As a project, I attempted to modify the code so that the size of the array
can be variable, mostly for the purpose of importing images.  The functions
have been modified as follows:

mod = cuda.SourceModule(
  __global__ void doublify(float *a, int rows)
  {
int idx = threadIdx.x + threadIdx.y*rows;
a[idx] += 2;
  }
)
.
.
.
func = (a_gpu, r_gpu, block=(4,4,1))

The idea is to pass an additional int variable into the function. However,
when I run the code I get an error telling me of an invalid type parameter,
as follows:

Traceback (most recent call last):
  File img_double_c.py, line 39, in module
func(a_gpu, r_gpu,  block=(5,5,1))
  File
/usr/local/lib64/python2.5/site-packages/pycuda-0.91-py2.5-linux-x86_64.egg/pycuda/driver.py,
line 108, in function_call
handlers = func.param_set(*args)
  File
/usr/local/lib64/python2.5/site-packages/pycuda-0.91-py2.5-linux-x86_64.egg/pycuda/driver.py,
line 78, in function_param_set
raise TypeError(invalid type on parameter #%d (0-based) % i)
TypeError: invalid type on parameter #1 (0-based)


Reading more of the documentation showed that only certain datatypes may be
passed into the module, none of which are of int type. Is there something
I'm missing here?  If not, is there a way to pass variables (i.e. image
width and image height) into a SourceModule?

Brad Zima
___
PyCuda mailing list
PyCuda@tiker.net
http://tiker.net/mailman/listinfo/pycuda_tiker.net


Re: [PyCuda] Questions about copying values into cubins

2008-11-25 Thread Andreas Klöckner
On Mittwoch 26 November 2008, Brad Zima wrote:
 Reading more of the documentation showed that only certain datatypes may be
 passed into the module, none of which are of int type. Is there something
 I'm missing here?  If not, is there a way to pass variables (i.e. image
 width and image height) into a SourceModule?

You're likely passing an int for the r_gpu parameter. The problem is that 
PyCuda is refusing to guess what type the Python 'int' may correspond to. You 
have to tell it.

There are two ways:

- Use numpy's sized integers in the direct invocation interface. (convenient)
- Use the prepared_call interface. [1] (recommended) In this case, you don't 
have to pass sized ints any more, since you've already specified arg types in 
prepare().

I've updated the docs to make this clearer.

HTH,
Andreas

[1] http://is.gd/94wA


signature.asc
Description: This is a digitally signed message part.
___
PyCuda mailing list
PyCuda@tiker.net
http://tiker.net/mailman/listinfo/pycuda_tiker.net