1 //===-- Shared/Environment.h - OpenMP GPU environments ------------ C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // Environments shared between host and device. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef OMPTARGET_SHARED_ENVIRONMENT_H 14 #define OMPTARGET_SHARED_ENVIRONMENT_H 15 16 #include <stdint.h> 17 18 #ifdef OMPTARGET_DEVICE_RUNTIME 19 #include "DeviceTypes.h" 20 #else 21 #include "SourceInfo.h" 22 23 using IdentTy = ident_t; 24 #endif 25 26 #include "llvm/Frontend/OpenMP/OMPDeviceConstants.h" 27 28 enum class DeviceDebugKind : uint32_t { 29 Assertion = 1U << 0, 30 FunctionTracing = 1U << 1, 31 CommonIssues = 1U << 2, 32 AllocationTracker = 1U << 3, 33 }; 34 35 struct DeviceEnvironmentTy { 36 uint32_t DeviceDebugKind; 37 uint32_t NumDevices; 38 uint32_t DeviceNum; 39 uint32_t DynamicMemSize; 40 uint64_t ClockFrequency; 41 uintptr_t IndirectCallTable; 42 uint64_t IndirectCallTableSize; 43 uint64_t HardwareParallelism; 44 }; 45 46 struct DeviceMemoryPoolTy { 47 void *Ptr; 48 uint64_t Size; 49 }; 50 51 struct DeviceMemoryPoolTrackingTy { 52 uint64_t NumAllocations; 53 uint64_t AllocationTotal; 54 uint64_t AllocationMin; 55 uint64_t AllocationMax; 56 57 void combine(DeviceMemoryPoolTrackingTy &Other) { 58 NumAllocations += Other.NumAllocations; 59 AllocationTotal += Other.AllocationTotal; 60 AllocationMin = AllocationMin > Other.AllocationMin ? Other.AllocationMin 61 : AllocationMin; 62 AllocationMax = AllocationMax < Other.AllocationMax ? Other.AllocationMax 63 : AllocationMax; 64 } 65 }; 66 67 // NOTE: Please don't change the order of those members as their indices are 68 // used in the middle end. Always add the new data member at the end. 69 // Different from KernelEnvironmentTy below, this structure contains members 70 // that might be modified at runtime. 71 struct DynamicEnvironmentTy { 72 /// Current indentation level for the function trace. Only accessed by thread 73 /// 0. 74 uint16_t DebugIndentionLevel; 75 }; 76 77 // NOTE: Please don't change the order of those members as their indices are 78 // used in the middle end. Always add the new data member at the end. 79 struct ConfigurationEnvironmentTy { 80 uint8_t UseGenericStateMachine = 2; 81 uint8_t MayUseNestedParallelism = 2; 82 llvm::omp::OMPTgtExecModeFlags ExecMode = llvm::omp::OMP_TGT_EXEC_MODE_SPMD; 83 // Information about (legal) launch configurations. 84 //{ 85 int32_t MinThreads = -1; 86 int32_t MaxThreads = -1; 87 int32_t MinTeams = -1; 88 int32_t MaxTeams = -1; 89 int32_t ReductionDataSize = 0; 90 int32_t ReductionBufferLength = 0; 91 //} 92 }; 93 94 // NOTE: Please don't change the order of those members as their indices are 95 // used in the middle end. Always add the new data member at the end. 96 struct KernelEnvironmentTy { 97 ConfigurationEnvironmentTy Configuration; 98 IdentTy *Ident = nullptr; 99 DynamicEnvironmentTy *DynamicEnv = nullptr; 100 }; 101 102 struct KernelLaunchEnvironmentTy { 103 uint32_t ReductionCnt = 0; 104 uint32_t ReductionIterCnt = 0; 105 void *ReductionBuffer = nullptr; 106 }; 107 108 #endif // OMPTARGET_SHARED_ENVIRONMENT_H 109