brintos

brintos / llvm-project-archived public Read only

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