Copy an python object to device?

Hello everybody.

I want to pass a Python object (model - an instance of a Python Class) to the GPU and to run the kernel function (myfunc) on the device, which is supposed to call an optimizer to solve a linear problem (working on CPU).
Is it possible to pass a Python object to the GPU with numba? I can find examples doing this in C++, but for Python there are just examples passing arrays to the GPU.
Or is there anything else wrong with that?

I get the following error message:
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
non-precise type array(pyobject, 1d, C)
During: typing of argument at (208)

#part of my code
model = solph.Model(energysystem)
d_model = cuda.to_device(model)

def myfunc(model):

threadsperblock = (16, 16)
blockspergrid = (50, 50)
myfunc[blockspergrid, threadsperblock] (d_model)

Thank you for your answer!

Hi @Tessa321

In general Numba doesn’t handle arbitrary python objects very well. It works best on arrays and primitive data types. The GPU compilers are even more restrictive in this respect. Further, to directly answer your question, no you cannot in general pass python objects to the GPU with Numba.

You can of course do things like write optimisers for the GPU, they’d just operate on your array/scalar data opposed to an python object. There’s a new tutorial on using CUDA by @gmarkall (NVIDIA) here: GitHub - numba/nvidia-cuda-tutorial: Nvidia contributed CUDA tutorial for Numba perhaps start with that as an introduction?

Hope this helps?

Thank you for confirming my suspicions!