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