|
1 |
| -# Rust CUDA |
| 1 | +<div align="center"> |
| 2 | + <h1>The Rust CUDA Project</h1> |
| 3 | + |
| 4 | + <p> |
| 5 | + <strong>An ecosystem of libraries and tools for writing and executing extremely fast GPU code fully in |
| 6 | + <a href="https://www.rust-lang.org/">Rust</a></strong> |
| 7 | + </p> |
| 8 | + |
| 9 | + <h3> |
| 10 | + <a href="guide">Guide</a> |
| 11 | + <span> | </span> |
| 12 | + <a href="guide/src/guide/getting_started.md">Getting Started</a> |
| 13 | + <span> | </span> |
| 14 | + <a href="guide/src/features.md">Features</a> |
| 15 | + </h3> |
| 16 | +<strong>⚠️ The project is still in early development, expect bugs, safety issues, and things that don't work ⚠️</strong> |
| 17 | +</div> |
| 18 | + |
| 19 | +## Goal |
| 20 | + |
| 21 | +The Rust CUDA Project is a project aimed at making Rust a tier-1 language for extremely fast GPU computing |
| 22 | +using the CUDA Toolkit. It provides tools for compiling Rust to extremely fast PTX code as well as libraries |
| 23 | +for using existing CUDA libraries with it. |
| 24 | + |
| 25 | +## Background |
| 26 | + |
| 27 | +Historically, general purpose high performance GPU computing has been done using the CUDA toolkit. The CUDA toolkit primarily |
| 28 | +provides a way to use Fortran/C/C++ code for GPU computing in tandem with CPU code with a single source. It also provides |
| 29 | +many libraries, tools, forums, and documentation to supplement the single-source CPU/GPU code. |
| 30 | + |
| 31 | +CUDA is exclusively an NVIDIA-only toolkit. Many tools have been proposed for cross-platform GPU computing such as |
| 32 | +OpenCL, Vulkan Computing, and HIP. However, CUDA remains the most used toolkit for such tasks by far. This is why it is |
| 33 | +imperative to make Rust a viable option for use with the CUDA toolkit. |
| 34 | + |
| 35 | +However, CUDA with Rust has been a historically very rocky road. The only viable option until now has been to use the LLVM PTX |
| 36 | +backend, however, the LLVM PTX backend does not always work and would generate invalid PTX for many common Rust operations, and |
| 37 | +in recent years it has been shown time and time again that a specialized solution is needed for Rust on the GPU with the advent |
| 38 | +of projects such as rust-gpu (for Rust -> SPIR-V). |
| 39 | + |
| 40 | +Our hope is that with this project we can push the Rust GPU computing industry forward and make Rust an excellent language |
| 41 | +for such tasks. Rust offers plenty of benefits such as `__restrict__` performance benefits for every kernel, An excellent module/crate system, |
| 42 | +delimiting of unsafe areas of CPU/GPU code with `unsafe`, high level wrappers to low level CUDA libraries, etc. |
| 43 | + |
| 44 | +## Structure |
| 45 | + |
| 46 | +The scope of the Rust CUDA Project is quite broad, it spans the entirety of the CUDA ecosystem, with libraries and tools to make it |
| 47 | +usable using Rust. Therefore, the project contains many crates for all corners of the CUDA ecosystem. |
| 48 | + |
| 49 | +The current line-up of libraries is the following: |
| 50 | + |
| 51 | +- `rustc_codegen_nvvm` Which is a rustc backend that targets NVVM IR (a subset of LLVM IR) for the [libnvvm](https://docs.nvidia.com/cuda/nvvm-ir-spec/index.html) library. |
| 52 | + - Generates highly optimized PTX code which can be loaded by the CUDA Driver API to execute on the GPU. |
| 53 | + - For the near future it will be CUDA-only, but it may be used to target amdgpu in the future. |
| 54 | +- `cuda_std` for GPU-side functions and utilities, such as thread index queries, memory allocation, warp intrinsics, etc. |
| 55 | + - *Not* a low level library, provides many utility functions to make it easier to write cleaner and more reliable GPU kernels. |
| 56 | + - Closely tied to `rustc_codegen_nvvm` which exposes GPU features through it internally. |
| 57 | +- `cust` for CPU-side CUDA features such as launching GPU kernels, GPU memory allocation, device queries, etc. |
| 58 | + - High level with features such as RAII and Rust Results that make it easier and cleaner to manage the interface to the GPU. |
| 59 | + - A high level wrapper for the CUDA Driver API, the lower level version of the more common CUDA Runtime API used from C++. |
| 60 | + - Provides much more fine grained control over things like kernel concurrency and module loading than the C++ Runtime API. |
| 61 | +- `gpu_rand` for GPU-friendly random number generation, currently only implements xoroshiro RNGs from `rand_xoshiro`. |
| 62 | +- `optix` for CPU-side hardware raytracing and denoising using the CUDA OptiX library. |
| 63 | + |
| 64 | +In addition to many "glue" crates for things such as high level wrappers for certain smaller CUDA libraries. |
| 65 | + |
| 66 | +## Related Projects |
| 67 | + |
| 68 | +Other projects related to using Rust on the GPU: |
| 69 | +- 2016: [glassful](https://github.com/kmcallister/glassful) Subset of Rust that compiles to GLSL. |
| 70 | +- 2017: [inspirv-rust](https://github.com/msiglreith/inspirv-rust) Experimental Rust MIR -> SPIR-V Compiler. |
| 71 | +- 2018: [nvptx](https://github.com/japaric-archived/nvptx) Rust to PTX compiler using the `nvptx` target for rustc (using the LLVM PTX backend). |
| 72 | +- 2020: [accel](https://github.com/termoshtt/accel) Higher level library that relied on the same mechanism that `nvptx` does. |
| 73 | +- 2020: [rlsl](https://github.com/MaikKlein/rlsl) Experimental Rust -> SPIR-V compiler (predecessor to rust-gpu) |
| 74 | +- 2020: [rust-gpu](https://github.com/EmbarkStudios/rust-gpu) Rustc codegen backend to compile Rust to SPIR-V for use in shaders, similar mechanism as our project. |
| 75 | + |
| 76 | +## License |
| 77 | + |
| 78 | +Licensed under either of |
| 79 | + |
| 80 | +- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) |
| 81 | +- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) |
| 82 | + |
| 83 | +at your discretion. |
| 84 | + |
| 85 | +### Contribution |
| 86 | + |
| 87 | +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. |
2 | 88 |
|
3 |
| -TODO: the entire readme |
|
0 commit comments