From 198c24e156e24c496b5eba561fd52556216c0896 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 21 Nov 2025 20:52:06 +1100 Subject: [PATCH] Run some unit tests on CI. Most tests are out of reach because they require an NVIDIA GPU, but a few can run. (Ones in `gpu_rand` and `cuda_std` need minor fixes.) Might as well enable them. --- .github/workflows/ci_linux.yml | 12 +++++++++++ .github/workflows/ci_windows.yml | 6 +++--- crates/cuda_std/src/thread.rs | 20 +++++++++++++------ .../src/xoroshiro/xoroshiro128plus.rs | 4 ++-- .../src/xoroshiro/xoroshiro128plusplus.rs | 4 ++-- .../src/xoroshiro/xoroshiro128starstar.rs | 4 ++-- .../gpu_rand/src/xoroshiro/xoshiro128plus.rs | 4 ++-- .../src/xoroshiro/xoshiro128plusplus.rs | 4 ++-- .../src/xoroshiro/xoshiro128starstar.rs | 4 ++-- .../gpu_rand/src/xoroshiro/xoshiro256plus.rs | 4 ++-- .../src/xoroshiro/xoshiro256plusplus.rs | 4 ++-- .../src/xoroshiro/xoshiro256starstar.rs | 4 ++-- .../gpu_rand/src/xoroshiro/xoshiro512plus.rs | 4 ++-- .../src/xoroshiro/xoshiro512plusplus.rs | 4 ++-- .../src/xoroshiro/xoshiro512starstar.rs | 4 ++-- 15 files changed, 53 insertions(+), 33 deletions(-) diff --git a/.github/workflows/ci_linux.yml b/.github/workflows/ci_linux.yml index e60d2f3f..0079fd4b 100644 --- a/.github/workflows/ci_linux.yml +++ b/.github/workflows/ci_linux.yml @@ -171,6 +171,18 @@ jobs: --exclude "cudnn*" ' + # Very limited testing because we can only run tests that don't rely on having a CUDA GPU. + - name: Test + run: | + docker exec "$CONTAINER_NAME" bash -lc 'set -euo pipefail + export RUSTFLAGS=-Dwarnings + cargo test \ + -p cuda_std \ + -p gpu_rand \ + -p nvvm \ + -p rustc_codegen_nvvm + ' + - name: Check documentation run: | docker exec "$CONTAINER_NAME" bash -lc 'set -euo pipefail diff --git a/.github/workflows/ci_windows.yml b/.github/workflows/ci_windows.yml index a5910cf4..9ec20321 100644 --- a/.github/workflows/ci_windows.yml +++ b/.github/workflows/ci_windows.yml @@ -96,9 +96,9 @@ jobs: RUSTFLAGS: -Dwarnings run: cargo clippy --workspace --exclude "optix*" --exclude "path-tracer" --exclude "denoiser" --exclude "vecadd*" --exclude "gemm*" --exclude "ex0*" --exclude "cudnn*" --exclude "sha2*" - # Don't currently test because many tests rely on the system having a CUDA GPU - # - name: Test - # run: cargo test --workspace + # Very limited testing because we can only run tests that don't rely on having a CUDA GPU. + - name: Test + run: cargo test -p cuda_std -p gpu_rand -p nvvm -p rustc_codegen_nvvm - name: Check documentation env: diff --git a/crates/cuda_std/src/thread.rs b/crates/cuda_std/src/thread.rs index 42edbecc..80d79f8b 100644 --- a/crates/cuda_std/src/thread.rs +++ b/crates/cuda_std/src/thread.rs @@ -42,16 +42,24 @@ //! ## Computing global indices (examples) //! //! 1D global thread index: -//! ```rust -//! use cuda_std::thread; -//! let gx = thread::block_idx_x() * thread::block_dim_x() + thread::thread_idx_x(); +//! ```no_run +//! # use cuda_std::kernel; +//! ##[kernel] +//! pub unsafe fn f1d() { +//! use cuda_std::thread; +//! let gx = thread::block_idx_x() * thread::block_dim_x() + thread::thread_idx_x(); +//! } //! ``` //! //! 2D global coordinates (x, y): //! ```rust -//! use cuda_std::thread; -//! let x = thread::block_idx_x() * thread::block_dim_x() + thread::thread_idx_x(); -//! let y = thread::block_idx_y() * thread::block_dim_y() + thread::thread_idx_y(); +//! # use cuda_std::kernel; +//! ##[kernel] +//! pub unsafe fn f2d() { +//! use cuda_std::thread; +//! let x = thread::block_idx_x() * thread::block_dim_x() + thread::thread_idx_x(); +//! let y = thread::block_idx_y() * thread::block_dim_y() + thread::thread_idx_y(); +//! } //! ``` //! //! Note: Hardware limits for block dimensions, grid dimensions, and total threads per block diff --git a/crates/gpu_rand/src/xoroshiro/xoroshiro128plus.rs b/crates/gpu_rand/src/xoroshiro/xoroshiro128plus.rs index cdefec31..cc5e586f 100644 --- a/crates/gpu_rand/src/xoroshiro/xoroshiro128plus.rs +++ b/crates/gpu_rand/src/xoroshiro/xoroshiro128plus.rs @@ -27,8 +27,8 @@ impl Xoroshiro128Plus { /// parallel computations. /// /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoroshiro128Plus; + /// use gpu_rand::xoroshiro::rand_core::SeedableRng; + /// use gpu_rand::xoroshiro::Xoroshiro128Plus; /// /// let rng1 = Xoroshiro128Plus::seed_from_u64(0); /// let mut rng2 = rng1.clone(); diff --git a/crates/gpu_rand/src/xoroshiro/xoroshiro128plusplus.rs b/crates/gpu_rand/src/xoroshiro/xoroshiro128plusplus.rs index dba1dd2e..4dc6138a 100644 --- a/crates/gpu_rand/src/xoroshiro/xoroshiro128plusplus.rs +++ b/crates/gpu_rand/src/xoroshiro/xoroshiro128plusplus.rs @@ -26,8 +26,8 @@ impl Xoroshiro128PlusPlus { /// parallel computations. /// /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoroshiro128PlusPlus; + /// use gpu_rand::xoroshiro::rand_core::SeedableRng; + /// use gpu_rand::xoroshiro::Xoroshiro128PlusPlus; /// /// let rng1 = Xoroshiro128PlusPlus::seed_from_u64(0); /// let mut rng2 = rng1.clone(); diff --git a/crates/gpu_rand/src/xoroshiro/xoroshiro128starstar.rs b/crates/gpu_rand/src/xoroshiro/xoroshiro128starstar.rs index 4adb15fa..03eae7c4 100644 --- a/crates/gpu_rand/src/xoroshiro/xoroshiro128starstar.rs +++ b/crates/gpu_rand/src/xoroshiro/xoroshiro128starstar.rs @@ -26,8 +26,8 @@ impl Xoroshiro128StarStar { /// parallel computations. /// /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoroshiro128StarStar; + /// use gpu_rand::xoroshiro::rand_core::SeedableRng; + /// use gpu_rand::xoroshiro::Xoroshiro128StarStar; /// /// let rng1 = Xoroshiro128StarStar::seed_from_u64(0); /// let mut rng2 = rng1.clone(); diff --git a/crates/gpu_rand/src/xoroshiro/xoshiro128plus.rs b/crates/gpu_rand/src/xoroshiro/xoshiro128plus.rs index baf50929..ae1dcf54 100644 --- a/crates/gpu_rand/src/xoroshiro/xoshiro128plus.rs +++ b/crates/gpu_rand/src/xoroshiro/xoshiro128plus.rs @@ -25,8 +25,8 @@ impl Xoshiro128Plus { /// parallel computations. /// /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoroshiro128StarStar; + /// use gpu_rand::xoroshiro::rand_core::SeedableRng; + /// use gpu_rand::xoroshiro::Xoroshiro128StarStar; /// /// let rng1 = Xoroshiro128StarStar::seed_from_u64(0); /// let mut rng2 = rng1.clone(); diff --git a/crates/gpu_rand/src/xoroshiro/xoshiro128plusplus.rs b/crates/gpu_rand/src/xoroshiro/xoshiro128plusplus.rs index 66e25bc5..cbaaf16d 100644 --- a/crates/gpu_rand/src/xoroshiro/xoshiro128plusplus.rs +++ b/crates/gpu_rand/src/xoroshiro/xoshiro128plusplus.rs @@ -24,8 +24,8 @@ impl Xoshiro128PlusPlus { /// parallel computations. /// /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoroshiro128PlusPlus; + /// use gpu_rand::xoroshiro::rand_core::SeedableRng; + /// use gpu_rand::xoroshiro::Xoroshiro128PlusPlus; /// /// let rng1 = Xoroshiro128PlusPlus::seed_from_u64(0); /// let mut rng2 = rng1.clone(); diff --git a/crates/gpu_rand/src/xoroshiro/xoshiro128starstar.rs b/crates/gpu_rand/src/xoroshiro/xoshiro128starstar.rs index 082d1cf9..c5217e4a 100644 --- a/crates/gpu_rand/src/xoroshiro/xoshiro128starstar.rs +++ b/crates/gpu_rand/src/xoroshiro/xoshiro128starstar.rs @@ -24,8 +24,8 @@ impl Xoshiro128StarStar { /// parallel computations. /// /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoroshiro128StarStar; + /// use gpu_rand::xoroshiro::rand_core::SeedableRng; + /// use gpu_rand::xoroshiro::Xoroshiro128StarStar; /// /// let rng1 = Xoroshiro128StarStar::seed_from_u64(0); /// let mut rng2 = rng1.clone(); diff --git a/crates/gpu_rand/src/xoroshiro/xoshiro256plus.rs b/crates/gpu_rand/src/xoroshiro/xoshiro256plus.rs index 4b2bb8b6..7bdc56a8 100644 --- a/crates/gpu_rand/src/xoroshiro/xoshiro256plus.rs +++ b/crates/gpu_rand/src/xoroshiro/xoshiro256plus.rs @@ -25,8 +25,8 @@ impl Xoshiro256Plus { /// parallel computations. /// /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoshiro256Plus; + /// use gpu_rand::xoroshiro::rand_core::SeedableRng; + /// use gpu_rand::xoroshiro::Xoshiro256Plus; /// /// let rng1 = Xoshiro256Plus::seed_from_u64(0); /// let mut rng2 = rng1.clone(); diff --git a/crates/gpu_rand/src/xoroshiro/xoshiro256plusplus.rs b/crates/gpu_rand/src/xoroshiro/xoshiro256plusplus.rs index 1fddcf54..f3bc98ee 100644 --- a/crates/gpu_rand/src/xoroshiro/xoshiro256plusplus.rs +++ b/crates/gpu_rand/src/xoroshiro/xoshiro256plusplus.rs @@ -24,8 +24,8 @@ impl Xoshiro256PlusPlus { /// parallel computations. /// /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoshiro256PlusPlus; + /// use gpu_rand::xoroshiro::rand_core::SeedableRng; + /// use gpu_rand::xoroshiro::Xoshiro256PlusPlus; /// /// let rng1 = Xoshiro256PlusPlus::seed_from_u64(0); /// let mut rng2 = rng1.clone(); diff --git a/crates/gpu_rand/src/xoroshiro/xoshiro256starstar.rs b/crates/gpu_rand/src/xoroshiro/xoshiro256starstar.rs index d8cef797..0b7e9b27 100644 --- a/crates/gpu_rand/src/xoroshiro/xoshiro256starstar.rs +++ b/crates/gpu_rand/src/xoroshiro/xoshiro256starstar.rs @@ -24,8 +24,8 @@ impl Xoshiro256StarStar { /// parallel computations. /// /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoshiro256StarStar; + /// use gpu_rand::xoroshiro::rand_core::SeedableRng; + /// use gpu_rand::xoroshiro::Xoshiro256StarStar; /// /// let rng1 = Xoshiro256StarStar::seed_from_u64(0); /// let mut rng2 = rng1.clone(); diff --git a/crates/gpu_rand/src/xoroshiro/xoshiro512plus.rs b/crates/gpu_rand/src/xoroshiro/xoshiro512plus.rs index 00e93dfc..7e5e2f8e 100644 --- a/crates/gpu_rand/src/xoroshiro/xoshiro512plus.rs +++ b/crates/gpu_rand/src/xoroshiro/xoshiro512plus.rs @@ -27,8 +27,8 @@ impl Xoshiro512Plus { /// parallel computations. /// /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoshiro512Plus; + /// use gpu_rand::xoroshiro::rand_core::SeedableRng; + /// use gpu_rand::xoroshiro::Xoshiro512Plus; /// /// let rng1 = Xoshiro512Plus::seed_from_u64(0); /// let mut rng2 = rng1.clone(); diff --git a/crates/gpu_rand/src/xoroshiro/xoshiro512plusplus.rs b/crates/gpu_rand/src/xoroshiro/xoshiro512plusplus.rs index 29569529..966b5af0 100644 --- a/crates/gpu_rand/src/xoroshiro/xoshiro512plusplus.rs +++ b/crates/gpu_rand/src/xoroshiro/xoshiro512plusplus.rs @@ -26,8 +26,8 @@ impl Xoshiro512PlusPlus { /// parallel computations. /// /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoshiro512PlusPlus; + /// use gpu_rand::xoroshiro::rand_core::SeedableRng; + /// use gpu_rand::xoroshiro::Xoshiro512PlusPlus; /// /// let rng1 = Xoshiro512PlusPlus::seed_from_u64(0); /// let mut rng2 = rng1.clone(); diff --git a/crates/gpu_rand/src/xoroshiro/xoshiro512starstar.rs b/crates/gpu_rand/src/xoroshiro/xoshiro512starstar.rs index 4ac16705..2f6fd0db 100644 --- a/crates/gpu_rand/src/xoroshiro/xoshiro512starstar.rs +++ b/crates/gpu_rand/src/xoroshiro/xoshiro512starstar.rs @@ -26,8 +26,8 @@ impl Xoshiro512StarStar { /// parallel computations. /// /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoshiro512StarStar; + /// use gpu_rand::xoroshiro::rand_core::SeedableRng; + /// use gpu_rand::xoroshiro::Xoshiro512StarStar; /// /// let rng1 = Xoshiro512StarStar::seed_from_u64(0); /// let mut rng2 = rng1.clone();