Reputation: 4978
If I have a simple sampling 3D points of the form
s = [[x1, y1, z1], [x2, y2, z2],[x3, y3, z3],[x4, y4, z4],.....]
in to voxels function implemented in cupy, Can I call that function from c++ code? We have c++ code calling tensorflow graph and execute in the car. Can I compile my cupy code into c++ binary and call that from c++ code?
Upvotes: 2
Views: 764
Reputation: 70
I'm not familiar with CuPy but have a look at the Python C API (https://docs.python.org/3/c-api/). This allows you to run Python functions in C and C++.
Heres an example, running a function called functionname within pythonfile.py (Have not tested this but should be fine).
PyObject* pyModuleStr = PyString_FromString((char*)"pythonfile");
PyObject* pyModule = PyImport_Import(pyModuleStr);
PyObject* pyFunction = PyObject_GetAttrString(pyModule,(char*)"functionname");
PyObject_CallObject(pyFunction);
It is also possible to extract the function's return value, and add arguments.
Hope this helps!
8)
EDIT: Heres a StackOverflow post which may be helpful (Calling a python method from C/C++, and extracting its return value).
Upvotes: 2