Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pybind11 extended functions and classes support in no python mode #8444

Open
sivansh11 opened this issue Sep 17, 2022 · 6 comments
Open

Pybind11 extended functions and classes support in no python mode #8444

sivansh11 opened this issue Sep 17, 2022 · 6 comments

Comments

@sivansh11
Copy link

Feature request

Pybind11 extended functions and classes support in no python mode,
these are either made into their own binaries (modules) by pybind or are included while emmbdeding (PYBIND11_EMBEDDED_MODULE).

Why use something like this ?
For using python as a scripting language in game engines. Python is super easy to use by anyone, but every one quickly learns about it being slower than compiled languages by orders of magnitudess. But what if someone is able to compile python while being able to use the sea of libraries (my main usecase is with machine learning libraries) that are easily accessible.

I am extremely sorry for not following the proper github issue template, this is my first issue ever.
Please tell me what all I should add to the issue for it to be considered valid issue, I have done a basic search of pybind11 in the issue search bar and didnt get any related result.

@esc
Copy link
Member

esc commented Sep 17, 2022

@sivansh11 thank you for raising this. I would like to clarify, what it is you are trying to access. Are you trying to use Python modules that were written with pybind11 from Numba? Or, are you trying to use the C/C++ libraries that were exposed with pybind11?

This sounds like the following use-case: https://numba.readthedocs.io/en/latest/user/cfunc.html?highlight=cfunc#calling-c-code-from-numba

@sivansh11
Copy link
Author

@esc
Not exactly, I dont have a shared object that I can load in the script, the main executable itself has an embedded library (take a look at https://pybind11.readthedocs.io/en/stable/advanced/embedding.html#adding-embedded-modules).
I wanna be able to call these embedded functions and classes in nopython mode.

I may be wrong, but I did find this http://numba.pydata.org/numba-doc/0.50.0/extending/low-level.html#typing
from my understanding this is useful for creating custom numba understandable types ?

I couldn't get this to work, hence my post for adding a some form of pybind11 support so extending python and numba becomes easier and more performant.

If you need some more information, please feel free to ask, ill try to reply to everything.

@esc
Copy link
Member

esc commented Sep 19, 2022

@sivansh11 ok, thank you for clarifying. This post on our Discourse may potentially be related: https://numba.discourse.group/t/how-to-extend-numba-so-it-supports-pybind11-wrapped-c-struct/1419

@numba numba deleted a comment from sivansh11 Sep 20, 2022
@esc
Copy link
Member

esc commented Sep 20, 2022

@sivansh11 I am so sorry, Github showed me two copies of your latest post and after I tried to delete one of them it seems like Github has deleted both. This was a glitch and entirely unintentional, so sorry, please ask again.

@sivansh11
Copy link
Author

@esc
It's no problem

I don't exactly remember what I wrote, but it was something like this

The link you shared was really helpful,
It showed me i have a bit of learning to do
(About numbas internals and llvm in general)

So just to test my understandings, the link explained how to "tell" numba about my function, what are the expected input parameters and it's types and the expected output parameters and it's types right ?

Also a follow up question, so technically the functions backend doesnt matter, it could be pure python (no decorator jit or njit) it could be pybind11 embedded etc and it would still work in the nopython mode ?

@esc
Copy link
Member

esc commented Sep 29, 2022

@esc It's no problem

I don't exactly remember what I wrote, but it was something like this

The link you shared was really helpful, It showed me i have a bit of learning to do (About numbas internals and llvm in general)

So just to test my understandings, the link explained how to "tell" numba about my function, what are the expected input parameters and it's types and the expected output parameters and it's types right ?

Yes. You tell Numba about your native function, and then you can call it from Numba.

Also a follow up question, so technically the functions backend doesnt matter, it could be pure python (no decorator jit or njit) it could be pybind11 embedded etc and it would still work in the nopython mode ?

I am not sure exactly, but I don't think so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants