# Copy an python object to device?

**URL:** <https://numba.discourse.group/t/copy-an-python-object-to-device/689>\
**Category:** Support: What is this error message?\
**Created:** [April 27, 2021, 3:06pm UTC](https://numba.discourse.group/t/copy-an-python-object-to-device/689 "2021-04-27T15:06:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tessa321](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/tessa321/32/312_2.png) [@Tessa321](https://numba.discourse.group/u/Tessa321)\
**Post date:** [April 27, 2021, 3:06pm UTC](https://numba.discourse.group/t/copy-an-python-object-to-device/689/1 "2021-04-27T15:06:12Z")

</div>

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 basic\_example.py (208)

#part of my code  
model = solph.Model(energysystem)  
d\_model = cuda.to\_device(model)

@cuda.jit()  
def myfunc(model):  
model.solve(solver=“gurobi\_direct”)

threadsperblock = (16, 16)  
blockspergrid = (50, 50)  
myfunc[blockspergrid, threadsperblock] (d\_model)

Thank you for your answer!

---

<div class="post-metadata">

**Author:** ![stuartarchibald](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/stuartarchibald/32/10_2.png) [@stuartarchibald](https://numba.discourse.group/u/stuartarchibald)\
**Post date:** [April 30, 2021, 5:38pm UTC](https://numba.discourse.group/t/copy-an-python-object-to-device/689/2 "2021-04-30T17:38:33Z")

</div>

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](https://github.com/numba/nvidia-cuda-tutorial) perhaps start with that as an introduction?

Hope this helps?

---

<div class="post-metadata">

**Author:** ![Tessa321](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/tessa321/32/312_2.png) [@Tessa321](https://numba.discourse.group/u/Tessa321)\
**Post date:** [May 11, 2021, 12:42pm UTC](https://numba.discourse.group/t/copy-an-python-object-to-device/689/3 "2021-05-11T12:42:46Z")

</div>

Thank you for confirming my suspicions!
