CEED / libCEED

CEED Library: Code for Efficient Extensible Discretizations
https://libceed.org
BSD 2-Clause "Simplified" License
187 stars 45 forks source link

More advanced Rust binding examples #1621

Open eliasboegel opened 4 days ago

eliasboegel commented 4 days ago

Hi,

I'm wondering whether there are any more advanced examples or, even better, research codes using the Rust bindings outside of the libceed repository that go into more depth than just a mass or stiffness matrix. I'm especially looking for some example codes that use the libceed bindings, as well as petsc-rs (and possibly rsmpi) bindings, just showing how the different binding APIs of libceed and petsc-rs interact. Does anything like this exist?

Thanks!

jeremylt commented 4 days ago

Such examples don't exist currently. I do want to make some but it hasn't bubbled to the top of my list yet

eliasboegel commented 13 hours ago

On a related note: Is there an overview of the limitations of using the Rust bindings to libceed anywhere? I remember Jed mentioning that device acceleration is unavailable with the Rust binding in a Rust talk (due to lack of kernel fusion?), but I couldn't actually find anything mentioning this in the docs. Is that still a limitation, and are there any others?

jeremylt commented 13 hours ago

That's correct, at this time only QFunctions written in C can be used via the Rust interface on the device (QFunctions created from the 'gallery'). QFunction source written in Rust can only be run by the CPU backends. The Julia wrapper can compile user QFunction code for CUDA backends but we haven't figured out something similar for Rust yet.

eliasboegel commented 12 hours ago

Thanks - do I then understand correctly that it is possible to get full device acceleration with the Rust bindings if the QFunction is written in C, with everything else using the bindings? What would be the correct way to do this?

I have similar questions about the practical limitations of the PETSc bindings, but those are probably better kept in a petsc-rs issue.

jeremylt commented 12 hours ago

So currently we don't have the ability to make a new QFunction in C from the Rust interface and pass it to the GPU backends, but that should be relatively straightforward to set up if you would like that.

Only the current QFunctions available here can be used on the GPU from Rust:

https://github.com/CEED/libCEED/tree/main/gallery

https://docs.rs/libceed/latest/libceed/qfunction/struct.QFunctionByName.html

Wrapping a libCEED operator in a MatShell in Rust is probably the other missing piece you need. I don't have an example of that due to getting lost with lifelines being tangled

eliasboegel commented 12 hours ago

No worries. Thank you for all the information provided so far!

jeremylt commented 11 hours ago

It's incomplete but here's as far as I got with using the two Rust wrappers together

https://github.com/jeremylt/meles-rs

jeremylt commented 11 hours ago

Note to me - merging MatCEED upstream will help with those timelines I think