Search code examples
pythoncudapycuda

using dictionary in pycuda


I have a dictionary and i would like to know if is it possible to use it as a parameter of a kernel.

for instance

i have the cuda kernel signature

__global__ void calTab(Tableaux)

Tableaux is a C structure corresponding to

typedef struct
{
    float *Tab1;
    float *Tab2;
} Tableaux;

in python Tableaux correspond to the dictionary below:

Tableaux={}
Tableaux["Tab1"]=[]
Tableaux["Tab2"]=[]

is it possible to use the dictionary as the C structure without using a C API?

Thank you in advance


Solution

  • None of what you are proposing is possible. In PyCUDA, you cannot

    1. Pass a dictionary to a kernel
    2. Pass a list to a kernel
    3. Directly translate a dictionary to C++ structure in device code
    4. Directly translate a list to a C++ linear array in device

    PyCUDA can use Python classes as C++ structures and it has a numpy like array for use on the GPU. So points 3 and 4 are possible, but not as you would like to do them. Both techniques are discussed in the documentation,here for gpuarray and here for structures.