Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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:
- "*"
22 changes: 22 additions & 0 deletions .github/workflows/cargo-shear.yml
Original file line number Diff line number Diff line change
@@ -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
117 changes: 74 additions & 43 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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
20 changes: 20 additions & 0 deletions .github/workflows/deny.yml
Original file line number Diff line number Diff line change
@@ -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"
16 changes: 10 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"]
9 changes: 9 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[bans]
multiple-versions = "allow"

[licenses]
allow = [
"Apache-2.0",
"MIT",
"Unicode-3.0",
]
2 changes: 1 addition & 1 deletion rust-toolchain → rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.81.0"
channel = "1.99.1"
components = ["clippy", "rustfmt"]
2 changes: 1 addition & 1 deletion src/cuda/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Kernel> {
pub fn create_kernel(&self, name: &str, gws: usize, lws: usize) -> GPUResult<Kernel<'_>> {
let function_name = CString::new(name).expect("Kernel name must not contain nul bytes");
let function = self.module.get_function(&function_name)?;

Expand Down
35 changes: 0 additions & 35 deletions src/opencl/error.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/opencl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl Program {
name: &str,
global_work_size: usize,
local_work_size: usize,
) -> GPUResult<Kernel> {
) -> GPUResult<Kernel<'_>> {
let kernel = self
.kernels_by_name
.get(name)
Expand Down
16 changes: 2 additions & 14 deletions src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -246,20 +240,14 @@ 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
/// });
///
/// // 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 },
/// );
Expand Down