-
Notifications
You must be signed in to change notification settings - Fork 150
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
Rust codegen support #374
Comments
This would be great, and it shouldn't be much work to at least start with a minimal Rust backend. One decision that's going to come up is what matrix library to use for vector and matrix inputs and outputs in the API - SymForce just needs these as containers, we don't need any operators. Ideally it would support representing both dense and sparse matrices, just dense might be ok initially but it would be annoying to use a different library for representing sparse matrices. Also, just noting that the first thing to do here is just codegen support, and a Rust version of the optimizer (either through FFI to the C++ optimizer, or a Rust-native optimizer) would be an additional project. |
Is the linear algebra really only needed for its types? If so, then I would choose one that adds minimal size to the compiled binary. The most use linear algebra library in rust, Does the chosen library need to support n-dimensional arrays, or only vector and matrices? |
For the generated code yes. For the factors we sometimes use Eigen's dense matrix ops to form the linearization, although we don't usually recommend this. More importantly the optimizer uses Eigen's SparseMatrix representation and needs a linear solver (either one from Eigen, or custom). I think we could very well use a library that doesn't provide any linear algebra operations as long as it has the right containers, but I'm not sure how to best do this without thinking about it a little more. We don't need nd arrays, just vectors and matrices, although it might be interesting to expose DataBuffer in Rust as an n-d object if that ends up being easy (we don't currently do this in other languages) |
I had look through the available linear algebra crates and I think |
Nice, thanks for checking! I think it'd make sense to go ahead with |
Has there been any movement here on supporting Rust @avsaase @aaron-skydio? I'd give a +1 to using nalgebra. If there is a work in progress that needs some help I might be able to throw some cycles at it. |
Nothing currently in progress. I think the other matrix library we could use is An example of the codegen part at least is the CUDA backend, sympy also already has a Rust printer so it might be even less work |
I could also really use this! In my mind, the best solution would be to support multiple Rust backend libraries. Ideally, this would involve very little unique code for each. Right now I am using a find-and-replace method to convert the C++ w/ Eigen codegen to Rust with nalgebra. |
I started working on this here. The sympy rust backend doesn't seem all that functional or at least I had to overwrite more than I expected and there are definitely holes still. This is a very rough pass, but I would love to get something minimal in if possible that gets a foothold for working on a more robust backend. |
Initial support was merged here. Thanks Aaron! |
Is your feature request related to a problem? Please describe.
Rust is getting more popular in the embedded space and it would be great if symforce could generate efficient Rust code.
Describe the solution you'd like
Symforce has a Rust codegen backend. Ideally it would also support adding doc comments to the rust code to make it easier to work with the generated code.
Describe alternatives you've considered
Call the generated C++ code from Rust with FFI. I haven't tried this yet but it would certainly be much nicer work with generated Rust code directly.
Additional context
I searched for an existing feature request about this but wasn't able to find one.
The text was updated successfully, but these errors were encountered: