From 2cb279218db1e4b8064c45db6530666d9207a8f8 Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Thu, 4 Aug 2022 20:46:12 +0200 Subject: [PATCH 1/3] Allow to use clang++ with CUDA compiler. CUDA compiler supports clang++, but it wasn't possible to use it with cc-rs, because --target option was passed to nvcc instead of clang. --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 486d67e0b..e0e4a73f2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1690,7 +1690,7 @@ impl Build { cmd.args.push("--target=aarch64-unknown-windows-gnu".into()) } } else { - cmd.args.push(format!("--target={}", target).into()); + cmd.push_cc_arg(format!("--target={}", target).into()); } } } From fabd0616aa9794d7e48966f88d9c9e34908b732d Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Thu, 4 Aug 2022 20:51:31 +0200 Subject: [PATCH 2/3] Refine CUDA support. Instead of counting all source files we count only .cu files, ones with device code that actually require the special treatment. --- src/lib.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e0e4a73f2..55ee8bc29 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1367,7 +1367,7 @@ impl Build { if !msvc || !is_asm || !is_arm { cmd.arg("-c"); } - if self.cuda && self.files.len() > 1 { + if self.cuda && self.cuda_file_count() > 1 { cmd.arg("--device-c"); } if is_asm { @@ -2035,7 +2035,7 @@ impl Build { self.assemble_progressive(dst, chunk)?; } - if self.cuda { + if self.cuda && self.cuda_file_count() > 0 { // Link the device-side code and add it to the target library, // so that non-CUDA linker can link the final binary. @@ -3010,6 +3010,13 @@ impl Build { cache.insert(sdk.into(), ret.clone()); Ok(ret) } + + fn cuda_file_count(&self) -> usize { + self.files + .iter() + .filter(|file| file.extension() == Some(OsStr::new("cu"))) + .count() + } } impl Default for Build { From f3232663d411d07c781d3ed2a16be8671b25e4e1 Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Wed, 23 Nov 2022 21:58:04 +0100 Subject: [PATCH 3/3] Update CUDA toolchain. --- .github/workflows/main.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ebd63c210..94638d9e9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -96,16 +96,14 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@master - - name: Install cuda-minimal-build-11-6 + - name: Install cuda-minimal-build-11-8 shell: bash run: | # https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=deb_network - wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin - sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600 - sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub - sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /" + wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb + sudo dpkg -i cuda-keyring_1.0-1_all.deb sudo apt-get update - sudo apt-get -y install cuda-minimal-build-11-6 + sudo apt-get -y install cuda-minimal-build-11-8 - name: Test 'cudart' feature shell: bash run: env PATH=/usr/local/cuda/bin:$PATH cargo test --manifest-path cc-test/Cargo.toml --features test_cuda