[llvm-branch-commits] [llvm] [offload][nfc] Pull OpenMP's InteropTbl out of PluginManager (PR #230483)
Ivan R. Ivanov via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Oct 9 07:52:28 PDT 2026
https://github.com/ivanradanov updated https://github.com/llvm/llvm-project/pull/230483
>From 1d38b0b531998387115379eed13873f3d95e1889 Mon Sep 17 00:00:00 2001
From: Ivan Radanov Ivanov <iivanov at nvidia.com>
Date: Fri, 9 Oct 2026 05:38:41 -0700
Subject: [PATCH 1/2] [offload][nfc] Pull OpenMP's InteropTbl out of
PluginManager
PluginManager is shared with OpenACC, so the OpenMP interop table moves
to OmpPluginManager in libomptarget. The OpenMP PM is defined there, and
interop cleanup is registered from initRuntime.
---
offload/include/OpenMP/OffloadRTL.h | 11 ++++++++++-
offload/include/PluginManager.h | 5 -----
offload/libompaccsupport/PluginManager.cpp | 7 -------
offload/libomptarget/OffloadRTL.cpp | 16 ++++++++++++----
4 files changed, 22 insertions(+), 17 deletions(-)
diff --git a/offload/include/OpenMP/OffloadRTL.h b/offload/include/OpenMP/OffloadRTL.h
index c1fcae2588d95..5781bab5fea1c 100644
--- a/offload/include/OpenMP/OffloadRTL.h
+++ b/offload/include/OpenMP/OffloadRTL.h
@@ -13,11 +13,20 @@
#ifndef OMPTARGET_OPENMP_OFFLOADRTL_H
#define OMPTARGET_OPENMP_OFFLOADRTL_H
+#include "OpenMP/InteropAPI.h"
#include "PluginManager.h"
#include <atomic>
-extern PluginManager *PM;
+namespace llvm::omp::target {
+class OmpPluginManager : public PluginManager {
+public:
+ /// Table of cached implicit interop objects
+ InteropTblTy InteropTbl;
+};
+} // namespace llvm::omp::target
+
+extern llvm::omp::target::OmpPluginManager *PM;
extern std::atomic<bool> RTLAlive; // Indicates if the RTL has been initialized
extern std::atomic<int> RTLOngoingSyncs; // Counts ongoing external syncs
diff --git a/offload/include/PluginManager.h b/offload/include/PluginManager.h
index d1e40dd0d3a5f..afd75b24651c8 100644
--- a/offload/include/PluginManager.h
+++ b/offload/include/PluginManager.h
@@ -37,8 +37,6 @@
#include <mutex>
#include <string>
-#include "OpenMP/InteropAPI.h"
-
using GenericPluginTy = llvm::omp::target::plugin::GenericPluginTy;
/// Struct for the data required to handle plugins
@@ -95,9 +93,6 @@ struct PluginManager {
HostPtrToTableMapTy HostPtrToTableMap;
std::mutex TblMapMtx; ///< For HostPtrToTableMap
- /// Table of cached implicit interop objects
- InteropTblTy InteropTbl;
-
// Work around for plugins that call dlopen on shared libraries that call
// tgt_register_lib during their initialisation. Stash the pointers in a
// vector until the plugins are all initialised and then register them.
diff --git a/offload/libompaccsupport/PluginManager.cpp b/offload/libompaccsupport/PluginManager.cpp
index 5d95d08accd37..6186ffcca6d62 100644
--- a/offload/libompaccsupport/PluginManager.cpp
+++ b/offload/libompaccsupport/PluginManager.cpp
@@ -133,13 +133,6 @@ void PluginManager::initializeAllDevices() {
[this](ol_device_handle_t Device) { initializeDevice(Device); })) {
REPORT() << "Failed to iterate devices: " << toString(std::move(Err));
}
- // After all plugins are initialized, register atExit cleanup handlers
- std::atexit([]() {
- // Interop cleanup should be done before the plugins are deinitialized as
- // the backend libraries may be already unloaded.
- if (PM)
- PM->InteropTbl.clear();
- });
}
// Returns a pointer to the binary descriptor, upgrading from a legacy format if
diff --git a/offload/libomptarget/OffloadRTL.cpp b/offload/libomptarget/OffloadRTL.cpp
index 6812d7554a82e..84806527fb8d6 100644
--- a/offload/libomptarget/OffloadRTL.cpp
+++ b/offload/libomptarget/OffloadRTL.cpp
@@ -18,6 +18,7 @@
#include "Shared/Profile.h"
using namespace llvm::omp::target::debug;
+using llvm::omp::target::OmpPluginManager;
static std::mutex &getPluginMutex() {
static std::mutex Mutex;
@@ -26,7 +27,7 @@ static std::mutex &getPluginMutex() {
static uint32_t RefCount = 0;
std::atomic<bool> RTLAlive{false};
std::atomic<int> RTLOngoingSyncs{0};
-PluginManager *PM = nullptr;
+OmpPluginManager *PM = nullptr;
/// Check deleted and deprecated features, such as environment variables.
static void checkRuntimeEnvironment() {
@@ -44,11 +45,11 @@ void initRuntime() {
checkRuntimeEnvironment();
- if (PM == nullptr)
- PM = new PluginManager();
-
RefCount++;
if (RefCount == 1) {
+ assert(PM == nullptr);
+ PM = new llvm::omp::target::OmpPluginManager();
+
ODBG(ODT_Init) << "Init offload library!";
#ifdef OMPT_SUPPORT
// Initialize OMPT first
@@ -57,6 +58,13 @@ void initRuntime() {
PM->init();
PM->registerDelayedLibraries();
+ // After all plugins are initialized, register atExit cleanup handlers
+ std::atexit([]() {
+ // Interop cleanup should be done before the plugins are deinitialized as
+ // the backend libraries may be already unloaded.
+ if (PM)
+ PM->InteropTbl.clear();
+ });
// RTL initialization is complete
RTLAlive = true;
>From 477b9adfc360c54f6023ecb2ead4f969396398dc Mon Sep 17 00:00:00 2001
From: Ivan Radanov Ivanov <iivanov at nvidia.com>
Date: Fri, 9 Oct 2026 07:43:30 -0700
Subject: [PATCH 2/2] add fullstops
---
offload/include/OpenMP/OffloadRTL.h | 2 +-
offload/libomptarget/OffloadRTL.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/offload/include/OpenMP/OffloadRTL.h b/offload/include/OpenMP/OffloadRTL.h
index 5781bab5fea1c..e71182d39614b 100644
--- a/offload/include/OpenMP/OffloadRTL.h
+++ b/offload/include/OpenMP/OffloadRTL.h
@@ -21,7 +21,7 @@
namespace llvm::omp::target {
class OmpPluginManager : public PluginManager {
public:
- /// Table of cached implicit interop objects
+ /// Table of cached implicit interop objects.
InteropTblTy InteropTbl;
};
} // namespace llvm::omp::target
diff --git a/offload/libomptarget/OffloadRTL.cpp b/offload/libomptarget/OffloadRTL.cpp
index 84806527fb8d6..76436a066805f 100644
--- a/offload/libomptarget/OffloadRTL.cpp
+++ b/offload/libomptarget/OffloadRTL.cpp
@@ -58,7 +58,7 @@ void initRuntime() {
PM->init();
PM->registerDelayedLibraries();
- // After all plugins are initialized, register atExit cleanup handlers
+ // After all plugins are initialized, register atExit cleanup handlers.
std::atexit([]() {
// Interop cleanup should be done before the plugins are deinitialized as
// the backend libraries may be already unloaded.
More information about the llvm-branch-commits
mailing list