Skip to content

Commit 021a1f6

Browse files
adurangjhuber6
andauthored
[OFFLOAD] Stricter enforcement of user offload disable (#133470)
If user specifies offload is disabled (e.g., OMP_TARGET_OFFLOAD=disable), disable library almost completely. This reduces resources spent to a minimum and ensures all APIs behave as if the only available device is the host device. Currently some of the APIs behave as if there were devices avaible for offload even when under OMP_TARGET_OFFLOAD=disable. --------- Co-authored-by: Joseph Huber <[email protected]>
1 parent 5a073f1 commit 021a1f6

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

offload/include/OffloadPolicy.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@ class OffloadPolicy {
4646
Kind = DISABLED;
4747
}
4848
return;
49-
};
49+
}
5050
}
5151

5252
public:
53+
static bool isOffloadDisabled() {
54+
return static_cast<kmp_target_offload_kind_t>(
55+
__kmpc_get_target_offload()) == tgt_disabled;
56+
}
57+
5358
static const OffloadPolicy &get(PluginManager &PM) {
5459
static OffloadPolicy OP(PM);
5560
return OP;

offload/libomptarget/PluginManager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "PluginManager.h"
14+
#include "OffloadPolicy.h"
1415
#include "Shared/Debug.h"
1516
#include "Shared/Profile.h"
1617
#include "device.h"
@@ -30,6 +31,11 @@ PluginManager *PM = nullptr;
3031

3132
void PluginManager::init() {
3233
TIMESCOPE();
34+
if (OffloadPolicy::isOffloadDisabled()) {
35+
DP("Offload is disabled. Skipping plugin initialization\n");
36+
return;
37+
}
38+
3339
DP("Loading RTLs...\n");
3440

3541
// Attempt to create an instance of each supported plugin.

0 commit comments

Comments
 (0)