diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp index 0058def1aacfa..27853bd64b4fe 100644 --- a/clang/lib/Driver/ToolChains/Cuda.cpp +++ b/clang/lib/Driver/ToolChains/Cuda.cpp @@ -136,6 +136,11 @@ CudaInstallationDetector::CudaInstallationDetector( Candidates.emplace_back( Args.getLastArgValue(clang::driver::options::OPT_cuda_path_EQ).str()); } else if (HostTriple.isOSWindows()) { + // CUDA_PATH is set by the installer, prefer it over other versions that + // might be present on the system. + if (const char *CudaPathEnvVar = ::getenv("CUDA_PATH")) + Candidates.emplace_back(CudaPathEnvVar); + for (const char *Ver : Versions) Candidates.emplace_back( D.SysRoot + "/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v" + diff --git a/clang/test/Driver/cuda-windows-cuda-path.cpp b/clang/test/Driver/cuda-windows-cuda-path.cpp new file mode 100644 index 0000000000000..ddbf6b1e140da --- /dev/null +++ b/clang/test/Driver/cuda-windows-cuda-path.cpp @@ -0,0 +1,11 @@ +/// +/// Make sure that CUDA_PATH is picked up correctly when looking for CUDA +/// installation. +/// + +// REQUIRES: system-windows +// RUN: env CUDA_PATH=%S\Inputs\CUDA_111\usr\local\cuda %clang -fsycl \ +// RUN: -fsycl-targets=nvptx64-nvidia-cuda -### -v %s 2>&1 | \ +// RUN: FileCheck %s + +// CHECK: Found CUDA installation: {{.*}}Inputs\CUDA_111\usr\local\cuda, version 11.1