Replies: 1 comment
-
Hi @davidhewitt (sorry to ping you specifically, I chose the first maintainer on the list), this is a kind UP as I didn't get reply on this yet :-) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
I am currently trying to extend the JAX Python package with Rust bindings. My goal is to adapt the extending JAX with C++ tutorial to Rust, if possible, using PyO3 and Maturin.
Unfortunately, generating XLA-compatible code heavily relies on C++ features like macros and templates, for which it seems impossible to automatically generate bindings (through
autocxx
, for example). The partial solution I have come up on is to:rms_norm
) in Rust;extern "C"
) back to Rust;PyCapsule
.I could probably stop at step (3) and use, e.g., nanobind to generate the Python module from C++, but my goal is to preferably stick with PyO3 and Maturin, as they are much more convenient in my case :-)
The Rust code looks as follows:
When registering the custom FFI call (inside Python), with:
it somewhat later generates a segmentation fault, so my question is: do I pass the pointer to the C++ function correctly?
When reading the C++ example, they register the callable1 as a
*const void
and store it inside aPyCapsule
. I have tried to mimic this, but yourPyCapsule
constructor doesn't allow explicitly passing a pointer, as it is notSend
, so I cast the function to a function pointer.Thanks for your help!
You can find the full MWE code here: https://github.com/jeertmans/extending-jax/tree/5297b806c8f434030612875e270e3f598ec0e38d
Footnotes
They also wrap the
PyCapsule
inside a lambda-like function, meaning they need to callrms_norm()
to actually return thePyCapsule
, but I don't think this additional level of nesting is necessary, is it? ↩Beta Was this translation helpful? Give feedback.
All reactions