<#part sign=pgpmime> On Tue, 6 Mar 2012 14:49:13 +0100, Sqoox85 <sqoo...@gmail.com> wrote: > Hi all, > > I need a suggestion to allocate a particular struct of pointers of > functions used as VTable. > The idea is to get some polymorphism property in CUDA and the > implementation works well with it. > The problem is to adapt the code with pyCUDA because I don't know how > to get a pointer of a function. > I would know how it's possible to allocate a struct and copy a function > pointer > into it. Here a simple example: > -------------------------------------------------------------------------------------------- > typedef struct _cuobject cuObject; > > //pointers to function > typedef int (*comparefunc)(const cuObject*, const cuObject*, int); > > > typedef struct _cutype{ > comparefunc compare; > } cuType; > > __host__ __device__ int object_compare(const cuObject* a, const > cuObject* b, int op){ > return -1; > } > ------------------------------------------------------------------------------------------------------- > > > > I would do something like this but in pyCuda with mem_alloc and mem_cpy: > > ----------------------------------------------------------------------------- > cuType cuobjecttype = { > object_compare, > }; > ----------------------------------------------------------------------------- > In this way I associate the function "object_compare" to the struct. > The way to do so in pyCuda could be: > > ptr = cuda.mem_alloc(np.intp(0).nbytes) // allocate for > cuType > cuda.memcpy_htod_async(ptr, np.int32(0)) // <- how to > specify the function pointer named "object_compare"??? O.o
Hi Filippo, there's no way to meaningfully copy a function pointer from host to device. You either have to statically initialize that pointer in code or set it at runtime from your kernel. Andreas _______________________________________________ PyCUDA mailing list PyCUDA@tiker.net http://lists.tiker.net/listinfo/pycuda