Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tmrob2/cuda2rust_sandpit
Minimal examples to get CUDA linear algebra programs working with Rust using CC & FFI.
https://github.com/tmrob2/cuda2rust_sandpit
cc clang cublas cuda cusparse rust
Last synced: 2 months ago
JSON representation
Minimal examples to get CUDA linear algebra programs working with Rust using CC & FFI.
- Host: GitHub
- URL: https://github.com/tmrob2/cuda2rust_sandpit
- Owner: tmrob2
- Created: 2022-10-20T01:04:29.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-23T03:12:33.000Z (over 2 years ago)
- Last Synced: 2024-08-04T02:06:44.660Z (6 months ago)
- Topics: cc, clang, cublas, cuda, cusparse, rust
- Language: Rust
- Homepage:
- Size: 13.7 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-cuda-triton-hpc - tmrob2/cuda2rust_sandpit
- awesome-cuda-triton-hpc - tmrob2/cuda2rust_sandpit
- awesome-rust-list - tmrob2/cuda2rust_sandpit
- awesome-rust-list - tmrob2/cuda2rust_sandpit
README
# cuda2rust_sandpit
Simplest configuration and testing of Rust sparse matrix
data structures for sparse matrix linear algebra on CUDA.First, define a `build.rs` which configures the linking of
cuda libs necessary for computation. Then `C` libraries are
created under `myclib` which creates the most basic interface for controlling cuBlas and cuSparse linalg routines.A very simple FFI is constructed in `lib.rs` which references functions in `myclib`, and `build.rs` manages the construction of the dynamic shared library using:
```Rust
cc::Build::new()
.file("myclib/mycfuncs.c")
.file("myclib/test_cublas.c")
.file("myclib/test_cusparse.c")
.file("myclib/sparse_funcs.c")
.cuda(true)
.compile("mycfuncs");
```The idea is to manage memory using Rust, bue still leverage the low level power of CUDA which is most conveniently accessed via a custom `C` library.
## Why not use `cuBlas` FFI?
I don't see any point in using a monolithic FFI for CUDA libs when it is clear that CUDA interfaces will not be natively written in `Rust` any time soon. Further, there is no FFI for `cuSparse` which is arguably the more important CUDA library.
It is much easier to write a small implementation using the `cuSparse` header and then create a small FFI related to a `Rust` project, which is playing to the strengths of both languages.
## Implementation Notes
A quick note on `build.rs` linking ordering. For `cargo test` to work the linked libraries need to go after `cc::Build::new()` otherwise a linking error will be generated, i.e.:
```Rust
cc::Build::new()
.file("myclib/mycfuncs.c")
.file("myclib/test_cublas.c")
.file("myclib/test_cusparse.c")
.cuda(true)
.compile("mycfuncs");
println!("cargo:rustc-link-lib=dylib=cublas");
```## Tests
Run lib tests with `cargo test`.