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
18using 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
36uint32_t config::getAssumeTeamsOversubscription() {
37 return __omp_rtl_assume_teams_oversubscription;
38}
39
40uint32_t config::getAssumeThreadsOversubscription() {
41 return __omp_rtl_assume_threads_oversubscription;
42}
43
44uint32_t config::getDebugKind() {
45 return __omp_rtl_debug_kind & __omp_rtl_device_environment.DeviceDebugKind;
46}
47
48uint32_t config::getNumDevices() {
49 return __omp_rtl_device_environment.NumDevices;
50}
51
52uint32_t config::getDeviceNum() {
53 return __omp_rtl_device_environment.DeviceNum;
54}
55
56uint64_t config::getDynamicMemorySize() {
57 return __omp_rtl_device_environment.DynamicMemSize;
58}
59
60uint64_t config::getClockFrequency() {
61 return __omp_rtl_device_environment.ClockFrequency;
62}
63
64void *config::getIndirectCallTablePtr() {
65 return reinterpret_cast<void *>(
66 __omp_rtl_device_environment.IndirectCallTable);
67}
68
69uint64_t config::getHardwareParallelism() {
70 return __omp_rtl_device_environment.HardwareParallelism;
71}
72
73uint64_t config::getIndirectCallTableSize() {
74 return __omp_rtl_device_environment.IndirectCallTableSize;
75}
76
77bool config::isDebugMode(DeviceDebugKind Kind) {
78 return config::getDebugKind() & uint32_t(Kind);
79}
80
81bool config::mayUseThreadStates() { return !__omp_rtl_assume_no_thread_state; }
82
83bool 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

source code of offload/DeviceRTL/src/Configuration.cpp