From 72c598c24f47ade8f959c7f31373f2c9e4a8149b Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Fri, 27 Nov 2026 12:45:53 +1100 Subject: [PATCH] chore: pin Rust 1.99.1, add cargo-deny, cargo-shear and Dependabot MSRV 1.85 with resolver 3, sha2 0.11, drop unused temp-env and the dead src/opencl/error.rs. Fix 1.99 lints and single-feature doctests. opencl3 stays at 0.11 as its types are public API. --- .github/dependabot.yml | 25 ++++++ .github/workflows/cargo-shear.yml | 22 +++++ .github/workflows/ci.yml | 117 ++++++++++++++++---------- .github/workflows/deny.yml | 20 +++++ Cargo.toml | 16 ++-- deny.toml | 9 ++ rust-toolchain => rust-toolchain.toml | 2 +- src/cuda/mod.rs | 2 +- src/opencl/error.rs | 35 -------- src/opencl/mod.rs | 2 +- src/program.rs | 16 +--- 11 files changed, 165 insertions(+), 101 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/cargo-shear.yml create mode 100644 .github/workflows/deny.yml create mode 100644 deny.toml rename rust-toolchain => rust-toolchain.toml (71%) delete mode 100644 src/opencl/error.rs diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..4f0de06 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,25 @@ +version: 2 +updates: + - package-ecosystem: "cargo" + directory: "/" + schedule: + interval: "monthly" + cooldown: + default-days: 7 + groups: + # Majors arrive as separate PRs so one that can't build doesn't block the rest + rust: + update-types: ["minor", "patch"] + patterns: + - "*" + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "monthly" + cooldown: + default-days: 7 + groups: + github-actions: + patterns: + - "*" diff --git a/.github/workflows/cargo-shear.yml b/.github/workflows/cargo-shear.yml new file mode 100644 index 0000000..2b36418 --- /dev/null +++ b/.github/workflows/cargo-shear.yml @@ -0,0 +1,22 @@ +# False positives are ignored via `[workspace.metadata.cargo-shear]` or `[package.metadata.cargo-shear]` in the relevant `Cargo.toml`. +name: Cargo Shear +on: + push: + branches: + - master + pull_request: + +permissions: + contents: read + +jobs: + cargo-shear: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Install cargo-shear + uses: taiki-e/install-action@75a7c0f87bd666af3cdb75c5b9e9d03ab6044e6f # v2.90.6 + with: + tool: cargo-shear@1.14.1 + - name: Running cargo-shear + run: cargo shear --deny-warnings --format=github diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cad2ae6..3c56279 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,57 +6,64 @@ on: branches: - master -# Cancel a job if there's a new one on the same branch started. -# Based on https://stackoverflow.com/questions/58895283/stop-already-running-workflow-job-in-github-actions/67223051#67223051 concurrency: - group: ${{ github.ref }} + group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read + env: + RUSTFLAGS: "-Dwarnings" CARGO_INCREMENTAL: 0 RUST_BACKTRACE: 1 - # Faster crates.io index checkout. - CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse - RUST_LOG: debug jobs: - check_clippy: - runs-on: ubuntu-24.04 - name: Clippy - steps: - - uses: actions/checkout@v4 - - name: Run cargo clippy - run: cargo clippy --all-targets --workspace --all-features -- -D warnings - - check_fmt: - runs-on: ubuntu-24.04 - name: Checking fmt + set-msrv: + runs-on: ubuntu-latest + outputs: + msrv: ${{ steps.msrv.outputs.msrv }} + pinned: ${{ steps.msrv.outputs.pinned }} steps: - - uses: actions/checkout@v4 - - name: Run cargo fmt - run: cargo fmt --all -- --check - - rustdoc: - runs-on: ubuntu-24.04 - name: Rustdoc - steps: - - uses: actions/checkout@v4 - - name: Run rustdoc - run: cargo rustdoc --all-features -- -D warnings + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - id: msrv + run: | + echo "msrv=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[0].rust_version')" | tee --append "$GITHUB_OUTPUT" + echo "pinned=$(sed -n 's/^channel = "\(.*\)"$/\1/p' rust-toolchain.toml)" | tee --append "$GITHUB_OUTPUT" - build: - runs-on: ubuntu-24.04 - name: Release build + linux: + needs: set-msrv + runs-on: ubuntu-latest + name: Build and test (${{ matrix.toolchain }}) + strategy: + matrix: + toolchain: + - ${{ needs.set-msrv.outputs.msrv }} + - ${{ needs.set-msrv.outputs.pinned }} + env: + RUSTUP_TOOLCHAIN: ${{ matrix.toolchain }} steps: - - uses: actions/checkout@v4 - - name: Run cargo release build - run: cargo build --release + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Install toolchain + run: rustup toolchain install ${{ matrix.toolchain }} --profile minimal + - name: Install required packages + run: sudo apt-get install --no-install-recommends --yes ocl-icd-opencl-dev + # Checking doesn't link, so CUDA builds need neither the toolkit nor a driver. + - name: Check all feature combinations + run: | + cargo check --all-targets + cargo check --all-targets --no-default-features --features cuda + cargo check --all-targets --no-default-features --features opencl + # GitHub-hosted runners have no GPU or OpenCL platform; device tests run in test_gpu. + - name: Run OpenCL tests + run: cargo test --no-default-features --features opencl -- --skip test_device_all test_gpu: - runs-on: ['self-hosted', 'linux', 'x64', '2xlarge+gpu'] - name: Test + needs: set-msrv + runs-on: ['self-hosted', 'linux', 'x64', 'xlarge+gpu'] + name: Test on GPU steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 # TODO: Move the driver installation to the AMI. # https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-nvidia-driver.html # https://www.nvidia.com/en-us/drivers/ @@ -68,15 +75,39 @@ jobs: sudo apt-get update sudo apt-get install --no-install-recommends --yes cuda-drivers rm nvidia-driver-local-repo-ubuntu2404-570.148.08_1.0-1_amd64.deb - - name: Install required packages + - name: Load NVIDIA kernel modules and verify GPU run: | - sudo apt-get update - sudo apt-get install --no-install-recommends --yes libhwloc-dev nvidia-cuda-toolkit ocl-icd-opencl-dev - # TODO: Remove this and other rust installation directives from jobs running - - uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 + sudo modprobe nvidia + sudo modprobe nvidia-uvm + nvidia-smi + - name: Install required packages + run: sudo apt-get install --no-install-recommends --yes nvidia-cuda-toolkit ocl-icd-opencl-dev + - uses: dtolnay/rust-toolchain@df2a88e9fe4098bad09cb42c3dec7187f15861fc with: - toolchain: 1.81 + toolchain: ${{ needs.set-msrv.outputs.pinned }} - name: Run tests run: cargo test - name: Run `add` example run: cargo run --example add + + clippy_check: + runs-on: ubuntu-latest + name: Clippy + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Run cargo clippy with cuda and opencl features + run: cargo clippy --all-targets -- -D warnings + - name: Run cargo clippy with cuda feature + run: cargo clippy --all-targets --no-default-features --features cuda -- -D warnings + - name: Run cargo clippy with opencl feature + run: cargo clippy --all-targets --no-default-features --features opencl -- -D warnings + + check_fmt_and_docs: + runs-on: ubuntu-latest + name: Checking fmt and docs + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: fmt + run: cargo fmt --all -- --check + - name: Docs + run: cargo rustdoc --all-features -- -D warnings diff --git a/.github/workflows/deny.yml b/.github/workflows/deny.yml new file mode 100644 index 0000000..fb64d26 --- /dev/null +++ b/.github/workflows/deny.yml @@ -0,0 +1,20 @@ +# Runs `cargo-deny` against the workspace: advisories, licences, bans and sources. +# Configuration lives in deny.toml. +name: Cargo Deny +on: + push: + branches: + - master + pull_request: + +permissions: + contents: read + +jobs: + cargo-deny: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: EmbarkStudios/cargo-deny-action@17aeb3c839e42274e2b8adf721c8c65edfdc74dd # v2.1.3 + with: + rust-version: "1.99.1" diff --git a/Cargo.toml b/Cargo.toml index b7c8e76..4c01ab6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,8 @@ edition = "2021" homepage = "https://github.com/filecoin-project/rust-gpu-tools" license = "MIT/Apache-2.0" repository = "https://github.com/filecoin-project/rust-gpu-tools" -rust-version = "1.81.0" +rust-version = "1.85" +resolver = "3" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] @@ -17,12 +18,15 @@ cuda = ["rustacuda"] [dependencies] home = "0.5" -sha2 = "0.10" -thiserror = "2.0.12" -log = "0.4.26" +sha2 = "0.11" +thiserror = "2.0.21" +log = "0.4.29" hex = "0.4.3" opencl3 = { version = "0.11.0", default-features = false, features = ["CL_VERSION_1_2"], optional = true } rustacuda = { package = "fil-rustacuda", version = "0.1.3", optional = true } -once_cell = "1.8.0" -temp-env = "0.3.3" +once_cell = "1.21.3" + +[[example]] +name = "add" +required-features = ["cuda", "opencl"] diff --git a/deny.toml b/deny.toml new file mode 100644 index 0000000..b31292d --- /dev/null +++ b/deny.toml @@ -0,0 +1,9 @@ +[bans] +multiple-versions = "allow" + +[licenses] +allow = [ + "Apache-2.0", + "MIT", + "Unicode-3.0", +] diff --git a/rust-toolchain b/rust-toolchain.toml similarity index 71% rename from rust-toolchain rename to rust-toolchain.toml index 251f956..10427b9 100644 --- a/rust-toolchain +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.81.0" +channel = "1.99.1" components = ["clippy", "rustfmt"] diff --git a/src/cuda/mod.rs b/src/cuda/mod.rs index bdcf83c..f7abe18 100644 --- a/src/cuda/mod.rs +++ b/src/cuda/mod.rs @@ -220,7 +220,7 @@ impl Program { /// number of threads. Instead it follows CUDA's definition and is the number of /// `local_work_size` sized thread groups. So the total number of threads is /// `global_work_size * local_work_size`. - pub fn create_kernel(&self, name: &str, gws: usize, lws: usize) -> GPUResult { + pub fn create_kernel(&self, name: &str, gws: usize, lws: usize) -> GPUResult> { let function_name = CString::new(name).expect("Kernel name must not contain nul bytes"); let function = self.module.get_function(&function_name)?; diff --git a/src/opencl/error.rs b/src/opencl/error.rs deleted file mode 100644 index 0d2f2a0..0000000 --- a/src/opencl/error.rs +++ /dev/null @@ -1,35 +0,0 @@ -use opencl3::{device::DeviceInfo, error_codes::ClError, program::ProgramInfo}; - -#[derive(thiserror::Error, Debug)] -#[allow(clippy::upper_case_acronyms)] -pub enum GPUError { - #[error("Opencl3 Error: {0}{}", match .1 { - Some(message) => format!(" {}", message), - None => "".to_string(), - })] - Opencl3(ClError, Option), - #[error("Device not found!")] - DeviceNotFound, - #[error("Device info not available!")] - DeviceInfoNotAvailable(DeviceInfo), - #[error("Program info not available!")] - ProgramInfoNotAvailable(ProgramInfo), - #[error("Kernel with name {0} not found!")] - KernelNotFound(String), - #[error("IO Error: {0}")] - IO(#[from] std::io::Error), - #[error("Vendor {0} is not supported.")] - UnsupportedVendor(String), - #[error("{0}")] - InvalidId(String), -} - -#[allow(clippy::upper_case_acronyms)] -#[allow(dead_code)] -pub type GPUResult = std::result::Result; - -impl From for GPUError { - fn from(error: ClError) -> Self { - GPUError::Opencl3(error, None) - } -} diff --git a/src/opencl/mod.rs b/src/opencl/mod.rs index c8e32b4..e5fbffe 100644 --- a/src/opencl/mod.rs +++ b/src/opencl/mod.rs @@ -291,7 +291,7 @@ impl Program { name: &str, global_work_size: usize, local_work_size: usize, - ) -> GPUResult { + ) -> GPUResult> { let kernel = self .kernels_by_name .get(name) diff --git a/src/program.rs b/src/program.rs index 26ad503..3f004aa 100644 --- a/src/program.rs +++ b/src/program.rs @@ -192,7 +192,7 @@ macro_rules! program_closures { /// ### Example /// /// ``` -/// use rust_gpu_tools::{cuda, opencl, program_closures}; +/// use rust_gpu_tools::{cuda, program_closures}; /// /// let closures = program_closures!(|program, arg: u8| -> bool { /// true @@ -201,13 +201,7 @@ macro_rules! program_closures { /// // Generates /// let closures = ( /// |program: &cuda::Program, arg: u8| { true }, -/// |program: &opencl::Program, arg: u8| { true }, -/// ); -/// -/// // If e.g. the `cuda` feature is disabled, it would generate -/// let closures_without_cuda = ( /// (), -/// |program: &opencl::Program, arg: u8| { true }, /// ); /// ``` #[macro_export] @@ -246,7 +240,7 @@ macro_rules! program_closures { /// ### Example /// /// ``` -/// use rust_gpu_tools::{cuda, opencl, program_closures}; +/// use rust_gpu_tools::{opencl, program_closures}; /// /// let closures = program_closures!(|program, arg: u8| -> bool { /// true @@ -254,12 +248,6 @@ macro_rules! program_closures { /// /// // Generates /// let closures = ( -/// |program: &cuda::Program, arg: u8| { true }, -/// |program: &opencl::Program, arg: u8| { true }, -/// ); -/// -/// // If e.g. the `cuda` feature is disabled, it would generate -/// let closures_without_cuda = ( /// (), /// |program: &opencl::Program, arg: u8| { true }, /// );