Hi Andreas,

So, is it possible to define static member data inside a struct in CUDA?
For example:
-------------------------------------------------------------------------------------------
typedef struct _cuobject{
    static cuType* type;

    __host__ __device__ _cuobject(){
        //type = NULL;
        if(type == NULL){

            cuType cuobjecttype = {
                cuObject_compare,
            };
            type = &cuobjecttype;
        }
    }
} cuObject;
-------------------------------------------------------------------------------------------

If so, I could declare statically a cuobjecttype directly inside the struct
without thinking about allocate it in pycuda code, but
It give me an error. It say that in "if(type==NULL)" type is not defined.

Thanks,
Filippo




On Tue, Mar 6, 2012 at 3:39 PM, Andreas Kloeckner
<[email protected]> wrote:
> <#part sign=pgpmime>
> On Tue, 6 Mar 2012 14:49:13 +0100, Sqoox85 <[email protected]> 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
[email protected]
http://lists.tiker.net/listinfo/pycuda

Reply via email to