AlexVlx created this revision. AlexVlx added reviewers: yaxunl, arsenm. AlexVlx added a project: clang. Herald added a project: All. AlexVlx requested review of this revision. Herald added subscribers: cfe-commits, wdng.
This patch adds the Driver changes needed by the standard algorithm offload feature being proposed here: https://discourse.llvm.org/t/rfc-adding-c-parallel-algorithm-offload-support-to-clang-llvm/72159/1. The verbose documentation is included in the head of the patch series. This change merely adds two macros to inform user space if we are compiling in `stdpar` mode and, respectively, if the optional allocation interposition mode has been requested, as well as associated minimal tests. The macros can be used by the runtime implementation of offload to drive conditional compilation, and are only defined if the HIP language has been enabled. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D155826 Files: clang/lib/Frontend/InitPreprocessor.cpp clang/test/Preprocessor/predefined-macros.c Index: clang/test/Preprocessor/predefined-macros.c =================================================================== --- clang/test/Preprocessor/predefined-macros.c +++ clang/test/Preprocessor/predefined-macros.c @@ -290,3 +290,19 @@ // RUN: -fcuda-is-device -fgpu-default-stream=per-thread \ // RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-PTH // CHECK-PTH: #define HIP_API_PER_THREAD_DEFAULT_STREAM 1 + +// RUN: %clang_cc1 %s -E -dM -o - -x hip -stdpar -triple x86_64-unknown-linux-gnu \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-STDPAR +// CHECK-STDPAR: #define __STDPAR__ 1 + +// RUN: %clang_cc1 %s -E -dM -o - -x hip -stdpar -stdpar-interpose-alloc \ +// RUN: -triple x86_64-unknown-linux-gnu | FileCheck -match-full-lines %s \ +// RUN: --check-prefix=CHECK-STDPAR-INTERPOSE +// CHECK-STDPAR-INTERPOSE: #define __STDPAR_INTERPOSE_ALLOC__ 1 +// CHECK-STDPAR-INTERPOSE: #define __STDPAR__ 1 + +// RUN: %clang_cc1 %s -E -dM -o - -x hip -stdpar -stdpar-interpose-alloc \ +// RUN: -triple amdgcn-amd-amdhsa -fcuda-is-device | FileCheck -match-full-lines \ +// RUN: %s --check-prefix=CHECK-STDPAR-INTERPOSE-DEV-NEG +// CHECK-STDPAR-INTERPOSE-DEV-NEG: #define __STDPAR__ 1 +// CHECK-STDPAR-INTERPOSE-DEV-NEG-NOT: #define __STDPAR_INTERPOSE_ALLOC__ 1 \ No newline at end of file Index: clang/lib/Frontend/InitPreprocessor.cpp =================================================================== --- clang/lib/Frontend/InitPreprocessor.cpp +++ clang/lib/Frontend/InitPreprocessor.cpp @@ -586,6 +586,11 @@ Builder.defineMacro("__HIP_MEMORY_SCOPE_WORKGROUP", "3"); Builder.defineMacro("__HIP_MEMORY_SCOPE_AGENT", "4"); Builder.defineMacro("__HIP_MEMORY_SCOPE_SYSTEM", "5"); + if (LangOpts.HIPStdPar) { + Builder.defineMacro("__STDPAR__"); + if (!LangOpts.CUDAIsDevice) + Builder.defineMacro("__STDPAR_INTERPOSE_ALLOC__"); + } if (LangOpts.CUDAIsDevice) { Builder.defineMacro("__HIP_DEVICE_COMPILE__"); if (!TI.hasHIPImageSupport()) {
Index: clang/test/Preprocessor/predefined-macros.c =================================================================== --- clang/test/Preprocessor/predefined-macros.c +++ clang/test/Preprocessor/predefined-macros.c @@ -290,3 +290,19 @@ // RUN: -fcuda-is-device -fgpu-default-stream=per-thread \ // RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-PTH // CHECK-PTH: #define HIP_API_PER_THREAD_DEFAULT_STREAM 1 + +// RUN: %clang_cc1 %s -E -dM -o - -x hip -stdpar -triple x86_64-unknown-linux-gnu \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-STDPAR +// CHECK-STDPAR: #define __STDPAR__ 1 + +// RUN: %clang_cc1 %s -E -dM -o - -x hip -stdpar -stdpar-interpose-alloc \ +// RUN: -triple x86_64-unknown-linux-gnu | FileCheck -match-full-lines %s \ +// RUN: --check-prefix=CHECK-STDPAR-INTERPOSE +// CHECK-STDPAR-INTERPOSE: #define __STDPAR_INTERPOSE_ALLOC__ 1 +// CHECK-STDPAR-INTERPOSE: #define __STDPAR__ 1 + +// RUN: %clang_cc1 %s -E -dM -o - -x hip -stdpar -stdpar-interpose-alloc \ +// RUN: -triple amdgcn-amd-amdhsa -fcuda-is-device | FileCheck -match-full-lines \ +// RUN: %s --check-prefix=CHECK-STDPAR-INTERPOSE-DEV-NEG +// CHECK-STDPAR-INTERPOSE-DEV-NEG: #define __STDPAR__ 1 +// CHECK-STDPAR-INTERPOSE-DEV-NEG-NOT: #define __STDPAR_INTERPOSE_ALLOC__ 1 \ No newline at end of file Index: clang/lib/Frontend/InitPreprocessor.cpp =================================================================== --- clang/lib/Frontend/InitPreprocessor.cpp +++ clang/lib/Frontend/InitPreprocessor.cpp @@ -586,6 +586,11 @@ Builder.defineMacro("__HIP_MEMORY_SCOPE_WORKGROUP", "3"); Builder.defineMacro("__HIP_MEMORY_SCOPE_AGENT", "4"); Builder.defineMacro("__HIP_MEMORY_SCOPE_SYSTEM", "5"); + if (LangOpts.HIPStdPar) { + Builder.defineMacro("__STDPAR__"); + if (!LangOpts.CUDAIsDevice) + Builder.defineMacro("__STDPAR_INTERPOSE_ALLOC__"); + } if (LangOpts.CUDAIsDevice) { Builder.defineMacro("__HIP_DEVICE_COMPILE__"); if (!TI.hasHIPImageSupport()) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits