From 7f40f1f9f4f9017fd392f7772853f3d5682aad10 Mon Sep 17 00:00:00 2001 From: Yang Zhou Date: Sat, 18 Jan 2025 11:28:11 -0500 Subject: [PATCH] [FIX] pool cuda support for windows platform (#227) * [FIX] (cu29_runtime) pool for windows cuda cfg * [FEAT] (CI) separate CUDA and non-CUDA Unit Tests * [FIX] (CI) remove cuda feature for Unit Tests (non-cuda) * [CHORE] (CI) add cuda-release mode in Unit-Tests for cleaning * [FIX] (CI) FEATURES_FLAG * [FIX] (CI) FEATURES_FLAG for windows --- .github/workflows/general.yml | 45 ++++++++++++++++++++++------------- core/cu29_runtime/Cargo.toml | 2 +- core/cu29_runtime/src/pool.rs | 8 +++---- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/.github/workflows/general.yml b/.github/workflows/general.yml index 0f5ecafb0..5a35a3318 100644 --- a/.github/workflows/general.yml +++ b/.github/workflows/general.yml @@ -18,7 +18,7 @@ jobs: strategy: matrix: os: [ ubuntu-latest, macos-latest, windows-latest ] - mode: [ debug, release ] + mode: [ debug, release, cuda-release] steps: - uses: actions/checkout@v4 @@ -37,17 +37,16 @@ jobs: run: cargo +stable fmt --all -- --check - name: Free Disk Space (Ubuntu) - if: runner.os == 'Linux' + if: runner.os == 'Linux' && matrix.mode == 'cuda-release' uses: jlumbroso/free-disk-space@main with: # this might remove tools that are actually needed, # if set to "true" but frees about 6 GB tool-cache: false - # all of these default to true, but feel free to set to - # "false" if necessary for your workflow android: true dotnet: true haskell: true + # do not remove large-packages, as it is necessary large-packages: false docker-images: true swap-storage: true @@ -56,12 +55,6 @@ jobs: if: runner.os == 'Linux' run: sudo apt-get update && sudo apt-get install -y libudev-dev libpcap-dev - - name: Install CUDA - uses: Jimver/cuda-toolkit@master - if: runner.os != 'macOS' - with: - log-file-suffix: '${{ matrix.os }}-${{ matrix.mode }}.txt' - - name: Install dependencies (Windows) if: runner.os == 'Windows' run: | @@ -71,22 +64,42 @@ jobs: winget install DaiyuuNobori.Win10Pcap --accept-source-agreements --accept-package-agreements Add-Content -Path $env:GITHUB_ENV -Value "LIB=$env:USERPROFILE\npcap-sdk\Lib\x64" + - name: Install CUDA + uses: Jimver/cuda-toolkit@master + if: runner.os != 'macOS' && matrix.mode == 'cuda-release' + with: + log-file-suffix: '${{ matrix.os }}-${{ matrix.mode }}-cuda.txt' + - name: Set build mode (Linux / MacOS) - if: runner.os != 'Windows' - run: echo "RELEASE_FLAG=$([[ '${{ matrix.mode }}' == 'release' ]] && echo '--release' || echo '')" >> $GITHUB_ENV + if: runner.os != 'Windows' && ( matrix.mode == 'release' || matrix.mode == 'cuda-release' ) + run: echo "RELEASE_FLAG=--release" >> $GITHUB_ENV - name: Set build mode (Windows) - if: runner.os == 'Windows' && matrix.mode == 'release' + if: runner.os == 'Windows' && ( matrix.mode == 'release' || matrix.mode == 'cuda-release' ) run: | Add-Content -Path $env:GITHUB_ENV -Value "RELEASE_FLAG=--release" + - name: Set features (Linux / MacOS) + if: runner.os != 'Windows' + run: echo "FEATURES_FLAG=$([[ '${{ matrix.mode }}' == 'cuda-release' ]] && echo '--all-features' || echo '--features macro_debug,mock,iyes_perf_ui,image,kornia')" >> $GITHUB_ENV + + - name: Set features (Windows) + if: runner.os == 'Windows' + run: | + $features = if ($env:matrix_mode -eq 'cuda-release') { + '--all-features' + } else { + '--features macro_debug,mock,iyes_perf_ui,image,kornia' + } + Add-Content -Path $env:GITHUB_ENV -Value "FEATURES_FLAG=$features" + # Run Clippy and build - name: Run clippy on (${{ matrix.os }} | ${{matrix.mode}}) run: cargo +stable clippy $RELEASE_FLAG --workspace --all-targets -- --deny warnings - name: Run clippy with all features on (${{ matrix.os }} | ${{matrix.mode}}) - run: cargo +stable clippy $RELEASE_FLAG --workspace --all-targets --all-features -- --deny warnings + run: cargo +stable clippy $RELEASE_FLAG --workspace --all-targets $FEATURES_FLAG -- --deny warnings - name: Run build with all features on (${{ matrix.os }} | ${{matrix.mode}}) - run: cargo +stable build $RELEASE_FLAG --workspace --all-targets --all-features + run: cargo +stable build $RELEASE_FLAG --workspace --all-targets $FEATURES_FLAG - name: Run doctests on (${{ matrix.os }} | debug) if: matrix.mode == 'debug' @@ -96,7 +109,7 @@ jobs: - name: Run Unit Tests on (${{ matrix.os }} | ${{matrix.mode}}) run: cargo +stable nextest run $RELEASE_FLAG --all-targets --workspace - name: Run Unit Tests with all features on (${{ matrix.os }} | ${{matrix.mode}}) - run: cargo +stable nextest run $RELEASE_FLAG --all-targets --workspace --all-features + run: cargo +stable nextest run $RELEASE_FLAG --all-targets --workspace $FEATURES_FLAG # Run Project Generation Tests - name: Install cargo-generate on (${{ matrix.os }} | debug) diff --git a/core/cu29_runtime/Cargo.toml b/core/cu29_runtime/Cargo.toml index 6a45e7c48..53a9f25b4 100644 --- a/core/cu29_runtime/Cargo.toml +++ b/core/cu29_runtime/Cargo.toml @@ -39,7 +39,7 @@ hdrhistogram = "7.5.4" petgraph = { version = "0.7.1", features = ["serde", "serde-1", "serde_derive"] } object-pool = "0.6.0" -[target.'cfg(target_os = "linux")'.dependencies] +[target.'cfg(not(target_os = "macos"))'.dependencies] cudarc = { version = "0.13", optional = true, features = ["cuda-version-from-build-system"] } [features] diff --git a/core/cu29_runtime/src/pool.rs b/core/cu29_runtime/src/pool.rs index b6b0629fd..b611f5e95 100644 --- a/core/cu29_runtime/src/pool.rs +++ b/core/cu29_runtime/src/pool.rs @@ -209,7 +209,7 @@ impl ArrayLike for Vec { type Element = E; } -#[cfg(all(feature = "cuda", target_os = "linux"))] +#[cfg(all(feature = "cuda", not(target_os = "macos")))] mod cuda { use super::*; use cudarc::driver::{CudaDevice, CudaSlice, DeviceRepr, ValidAsZeroBits}; @@ -443,7 +443,7 @@ impl Drop for AlignedBuffer { #[cfg(test)] mod tests { use super::*; - #[cfg(all(feature = "cuda", target_os = "linux"))] + #[cfg(all(feature = "cuda", not(target_os = "macos")))] use crate::pool::cuda::CuCudaPool; use std::cell::RefCell; @@ -475,7 +475,7 @@ mod tests { assert!(obj5.is_none()); } - #[cfg(all(feature = "cuda", target_os = "linux"))] + #[cfg(all(feature = "cuda", not(target_os = "macos")))] #[test] #[ignore] // Can only be executed if a real CUDA device is present fn test_cuda_pool() { @@ -502,7 +502,7 @@ mod tests { assert!(obj5.is_none()); } - #[cfg(all(feature = "cuda", target_os = "linux"))] + #[cfg(all(feature = "cuda", not(target_os = "macos")))] #[test] #[ignore] // Can only be executed if a real CUDA device is present fn test_copy_roundtrip() {