Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -529,6 +529,8 @@ HelpText<"CUDA installation path">; def fopenmp_cuda_gpu_arch_EQ : Joined<["--"], "fopenmp-cuda-gpu-arch=">, Flags<[DriverOption]>, HelpText<"Pass a single CUDA GPU architecture (default sm_20) to be used by OpenMP device offloading.">; +def fopenmp_ptx_EQ : Joined<["--"], "fopenmp-ptx=">, Flags<[DriverOption]>, + HelpText<"Pass a PTX version +ptxXX, default +ptx42 (for PTX version 4.2) used by OpenMP device offloading.">; def ptxas_path_EQ : Joined<["--"], "ptxas-path=">, Group, HelpText<"Path to ptxas (used for compiling CUDA code)">; def fcuda_flush_denormals_to_zero : Flag<["-"], "fcuda-flush-denormals-to-zero">, Index: lib/Driver/ToolChains/Cuda.cpp =================================================================== --- lib/Driver/ToolChains/Cuda.cpp +++ lib/Driver/ToolChains/Cuda.cpp @@ -492,8 +492,18 @@ // than LLVM defaults to. Use PTX4.2 which is the PTX version that // came with CUDA-7.0. CC1Args.push_back("-target-feature"); + + StringRef PtxVersion = DriverArgs.getLastArgValue( + options::OPT_fopenmp_ptx_EQ); + CC1Args.push_back("+ptx42"); + if (DeviceOffloadingKind == Action::OFK_OpenMP && + !PtxVersion.empty()) { + // Use PTX version passed to the driver. + CC1Args.back() = PtxVersion.data(); + } + if (DeviceOffloadingKind == Action::OFK_OpenMP) { SmallVector LibraryPaths; if (char *Env = ::getenv("LIBRARY_PATH")) { Index: test/Driver/openmp-offload.c =================================================================== --- test/Driver/openmp-offload.c +++ test/Driver/openmp-offload.c @@ -634,6 +634,16 @@ /// ########################################################################### +/// Check PTXAS is passed the compute capability passed to the driver. +// RUN: %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda --fopenmp-ptx=+ptx52 -save-temps -no-canonical-prefixes %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHK-PTXAS-VERSION %s + +// CHK-PTXAS-VERSION: clang{{.*}}.bc" {{.*}}"-target-feature" "+ptx52" +// CHK-PTXAS-VERSION-NEXT: clang{{.*}}.bc" {{.*}}"-target-feature" "+ptx52" +// CHK-PTXAS-VERSION-NEXT: clang{{.*}}.bc" {{.*}}"-target-feature" "+ptx52" + +/// ########################################################################### + /// Check -fopenmp-is-device is also passed when generating the *.i and *.s intermediate files. // RUN: %clang -### -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu -save-temps -no-canonical-prefixes %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHK-FOPENMP-IS-DEVICE %s