Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
rocm-rs: Safe Rust wrappers for AMD ROCm Libraries
This project provides Rust bindings for AMD's ROCm (Radeon Open Compute) libraries, allowing Rust developers to leverage AMD GPUs for high-performance computing.
Current Status
Note: This project is in early development.
Currently implemented:
- ✅ rocFFT - Fast Fourier Transform library (raw bindings + safe wrappers)
- ✅ HIP - Heterogeneous-Compute Interface for Portability (raw bindings + safe wrappers)
- ✅ rocBLAS - Basic Linear Algebra Subprograms (raw bindings + safe wrappers)
- ✅ MIOpen - Deep learning primitives (raw bindings + safe wrappers)
- ✅ rocRAND - Random number generation (raw bindings + safe wrappers)
- ✅ rocSOLVER - Linear system solvers (raw bindings only)
- ✅ rocSPARSE - Sparse linear algebra (raw bindings only)
- ✅ ROCArray - GPU array struct with api similar to Vec (to be deprecated in favor of DeviceMemoryExt)
- ✅ rocmsmi - system managment interface (refer to rocm_smi_lib)
- ✅ rocm_kernel_macros - macros for writing gpu kernels in rust(refer to rocm_kernel_macros)
The project currently focuses on providing raw FFI bindings for most libraries, with safe Rust wrappers available for rocFFT. Additional safe wrappers for other libraries are planned for future development.
Prerequisites
- AMD ROCm installed (version 6.3 or later recommended.It may work on older versions, but I did not test that)
- Ubuntu 24.04 / Fedora 42
- Rust toolchain (1.65.0 or later recommended)
- A compatible AMD GPU
Installation
Add this to your Cargo.toml:
[]
= "4.2"
Usage
First, ensure that the ROCm libraries are in your library path or set the ROCM_PATH environment variable.
Writing your own kernels with rust
use PathBuf;
use ;
use *;
const LEN: usize = 1024;
// initializing rust gpu kernel
amdgpu_kernel_init!;
// marking code that will be coppied to gpu kernel
// compiling gpu kernel
const AMDGPU_KERNEL_BINARY_PATH: &str = amdgpu_kernel_finalize!;
Using rocFFT with safe wrappers:
use ;
Using other libraries with raw bindings:
use *;
Building from Source
Important: When building from source, you need to run cargo build first to generate the bindings files before you can use the library or run tests.
# Clone the repository
# Set the ROCm path if not in the default location
# Build the project (generates bindings)
Feature flags
- rocm_smi - enables bindings and wrappers for rocm_smi_lib
Examples
- hip
- vector_add - example containing kernel written in cpp launched with rocm-rs
- rust_kernel - example containing kernel written in in rust using macros
- rust_kernel_async - example containing kernel written in in rust, using stream to manage memory asynchronously
- saxpy - X = aX+Y
- rand
- normal - generating random numbers with normal distribution
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
When contributing:
- Run
cargo buildfirst to generate the bindings - Add tests for new functionality
- Update documentation as needed
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- AMD for developing and maintaining ROCm
- The Rust community for bindgen and other tools used in this project