[clang] 002a63f - [OpenMP] Add `__CUDA_ARCH__` definition when offloading with OpenMP
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Fri May 13 11:39:19 PDT 2022
Author: Joseph Huber
Date: 2022-05-13T14:38:35-04:00
New Revision: 002a63f937d91c0aad192f2d4997317fb277b32a
URL: https://github.com/llvm/llvm-project/commit/002a63f937d91c0aad192f2d4997317fb277b32a
DIFF: https://github.com/llvm/llvm-project/commit/002a63f937d91c0aad192f2d4997317fb277b32a.diff
LOG: [OpenMP] Add `__CUDA_ARCH__` definition when offloading with OpenMP
Currently we define the `__CUDA_ARCH__` macro only in CUDA mode. This
patch allows us to use this macro in OpenMP-offloading mode when
targeting NVPTX.
Reviewed By: tra, tianshilei1992
Differential Revision: https://reviews.llvm.org/D125256
Added:
Modified:
clang/lib/Basic/Targets/NVPTX.cpp
clang/test/OpenMP/driver-openmp-target.c
Removed:
################################################################################
diff --git a/clang/lib/Basic/Targets/NVPTX.cpp b/clang/lib/Basic/Targets/NVPTX.cpp
index ffd69983a0be..9dd60adb00fb 100644
--- a/clang/lib/Basic/Targets/NVPTX.cpp
+++ b/clang/lib/Basic/Targets/NVPTX.cpp
@@ -179,7 +179,7 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const {
Builder.defineMacro("__PTX__");
Builder.defineMacro("__NVPTX__");
- if (Opts.CUDAIsDevice) {
+ if (Opts.CUDAIsDevice || Opts.OpenMPIsDevice) {
// Set __CUDA_ARCH__ for the GPU specified.
std::string CUDAArchCode = [this] {
switch (GPU) {
diff --git a/clang/test/OpenMP/driver-openmp-target.c b/clang/test/OpenMP/driver-openmp-target.c
index ae8430a953e7..8809b54df23b 100644
--- a/clang/test/OpenMP/driver-openmp-target.c
+++ b/clang/test/OpenMP/driver-openmp-target.c
@@ -1,4 +1,8 @@
// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
// REQUIRES: clang-target-64-bits
+
// RUN: %clang %s -c -E -dM -fopenmp=libomp -fopenmp-version=45 -fopenmp-targets=x86_64-unknown-unknown -o - | FileCheck --check-prefix=CHECK-45-VERSION %s
// CHECK-45-VERSION: #define _OPENMP 201511
+// RUN: %clang %s -c -E -dM -fopenmp=libomp -nogpulib --offload-arch=sm_70 --offload-device-only -o - | FileCheck --check-prefix=CHECK-CUDA-ARCH %s
+// CHECK-CUDA-ARCH: #define __CUDA_ARCH__ 700
More information about the cfe-commits
mailing list