HigherOrderCO / HVM

A massively parallel, optimal functional runtime in Rust
https://higherorderco.com
Apache License 2.0
10.42k stars 395 forks source link

Expose hvm_c and hvm_cu in lib.rs #367

Open developedby opened 3 months ago

developedby commented 3 months ago

For people who want to use HVM as a library, it would be useful to give access not only to the rust runtime, but to the C and CUDA runtimes as well.

I want to have this as an option in Bend so that we can provide users with a default HVM version that is guaranteed to work out of the box, removing the need to install HVM as an external dependency and making sure that users always have one option of HVM that is compatible with their version of Bend.

edusporto commented 3 months ago

Something like what I did in the interop branch can be used to do this: https://github.com/HigherOrderCO/HVM/blob/0e9c59636c78d75cc6c05a4a14cc79e87f658155/src/main.rs#L84-L90

net_ptr can then be read back into a Rust Net which could then be used as a library directly, without having to call hvm as a subprocess and read its stdout output.

I changed the original read back function to take an abstract NetReadback, which currently already works for the net coming from C and would take a bit more effort to work with the CUDA implementation. https://github.com/HigherOrderCO/HVM/blob/0e9c59636c78d75cc6c05a4a14cc79e87f658155/src/ast.rs#L399

https://github.com/HigherOrderCO/HVM/blob/0e9c59636c78d75cc6c05a4a14cc79e87f658155/src/interop.rs#L9-L12

Is this an appropriate solution to this issue or are you looking for something else?

developedby commented 3 months ago

Yes, except that hvm_c shouldn't print in that case. Otherwise I'd still need to call it as a subprocess to be able to intercept it's output (which is not that much of a problem)