[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 <huberjn@outlook.com>
This commit is contained in:
Alex 2025-03-28 23:28:14 +01:00 committed by GitHub
parent 5a073f1f3a
commit 021a1f6974
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -46,10 +46,15 @@ class OffloadPolicy {
Kind = DISABLED;
}
return;
};
}
}
public:
static bool isOffloadDisabled() {
return static_cast<kmp_target_offload_kind_t>(
__kmpc_get_target_offload()) == tgt_disabled;
}
static const OffloadPolicy &get(PluginManager &PM) {
static OffloadPolicy OP(PM);
return OP;

View File

@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "PluginManager.h"
#include "OffloadPolicy.h"
#include "Shared/Debug.h"
#include "Shared/Profile.h"
#include "device.h"
@ -30,6 +31,11 @@ PluginManager *PM = nullptr;
void PluginManager::init() {
TIMESCOPE();
if (OffloadPolicy::isOffloadDisabled()) {
DP("Offload is disabled. Skipping plugin initialization\n");
return;
}
DP("Loading RTLs...\n");
// Attempt to create an instance of each supported plugin.