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 _OMP;
19 
20 struct DeviceEnvironmentTy {
21   uint32_t DebugKind;
22   uint32_t NumDevices;
23   uint32_t DeviceNum;
24   uint64_t DynamicMemSize;
25 };
26 
27 #pragma omp declare target
28 
29 extern uint32_t __omp_rtl_debug_kind;
30 
31 // TOOD: We want to change the name as soon as the old runtime is gone.
32 DeviceEnvironmentTy CONSTANT(omptarget_device_environment)
33     __attribute__((used));
34 
35 uint32_t config::getDebugKind() {
36   return __omp_rtl_debug_kind & omptarget_device_environment.DebugKind;
37 }
38 
39 uint32_t config::getNumDevices() {
40   return omptarget_device_environment.NumDevices;
41 }
42 
43 uint32_t config::getDeviceNum() {
44   return omptarget_device_environment.DeviceNum;
45 }
46 
47 uint64_t config::getDynamicMemorySize() {
48   return omptarget_device_environment.DynamicMemSize;
49 }
50 
51 bool config::isDebugMode(config::DebugKind Kind) {
52   return config::getDebugKind() & Kind;
53 }
54 
55 #pragma omp end declare target
56