Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions offload/include/OffloadPolicy.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern "C" int __kmpc_get_target_offload(void) __attribute__((weak));

class OffloadPolicy {

OffloadPolicy(PluginManager &PM) {
OffloadPolicy() {
// TODO: Check for OpenMP.
switch ((kmp_target_offload_kind_t)__kmpc_get_target_offload()) {
case tgt_disabled:
Expand All @@ -36,6 +36,17 @@ class OffloadPolicy {
Kind = MANDATORY;
return;
default:
// delay DEFAULT policy until PluginManager is ready
UserValue = false;
return;
};
}

OffloadPolicy(PluginManager &PM) {
const OffloadPolicy &OP = get();
if (!OP.UserValue) {
// User didn't specify a policy, decide
// based on number of devices discovered
if (PM.getNumDevices()) {
DP("Default TARGET OFFLOAD policy is now mandatory "
"(devices were found)\n");
Expand All @@ -46,10 +57,16 @@ class OffloadPolicy {
Kind = DISABLED;
}
return;
};
}
Kind = OP.Kind;
}

public:
static const OffloadPolicy &get() {
static OffloadPolicy OP;
return OP;
}

static const OffloadPolicy &get(PluginManager &PM) {
static OffloadPolicy OP(PM);
return OP;
Expand All @@ -58,6 +75,7 @@ class OffloadPolicy {
enum OffloadPolicyKind { DISABLED, MANDATORY };

OffloadPolicyKind Kind = MANDATORY;
bool UserValue = true;
};

#endif // OMPTARGET_OFFLOAD_POLICY_H
7 changes: 7 additions & 0 deletions offload/libomptarget/OffloadRTL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//
//===----------------------------------------------------------------------===//

#include "OffloadPolicy.h"
#include "OpenMP/OMPT/Callback.h"
#include "PluginManager.h"

Expand All @@ -31,6 +32,12 @@ void initRuntime() {
if (PM == nullptr)
PM = new PluginManager();

if (OffloadPolicy::get().Kind == OffloadPolicy::DISABLED) {
DP("Offload is disabled. Skipping library initialization\n");
// Do only absolutely needed initialization
return;
}

RefCount++;
if (RefCount == 1) {
DP("Init offload library!\n");
Expand Down