From 693358d78721f4fa516cc703bffa4ae35080dca8 Mon Sep 17 00:00:00 2001 From: Shilei Tian Date: Sun, 22 Jan 2023 19:10:46 -0500 Subject: [PATCH] [OpenMP][DeviceRTL][NFC] Use `OMPTgtExecModeFlags` from `llvm/include/llvm/Frontend/OpenMP/OMPDeviceConstants.h` This patch makes preparation for a series that will enable per-kernel information used in both host and device runtime. Some variables/enums, such as `OMPTgtExecModeFlags`, have to be shared by both of them. A new header `OMPDeviceConstants.h` is added, containing code that will be shared by them. We will introduce more variables soon. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D142320 --- llvm/include/llvm/Frontend/OpenMP/OMPConstants.h | 10 ++----- .../llvm/Frontend/OpenMP/OMPDeviceConstants.h | 31 ++++++++++++++++++++++ openmp/libomptarget/DeviceRTL/include/Types.h | 5 ---- openmp/libomptarget/DeviceRTL/src/Kernel.cpp | 8 ++++-- 4 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 llvm/include/llvm/Frontend/OpenMP/OMPDeviceConstants.h diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPConstants.h b/llvm/include/llvm/Frontend/OpenMP/OMPConstants.h index 94dadbe..afdbc4d 100644 --- a/llvm/include/llvm/Frontend/OpenMP/OMPConstants.h +++ b/llvm/include/llvm/Frontend/OpenMP/OMPConstants.h @@ -185,14 +185,6 @@ enum class OMPScheduleType { LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ ModifierMask) }; -enum OMPTgtExecModeFlags : int8_t { - OMP_TGT_EXEC_MODE_GENERIC = 1 << 0, - OMP_TGT_EXEC_MODE_SPMD = 1 << 1, - OMP_TGT_EXEC_MODE_GENERIC_SPMD = - OMP_TGT_EXEC_MODE_GENERIC | OMP_TGT_EXEC_MODE_SPMD, - LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ OMP_TGT_EXEC_MODE_GENERIC_SPMD) -}; - /// Values for bit flags used to specify the mapping type for /// offloading. enum class OpenMPOffloadMappingFlags : uint64_t { @@ -280,4 +272,6 @@ enum class RTLDependenceKindTy { } // end namespace llvm +#include "OMPDeviceConstants.h" + #endif // LLVM_FRONTEND_OPENMP_OMPCONSTANTS_H diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPDeviceConstants.h b/llvm/include/llvm/Frontend/OpenMP/OMPDeviceConstants.h new file mode 100644 index 0000000..0a223b0 --- /dev/null +++ b/llvm/include/llvm/Frontend/OpenMP/OMPDeviceConstants.h @@ -0,0 +1,31 @@ +//===- OMPDeviceConstants.h - OpenMP device related constants ----- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// \file +/// +/// This file defines constans that will be used by both host and device +/// compilation. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_FRONTEND_OPENMP_OMPDEVICECONSTANTS_H +#define LLVM_FRONTEND_OPENMP_OMPDEVICECONSTANTS_H + +namespace llvm { +namespace omp { +enum OMPTgtExecModeFlags { + OMP_TGT_EXEC_MODE_GENERIC = 1 << 0, + OMP_TGT_EXEC_MODE_SPMD = 1 << 1, + OMP_TGT_EXEC_MODE_GENERIC_SPMD = + OMP_TGT_EXEC_MODE_GENERIC | OMP_TGT_EXEC_MODE_SPMD +}; + +} // end namespace omp + +} // end namespace llvm + +#endif // LLVM_FRONTEND_OPENMP_OMPDEVICECONSTANTS_H diff --git a/openmp/libomptarget/DeviceRTL/include/Types.h b/openmp/libomptarget/DeviceRTL/include/Types.h index 700ebbd..628755b 100644 --- a/openmp/libomptarget/DeviceRTL/include/Types.h +++ b/openmp/libomptarget/DeviceRTL/include/Types.h @@ -191,11 +191,6 @@ typedef enum omp_allocator_handle_t { KMP_ALLOCATOR_MAX_HANDLE = ~(0U) } omp_allocator_handle_t; -enum OMPTgtExecModeFlags : int8_t { - OMP_TGT_EXEC_MODE_GENERIC = 1 << 0, - OMP_TGT_EXEC_MODE_SPMD = 1 << 1, -}; - #define __PRAGMA(STR) _Pragma(#STR) #define OMP_PRAGMA(STR) __PRAGMA(omp STR) diff --git a/openmp/libomptarget/DeviceRTL/src/Kernel.cpp b/openmp/libomptarget/DeviceRTL/src/Kernel.cpp index 03c6aa4..c88aacb 100644 --- a/openmp/libomptarget/DeviceRTL/src/Kernel.cpp +++ b/openmp/libomptarget/DeviceRTL/src/Kernel.cpp @@ -17,6 +17,8 @@ #include "Synchronization.h" #include "Types.h" +#include "llvm/Frontend/OpenMP/OMPDeviceConstants.h" + using namespace ompx; #pragma omp begin declare target device_type(nohost) @@ -68,7 +70,8 @@ extern "C" { int32_t __kmpc_target_init(IdentTy *Ident, int8_t Mode, bool UseGenericStateMachine) { FunctionTracingRAII(); - const bool IsSPMD = Mode & OMP_TGT_EXEC_MODE_SPMD; + const bool IsSPMD = + Mode & llvm::omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_SPMD; if (IsSPMD) { inititializeRuntime(/* IsSPMD */ true); synchronize::threadsAligned(); @@ -127,7 +130,8 @@ int32_t __kmpc_target_init(IdentTy *Ident, int8_t Mode, /// void __kmpc_target_deinit(IdentTy *Ident, int8_t Mode) { FunctionTracingRAII(); - const bool IsSPMD = Mode & OMP_TGT_EXEC_MODE_SPMD; + const bool IsSPMD = + Mode & llvm::omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_SPMD; state::assumeInitialState(IsSPMD); if (IsSPMD) return; -- 2.7.4