Call a `jitclass` method from C/C++?

Hi!
Really happy to use this great project, thanks for that!

My use case is about calling a jitclass (non static) method from C/C++. I’m using pybind11 to create extensions of a C++ lib in Python and would like to rely on numba to make such extensions much more efficient by jitting those parts.

I managed quite easily to use a cfunc to call a free function from C++, but I can’t figure out if it’s possible or not to do the same on a class method with the self arg already managed/bound to the C struct counterpart of the jitclass. I would like to avoid using Python interpreter for performance (incl. acquiring the gil).
Does it looks feasible to get pointers to both C struct and class method and make the call from C/C++ code? Anybody has a pointer of where something similar would be done in numbas codebase?

I feel a bit lost in my attempts to understand how it works and how to do such a thing, sorry if the description is not crystal clear…
Thanks!

Adrien

1 Like

There’s probably a path forward for you… have a look at this as a starting point
I think you’ll want to make standalone entry functions on the numba, but you can use global StructRefs as jitclass doesn’t cache well.

Hi @nelson2005 thanks a lot for the quick answer!
This is exactly the article I used for the cfunc approach, I don’t figure out how to extend this to class methods…
I’ll take a look at the other link! So it looks like composing with cfunc and StructRefs would be a better path than using jitclass?

‘Better’ is relative :slight_smile: but it’s the approach I’ve taken, calling methods of a global StructRef (or one in a container if multiple are needed) from a cfunc (or a njit-func called from a cfunc, njit-funcs and cfuncs have some subtle differences)
This kind of stuff has a bit of a learning curve, so it’s best to make sure to get the foundation solid before moving on too much. Particularly around error handling/exceptions.