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.
Disclaimer
This project is not affiliated with, endorsed by, or sponsored by Advanced Micro Devices, Inc. (AMD).
ROCm and AMD are trademarks of Advanced Micro Devices, Inc.
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 + safe wrappers)
- ✅ 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:
[]
= "5.1"
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 ;
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!;
For async operations with streams:
use PathBuf;
use ;
const LEN: usize = 1024;
amdgpu_kernel_init!;
const AMDGPU_KERNEL_BINARY_PATH: &str = amdgpu_kernel_finalize!;
### Using rocFFT with safe wrappers:
```rust
use rocm_rs::rocfft::{self, plan, execution, field};
fn main() {
// Initialize the rocFFT library
// Use the safe wrappers for rocFFT
let plan = plan::Plan::new(/* parameters */);
let field = field::Field::new(/* parameters */);
let execution = execution::Execution::new(/* parameters */);
// Perform FFT operations
// ...
}
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
The project includes a workspace with examples for each sub-library. Run examples with:
HIP
vector_add_example- Vector addition with kernel written in HIPrust_kernel- Kernel written in Rust using macrosrust_kernel_async- Async kernel execution with streamssaxpy- SAXPY operation (Single-precision A*X + Y)sort- GPU sorting example
MIOpen
miopen_basic- Basic MIOpen usage examplemulti_tensor- Multi-tensor operations
rocBLAS
rocblas_basic- Basic rocBLAS usage example
rocRAND
normal- Random number generation 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