Warning: This file is not a C or C++ file. It does not have highlighting.

1//===-- OffloadPolicy.h - Configuration of offload behavior -----*- 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// Configuration for offload behavior, e.g., if offload is disabled, can be
10// disabled, is mandatory, etc.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef OMPTARGET_OFFLOAD_POLICY_H
15#define OMPTARGET_OFFLOAD_POLICY_H
16
17#include "PluginManager.h"
18
19enum kmp_target_offload_kind_t {
20 tgt_disabled = 0,
21 tgt_default = 1,
22 tgt_mandatory = 2
23};
24
25extern "C" int __kmpc_get_target_offload(void) __attribute__((weak));
26
27class OffloadPolicy {
28
29 OffloadPolicy(PluginManager &PM) {
30 // TODO: Check for OpenMP.
31 switch ((kmp_target_offload_kind_t)__kmpc_get_target_offload()) {
32 case tgt_disabled:
33 Kind = DISABLED;
34 return;
35 case tgt_mandatory:
36 Kind = MANDATORY;
37 return;
38 default:
39 if (PM.getNumDevices()) {
40 DP("Default TARGET OFFLOAD policy is now mandatory "
41 "(devices were found)\n");
42 Kind = MANDATORY;
43 } else {
44 DP("Default TARGET OFFLOAD policy is now disabled "
45 "(no devices were found)\n");
46 Kind = DISABLED;
47 }
48 return;
49 }
50 }
51
52public:
53 static bool isOffloadDisabled() {
54 return static_cast<kmp_target_offload_kind_t>(
55 __kmpc_get_target_offload()) == tgt_disabled;
56 }
57
58 static const OffloadPolicy &get(PluginManager &PM) {
59 static OffloadPolicy OP(PM);
60 return OP;
61 }
62
63 enum OffloadPolicyKind { DISABLED, MANDATORY };
64
65 OffloadPolicyKind Kind = MANDATORY;
66};
67
68#endif // OMPTARGET_OFFLOAD_POLICY_H
69

Warning: This file is not a C or C++ file. It does not have highlighting.

source code of offload/include/OffloadPolicy.h