Debian Codegraph @

openmp/device/src/Configuration.cpp

raw
1 //===- Configuration.cpp - OpenMP device configuration interface -- 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 // This file contains the data object of the constant device environment and the
10 // query API.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "Configuration.h"
15 #include "DeviceTypes.h"
16 #include "State.h"
17
18 using namespace ompx;
19
20 // Weak definitions will be overridden by CGOpenmpRuntimeGPU if enabled.
21 [[gnu::weak]] extern const uint32_t __omp_rtl_debug_kind = 0;
22 [[gnu::weak]] extern const uint32_t __omp_rtl_assume_no_thread_state = 0;
23 [[gnu::weak]] extern const uint32_t __omp_rtl_assume_no_nested_parallelism = 0;
24 [[gnu::weak]] extern const uint32_t __omp_rtl_assume_threads_oversubscription =
25 0;
26 [[gnu::weak]] extern const uint32_t __omp_rtl_assume_teams_oversubscription = 0;
27
28 // This variable should be visible to the plugin so we override the default
29 // hidden visibility.
30 [[gnu::used, gnu::retain, gnu::weak,
31 gnu::visibility(
32 "protected")]] Constant<DeviceEnvironmentTy> __omp_rtl_device_environment;
33
34 uint32_t config::getAssumeTeamsOversubscription() {
35 return __omp_rtl_assume_teams_oversubscription;
36 }
37
38 uint32_t config::getAssumeThreadsOversubscription() {
39 return __omp_rtl_assume_threads_oversubscription;
40 }
41
42 uint32_t config::getDebugKind() {
43 return __omp_rtl_debug_kind & __omp_rtl_device_environment.DeviceDebugKind;
44 }
45
46 uint32_t config::getNumDevices() {
47 return __omp_rtl_device_environment.NumDevices;
48 }
49
50 uint32_t config::getDeviceNum() {
51 return __omp_rtl_device_environment.DeviceNum;
52 }
53
54 uint64_t config::getDynamicMemorySize() {
55 return __omp_rtl_device_environment.DynamicMemSize;
56 }
57
58 uint64_t config::getClockFrequency() {
59 return __omp_rtl_device_environment.ClockFrequency;
60 }
61
62 void *config::getIndirectCallTablePtr() {
63 return reinterpret_cast<void *>(
64 __omp_rtl_device_environment.IndirectCallTable);
65 }
66
67 uint64_t config::getHardwareParallelism() {
68 return __omp_rtl_device_environment.HardwareParallelism;
69 }
70
71 uint64_t config::getIndirectCallTableSize() {
72 return __omp_rtl_device_environment.IndirectCallTableSize;
73 }
74
75 bool config::isDebugMode(DeviceDebugKind Kind) {
76 return config::getDebugKind() & uint32_t(Kind);
77 }
78
79 bool config::mayUseThreadStates() { return !__omp_rtl_assume_no_thread_state; }
80
81 bool config::mayUseNestedParallelism() {
82 if (__omp_rtl_assume_no_nested_parallelism)
83 return false;
84 return state::getKernelEnvironment().Configuration.MayUseNestedParallelism;
85 }