MCPcopy Index your code
hub / github.com/Rust-GPU/rust-cuda

github.com/Rust-GPU/rust-cuda @0.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.3 ↗ · + Follow
3,113 symbols 6,561 edges 255 files 621 documented · 20%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

The Rust CUDA Project

<strong>An ecosystem of libraries and tools for writing and executing extremely fast GPU code fully in 
<a href="https://www.rust-lang.org/">Rust</a></strong>

Guide | Getting Started | Features

⚠️ The project is still in early development, expect bugs, safety issues, and things that don't work ⚠️

Goal

The Rust CUDA Project is a project aimed at making Rust a tier-1 language for extremely fast GPU computing using the CUDA Toolkit. It provides tools for compiling Rust to extremely fast PTX code as well as libraries for using existing CUDA libraries with it.

Background

Historically, general purpose high performance GPU computing has been done using the CUDA toolkit. The CUDA toolkit primarily provides a way to use Fortran/C/C++ code for GPU computing in tandem with CPU code with a single source. It also provides many libraries, tools, forums, and documentation to supplement the single-source CPU/GPU code.

CUDA is exclusively an NVIDIA-only toolkit. Many tools have been proposed for cross-platform GPU computing such as OpenCL, Vulkan Computing, and HIP. However, CUDA remains the most used toolkit for such tasks by far. This is why it is imperative to make Rust a viable option for use with the CUDA toolkit.

However, CUDA with Rust has been a historically very rocky road. The only viable option until now has been to use the LLVM PTX backend, however, the LLVM PTX backend does not always work and would generate invalid PTX for many common Rust operations, and 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 of projects such as rust-gpu (for Rust -> SPIR-V).

Our hope is that with this project we can push the Rust GPU computing industry forward and make Rust an excellent language for such tasks. Rust offers plenty of benefits such as __restrict__ performance benefits for every kernel, An excellent module/crate system, delimiting of unsafe areas of CPU/GPU code with unsafe, high level wrappers to low level CUDA libraries, etc.

Structure

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 usable using Rust. Therefore, the project contains many crates for all corners of the CUDA ecosystem.

The current line-up of libraries is the following:

  • rustc_codegen_nvvm Which is a rustc backend that targets NVVM IR (a subset of LLVM IR) for the libnvvm library.
  • Generates highly optimized PTX code which can be loaded by the CUDA Driver API to execute on the GPU.
  • For the near future it will be CUDA-only, but it may be used to target amdgpu in the future.
  • cuda_std for GPU-side functions and utilities, such as thread index queries, memory allocation, warp intrinsics, etc.
  • Not a low level library, provides many utility functions to make it easier to write cleaner and more reliable GPU kernels.
  • Closely tied to rustc_codegen_nvvm which exposes GPU features through it internally.
  • cust for CPU-side CUDA features such as launching GPU kernels, GPU memory allocation, device queries, etc.
  • High level with features such as RAII and Rust Results that make it easier and cleaner to manage the interface to the GPU.
  • A high level wrapper for the CUDA Driver API, the lower level version of the more common CUDA Runtime API used from C++.
  • Provides much more fine grained control over things like kernel concurrency and module loading than the C++ Runtime API.
  • gpu_rand for GPU-friendly random number generation, currently only implements xoroshiro RNGs from rand_xoshiro.
  • optix for CPU-side hardware raytracing and denoising using the CUDA OptiX library.

In addition to many "glue" crates for things such as high level wrappers for certain smaller CUDA libraries.

Related Projects

Other projects related to using Rust on the GPU: - 2016: glassful Subset of Rust that compiles to GLSL. - 2017: inspirv-rust Experimental Rust MIR -> SPIR-V Compiler. - 2018: nvptx Rust to PTX compiler using the nvptx target for rustc (using the LLVM PTX backend). - 2020: accel Higher level library that relied on the same mechanism that nvptx does. - 2020: rlsl Experimental Rust -> SPIR-V compiler (predecessor to rust-gpu) - 2020: rust-gpu Rustc codegen backend to compile Rust to SPIR-V for use in shaders, similar mechanism as our project.

License

Licensed under either of

  • Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your discretion.

Contribution

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.

Extension points exported contracts — how you extend this code

DeviceCopy (Interface)
Marker trait for types which can safely be copied to or from a CUDA device. A type can be safely copied if its value ca [30 …
crates/cust_core/src/lib.rs
OpTensorOp (Interface)
A tensor core operation. [6 implementers]
crates/cudnn/src/op_tensor/op_tensor_op.rs
CopyDestination (Interface)
Sealed trait implemented by types which can be the source or destination when copying data to/from the device or from on [6 …
crates/cust/src/memory/device/mod.rs
Vertex (Interface)
Trait allowing the triangle builds to be generic over the input vertex data. For instance, if you had a custom vertex t [13 …
crates/optix/src/acceleration.rs
FloatExt (Interface)
Extension trait for [`f32`] and [`f64`] which provides high level functions for low level intrinsics for common math ope [2 …
crates/cuda_std/src/float_ext.rs
BlasDatatype (Interface)
(no doc) [4 implementers]
crates/blastoff/src/lib.rs
Material (Interface)
(no doc) [3 implementers]
examples/cuda/gpu/path_tracer_gpu/src/material.rs
LayoutLlvmExt (Interface)
exists in rustc_codegen_llvm but cant use it because its private :'( [1 implementers]
crates/rustc_codegen_nvvm/src/ty.rs

Core symbols most depended-on inside this repo

new
called by 390
crates/ptx/src/parser.rs
as_ptr
called by 229
crates/cust/src/memory/pointer.rs
unwrap
called by 171
crates/rustc_codegen_nvvm/rustc_llvm_wrapper/RustWrapper.cpp
len
called by 168
crates/cust/src/memory/device/device_slice.rs
to_result
called by 156
crates/cust/src/error.rs
push
called by 124
crates/cust/src/legacy.rs
as_device_ptr
called by 124
crates/cust/src/memory/device/device_box.rs
cast
called by 99
crates/cust/src/memory/pointer.rs

Shape

Method 1,336
Function 895
Class 504
Enum 308
Interface 70

Languages

Rust85%
C++14%
C1%

Modules by API surface

crates/cust_raw/src/cuda.rs236 symbols
crates/rustc_codegen_nvvm/rustc_llvm_wrapper/RustWrapper.cpp139 symbols
crates/rustc_codegen_nvvm/src/builder.rs111 symbols
crates/cudnn/src/sys.rs89 symbols
crates/rustc_codegen_nvvm/rustc_llvm_wrapper/PassWrapper.cpp69 symbols
crates/rustc_codegen_nvvm/src/debug_info/metadata.rs67 symbols
crates/optix/src/acceleration.rs66 symbols
crates/rustc_codegen_nvvm/src/ty.rs59 symbols
crates/optix/optix_wrapper.rs53 symbols
crates/cust/src/memory/array.rs52 symbols
crates/cust/src/memory/unified.rs50 symbols
crates/rustc_codegen_nvvm/src/llvm.rs44 symbols

For agents

$ claude mcp add rust-cuda \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact