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 "DeviceEnvironment.h"
16 #include "State.h"
17 #include "Types.h"
18 
19 using namespace _OMP;
20 
21 #pragma omp begin declare target device_type(nohost)
22 
23 // defined by CGOpenMPRuntimeGPU
24 extern uint32_t __omp_rtl_debug_kind;
25 extern uint32_t __omp_rtl_assume_no_thread_state;
26 
27 // TODO: We want to change the name as soon as the old runtime is gone.
28 // This variable should be visibile to the plugin so we override the default
29 // hidden visibility.
30 DeviceEnvironmentTy CONSTANT(omptarget_device_environment)
31     __attribute__((used, retain, weak, visibility("protected")));
32 
getDebugKind()33 uint32_t config::getDebugKind() {
34   return __omp_rtl_debug_kind & omptarget_device_environment.DebugKind;
35 }
36 
getNumDevices()37 uint32_t config::getNumDevices() {
38   return omptarget_device_environment.NumDevices;
39 }
40 
getDeviceNum()41 uint32_t config::getDeviceNum() {
42   return omptarget_device_environment.DeviceNum;
43 }
44 
getDynamicMemorySize()45 uint64_t config::getDynamicMemorySize() {
46   return omptarget_device_environment.DynamicMemSize;
47 }
48 
isDebugMode(config::DebugKind Kind)49 bool config::isDebugMode(config::DebugKind Kind) {
50   return config::getDebugKind() & Kind;
51 }
52 
mayUseThreadStates()53 bool config::mayUseThreadStates() { return !__omp_rtl_assume_no_thread_state; }
54 
55 #pragma omp end declare target
56