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

Bindings for other languages? #30

Open
mishushakov opened this issue Jul 19, 2021 · 6 comments
Open

Bindings for other languages? #30

mishushakov opened this issue Jul 19, 2021 · 6 comments

Comments

@mishushakov
Copy link

hey,
yesterday, i had an idea of using vst-rs, which is a Rust implementation of VST

in order to generate Rust bindings, i tried using bindgen, but it failed, because the code in RTNeural has some template-related code

i'm wondering whether you'd be interested in making RTNeural more compatible with other languages in the future?

@jatinchowdhury18
Copy link
Owner

Yes, I would definitely like to support Rust, though from doing a bit of research, it seems like it may be a somewhat daunting task!

For the dynamically implemented layers in RTNeural, the only template parameter is the data type (i.e. float or double), so we could probably work out a way to feed code into bindgen that would work. Unfortunately, for the more optimized statically implemented layers, the template parameters also cover things like the layer sizes, so until bindgen can handle templates, I don't think it would be possible to automatically generate bindings for those classes. Further, the library backends for RTNeural (Eigen and xsimd) don't have Rust bindings yet either (at least to my knowledge), likely due to the same limitations of templates.

Would it be possible to share the output of bindgen that was failing for you? It may be possible use macros to remove some of the problematic code when generating the Rust bindings.

In general though, I think this issue may require some minds with more Rust experience than I have under my belt :).

Thanks,
Jatin

@mishushakov
Copy link
Author

thanks for the detailed response

also i found the cxx module, which allows to interprop Rust and C++

would be cool to try out someday

@rcelha
Copy link

rcelha commented Jul 28, 2023

I've put something together rather quickly today to test with some vst in rust I have https://github.com/rcelha/rtneural-rs

I haven't tested it for real-time stuff yet tho

@jatinchowdhury18
Copy link
Owner

jatinchowdhury18 commented Jul 28, 2023

I've put something together rather quickly today to test with some vst in rust I have https://github.com/rcelha/rtneural-rs

I haven't tested it for real-time stuff yet tho

This looks very promising, thanks for sharing!

I had been concerned with how inter-operation might work given the highly-templated nature of RTNeural, but I see how that's working in your code with the "wrapper.h" file, basically constructing a non-templated wrapper of the template class. Very cool! I imagine it would be a little bit more complicated to support RTNeural::ModelT, since every model architecture would probably need its own wrapper class? But the wrapper classes could be generated programmatically, so it probably wouldn't be too bad.

I'd also be curious how the Rust vs. C++ performance would compare, since the inferencing calls are going through Rust's FFI. Probably won't make much difference for RTNeural::Model, but I imagine it could be more significant for RTNeural::ModelT.

Anyway, this looks really cool! I'll have to spend some time getting more familiar with it this weekend :)

@rcelha
Copy link

rcelha commented Jul 28, 2023

I am glad you like it!

I am not too concerned over performance, I developed a plugin in C++ (JUCE) in which most of the logic was in Rust, then Rust was talking to another Library in C (OnnxRuntime). It was all mostly fine, as there is not much copying and allocating around.

I am gonna try to put an example together with nih-plug to get a few for how that is gonna behave in real world tho.

@rcelha
Copy link

rcelha commented Jul 30, 2023

@jatinchowdhury18 you can check out the sample project I've put together over a few hours rcelha/rtneural-rs#1

Latency was pretty good across the board, although I didn't profile it. I was able to run a bunch models from AIDA-X with many different sample size configuration (the lowest my sound card goes is 32 samples).

*On a side note, I was trying to find some info on possible overhead between Rust/C interop: https://blog.rust-lang.org/2015/04/24/Rust-Once-Run-Everywhere.html

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

No branches or pull requests

3 participants