| Crates.io | cuda_setup |
| lib.rs | cuda_setup |
| version | 0.1.7 |
| created_at | 2025-01-27 19:56:35.491471+00 |
| updated_at | 2025-08-26 00:30:19.45829+00 |
| description | Assists with CUDA setup when using the CUDARC lib. |
| homepage | |
| repository | https://github.com/David-OConnor/cuda_setup |
| max_upload_size | |
| id | 1532805 |
| size | 10,513 |
This library abstracts over some of the boilerplate needed to use the Cudarc library, for using
CUDA GPU compute in the rust language. Primarily, it compiles of CUDA files (e.g. kernels and supporting code)
to PTX during application build, using the nvcc compiler that comes with CUDA.
Note: You must set the environment var LD_LIBARARY_PATH (Linux) or PATH (Windows) to your CUDA bin
directory, e.g. C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\bin. You may also need the build tools
containing cl.exe or similar in the path, e.g.: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x64
To use, create a build.rs file like this. It will automatically compile a PTX file. You should
package this PTX with your program, either as a file, or included in the binary.
//! We use this to automatically compile CUDA C++ code when building.
use cuda_setup::{build, GpuArchitecture};
fn main() {
// -This first parameter is the minimum GPU architecture that will be compatible.
// -The second parameter is a list of paths to all kernels to compile.
// The first kernel passed must be the entry point. All others are just to watch for changes to trigger
// a new compilation.
// -The third parameter is the name of the PTX file to output.
build(GpuArchitecture::Rtx4, &vec!["src/cuda/cuda.cu", "src/cuda/util.cu"], "my_program");
}
Or if your application has CUDA feature-gated:
//! We use this to automatically compile CUDA C++ code when building.
#[cfg(feature = "cuda")]
use cuda_setup::{build, GpuArchitecture};
fn main() {
#[cfg(feature = "cuda")]
build(GpuArchitecture::Rtx4, &vec!["src/cuda/cuda.cu", "src/cuda/util.cu"]);
}
Include this in Cargo.toml:
[build-dependencies]
# For compiling kernels to PTX.
cuda_setup = "0.1.4"