[Openmp-commits] [openmp] [Libomptarget] Remove handling of old ctor / dtor entries (PR #80153)
Joseph Huber via Openmp-commits
openmp-commits at lists.llvm.org
Wed Jan 31 07:46:18 PST 2024
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/80153
Summary:
A previous patch removed creating these entries in clang in favor of the
backend emitting a callable kernel and having the runtime call that if
present. The support for the old style was kept around in LLVM 18.0 but
now that we have forked to 19.0 we should remove the support.
The effect of this would be that an application linking against a newer
libomptarget that still had the old constructors will no longer be
called. In that case, they can either recompile or use the
`libomptarget.so.18` that comes with the previous release.
>From 07e1df4b0e50a5f1a90d13af1e043254cf5444b0 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Wed, 31 Jan 2024 09:43:03 -0600
Subject: [PATCH] [Libomptarget] Remove handling of old ctor / dtor entries
Summary:
A previous patch removed creating these entries in clang in favor of the
backend emitting a callable kernel and having the runtime call that if
present. The support for the old style was kept around in LLVM 18.0 but
now that we have forked to 19.0 we should remove the support.
The effect of this would be that an application linking against a newer
libomptarget that still had the old constructors will no longer be
called. In that case, they can either recompile or use the
`libomptarget.so.18` that comes with the previous release.
---
openmp/libomptarget/include/OffloadEntry.h | 2 -
openmp/libomptarget/include/PluginManager.h | 4 --
openmp/libomptarget/include/device.h | 15 -------
openmp/libomptarget/include/omptarget.h | 4 --
openmp/libomptarget/src/PluginManager.cpp | 44 -------------------
openmp/libomptarget/src/device.cpp | 41 +----------------
openmp/libomptarget/src/omptarget.cpp | 41 +++--------------
.../test/offloading/ctor_dtor.cpp | 9 +---
8 files changed, 8 insertions(+), 152 deletions(-)
diff --git a/openmp/libomptarget/include/OffloadEntry.h b/openmp/libomptarget/include/OffloadEntry.h
index 5173841f20a44..da1de8123be97 100644
--- a/openmp/libomptarget/include/OffloadEntry.h
+++ b/openmp/libomptarget/include/OffloadEntry.h
@@ -36,8 +36,6 @@ class OffloadEntryTy {
const char *getNameAsCStr() const { return OffloadEntry.name; }
__tgt_bin_desc *getBinaryDescription() const;
- bool isCTor() const { return hasFlags(OMP_DECLARE_TARGET_CTOR); }
- bool isDTor() const { return hasFlags(OMP_DECLARE_TARGET_DTOR); }
bool isLink() const { return hasFlags(OMP_DECLARE_TARGET_LINK); }
bool hasFlags(OpenMPOffloadingDeclareTargetFlags Flags) const {
diff --git a/openmp/libomptarget/include/PluginManager.h b/openmp/libomptarget/include/PluginManager.h
index a0499c37504c0..ec5d98dc8cd30 100644
--- a/openmp/libomptarget/include/PluginManager.h
+++ b/openmp/libomptarget/include/PluginManager.h
@@ -58,10 +58,6 @@ struct PluginAdaptorTy {
/// user.
int32_t getNumberOfUserDevices() const { return NumberOfUserDevices; }
- /// Add all offload entries described by \p DI to the devices managed by this
- /// plugin.
- void addOffloadEntries(DeviceImageTy &DI);
-
/// RTL index, index is the number of devices of other RTLs that were
/// registered before, i.e. the OpenMP index of the first device to be
/// registered with this RTL.
diff --git a/openmp/libomptarget/include/device.h b/openmp/libomptarget/include/device.h
index 1dc82e36f6813..3b40de959533b 100644
--- a/openmp/libomptarget/include/device.h
+++ b/openmp/libomptarget/include/device.h
@@ -38,14 +38,6 @@ struct PluginAdaptorTy;
struct __tgt_bin_desc;
struct __tgt_target_table;
-///
-struct PendingCtorDtorListsTy {
- std::list<void *> PendingCtors;
- std::list<void *> PendingDtors;
-};
-typedef std::map<__tgt_bin_desc *, PendingCtorDtorListsTy>
- PendingCtorsDtorsPerLibrary;
-
struct DeviceTy {
int32_t DeviceID;
PluginAdaptorTy *RTL;
@@ -53,10 +45,6 @@ struct DeviceTy {
bool HasMappedGlobalData = false;
- PendingCtorsDtorsPerLibrary PendingCtorsDtors;
-
- std::mutex PendingGlobalsMtx;
-
DeviceTy(PluginAdaptorTy *RTL, int32_t DeviceID, int32_t RTLDeviceID);
// DeviceTy is not copyable
DeviceTy(const DeviceTy &D) = delete;
@@ -158,9 +146,6 @@ struct DeviceTy {
int32_t destroyEvent(void *Event);
/// }
- /// Register \p Entry as an offload entry that is avalable on this device.
- void addOffloadEntry(const OffloadEntryTy &Entry);
-
/// Print all offload entries to stderr.
void dumpOffloadEntries();
diff --git a/openmp/libomptarget/include/omptarget.h b/openmp/libomptarget/include/omptarget.h
index d5602eec0d07c..3016467b3abdf 100644
--- a/openmp/libomptarget/include/omptarget.h
+++ b/openmp/libomptarget/include/omptarget.h
@@ -91,10 +91,6 @@ enum tgt_map_type {
enum OpenMPOffloadingDeclareTargetFlags {
/// Mark the entry global as having a 'link' attribute.
OMP_DECLARE_TARGET_LINK = 0x01,
- /// Mark the entry kernel as being a global constructor.
- OMP_DECLARE_TARGET_CTOR = 0x02,
- /// Mark the entry kernel as being a global destructor.
- OMP_DECLARE_TARGET_DTOR = 0x04,
/// Mark the entry global as being an indirectly callable function.
OMP_DECLARE_TARGET_INDIRECT = 0x08
};
diff --git a/openmp/libomptarget/src/PluginManager.cpp b/openmp/libomptarget/src/PluginManager.cpp
index f65ffc47d89a1..0693d4bd6c91e 100644
--- a/openmp/libomptarget/src/PluginManager.cpp
+++ b/openmp/libomptarget/src/PluginManager.cpp
@@ -89,19 +89,6 @@ Error PluginAdaptorTy::init() {
return Error::success();
}
-void PluginAdaptorTy::addOffloadEntries(DeviceImageTy &DI) {
- for (int32_t I = 0, E = getNumberOfUserDevices(); I < E; ++I) {
- auto DeviceOrErr = PM->getDevice(DeviceOffset + I);
- if (!DeviceOrErr)
- FATAL_MESSAGE(DeviceOffset + I, "%s",
- toString(DeviceOrErr.takeError()).c_str());
-
- DeviceTy &Device = *DeviceOrErr;
- for (__tgt_offload_entry &Entry : DI.entries())
- Device.addOffloadEntry(OffloadEntryTy(DI, Entry));
- }
-}
-
void PluginManager::init() {
TIMESCOPE();
DP("Loading RTLs...\n");
@@ -259,9 +246,6 @@ void PluginManager::registerLib(__tgt_bin_desc *Desc) {
PM->TrlTblMtx.unlock();
FoundRTL = &R;
- // Register all offload entries with the devices handled by the plugin.
- R.addOffloadEntries(DI);
-
// if an RTL was found we are done - proceed to register the next image
break;
}
@@ -302,34 +286,6 @@ void PluginManager::unregisterLib(__tgt_bin_desc *Desc) {
FoundRTL = &R;
- // Execute dtors for static objects if the device has been used, i.e.
- // if its PendingCtors list has been emptied.
- for (int32_t I = 0; I < FoundRTL->getNumberOfUserDevices(); ++I) {
- auto DeviceOrErr = PM->getDevice(FoundRTL->DeviceOffset + I);
- if (!DeviceOrErr)
- FATAL_MESSAGE(FoundRTL->DeviceOffset + I, "%s",
- toString(DeviceOrErr.takeError()).c_str());
-
- DeviceTy &Device = *DeviceOrErr;
- Device.PendingGlobalsMtx.lock();
- if (Device.PendingCtorsDtors[Desc].PendingCtors.empty()) {
- AsyncInfoTy AsyncInfo(Device);
- for (auto &Dtor : Device.PendingCtorsDtors[Desc].PendingDtors) {
- int Rc =
- target(nullptr, Device, Dtor, CTorDTorKernelArgs, AsyncInfo);
- if (Rc != OFFLOAD_SUCCESS) {
- DP("Running destructor " DPxMOD " failed.\n", DPxPTR(Dtor));
- }
- }
- // Remove this library's entry from PendingCtorsDtors
- Device.PendingCtorsDtors.erase(Desc);
- // All constructors have been issued, wait for them now.
- if (AsyncInfo.synchronize() != OFFLOAD_SUCCESS)
- DP("Failed synchronizing destructors kernels.\n");
- }
- Device.PendingGlobalsMtx.unlock();
- }
-
DP("Unregistered image " DPxMOD " from RTL " DPxMOD "!\n",
DPxPTR(Img->ImageStart), DPxPTR(R.LibraryHandler.get()));
diff --git a/openmp/libomptarget/src/device.cpp b/openmp/libomptarget/src/device.cpp
index 9bdc6b7cd8c9a..67edc559e8ede 100644
--- a/openmp/libomptarget/src/device.cpp
+++ b/openmp/libomptarget/src/device.cpp
@@ -66,7 +66,7 @@ int HostDataToTargetTy::addEventIfNecessary(DeviceTy &Device,
DeviceTy::DeviceTy(PluginAdaptorTy *RTL, int32_t DeviceID, int32_t RTLDeviceID)
: DeviceID(DeviceID), RTL(RTL), RTLDeviceID(RTLDeviceID),
- PendingCtorsDtors(), PendingGlobalsMtx(), MappingInfo(*this) {}
+ MappingInfo(*this) {}
DeviceTy::~DeviceTy() {
if (DeviceID == -1 || !(getInfoLevel() & OMP_INFOTYPE_DUMP_TABLE))
@@ -297,48 +297,11 @@ int32_t DeviceTy::destroyEvent(void *Event) {
return OFFLOAD_SUCCESS;
}
-void DeviceTy::addOffloadEntry(const OffloadEntryTy &Entry) {
- std::lock_guard<decltype(PendingGlobalsMtx)> Lock(PendingGlobalsMtx);
- DeviceOffloadEntries.getExclusiveAccessor()->insert({Entry.getName(), Entry});
- if (Entry.isGlobal())
- return;
-
- if (Entry.isCTor()) {
- DP("Adding ctor " DPxMOD " to the pending list.\n",
- DPxPTR(Entry.getAddress()));
- MESSAGE("WARNING: Calling deprecated constructor for entry %s will be "
- "removed in a future release \n",
- Entry.getNameAsCStr());
- PendingCtorsDtors[Entry.getBinaryDescription()].PendingCtors.push_back(
- Entry.getAddress());
- } else if (Entry.isDTor()) {
- // Dtors are pushed in reverse order so they are executed from end
- // to beginning when unregistering the library!
- DP("Adding dtor " DPxMOD " to the pending list.\n",
- DPxPTR(Entry.getAddress()));
- MESSAGE("WARNING: Calling deprecated destructor for entry %s will be "
- "removed in a future release \n",
- Entry.getNameAsCStr());
- PendingCtorsDtors[Entry.getBinaryDescription()].PendingDtors.push_front(
- Entry.getAddress());
- }
-
- if (Entry.isLink()) {
- MESSAGE(
- "WARNING: The \"link\" attribute is not yet supported for entry: %s!\n",
- Entry.getNameAsCStr());
- }
-}
-
void DeviceTy::dumpOffloadEntries() {
fprintf(stderr, "Device %i offload entries:\n", DeviceID);
for (auto &It : *DeviceOffloadEntries.getExclusiveAccessor()) {
const char *Kind = "kernel";
- if (It.second.isCTor())
- Kind = "constructor";
- else if (It.second.isDTor())
- Kind = "destructor";
- else if (It.second.isLink())
+ if (It.second.isLink())
Kind = "link";
else if (It.second.isGlobal())
Kind = "global var.";
diff --git a/openmp/libomptarget/src/omptarget.cpp b/openmp/libomptarget/src/omptarget.cpp
index 04490ab076b65..5b852495b7501 100644
--- a/openmp/libomptarget/src/omptarget.cpp
+++ b/openmp/libomptarget/src/omptarget.cpp
@@ -291,36 +291,9 @@ static int initLibrary(DeviceTy &Device) {
}
}
- if (Rc != OFFLOAD_SUCCESS) {
+ if (Rc != OFFLOAD_SUCCESS)
return Rc;
- }
- /*
- * Run ctors for static objects
- */
- if (!Device.PendingCtorsDtors.empty()) {
- AsyncInfoTy AsyncInfo(Device);
- // Call all ctors for all libraries registered so far
- for (auto &Lib : Device.PendingCtorsDtors) {
- if (!Lib.second.PendingCtors.empty()) {
- DP("Has pending ctors... call now\n");
- for (auto &Entry : Lib.second.PendingCtors) {
- void *Ctor = Entry;
- int Rc = target(nullptr, Device, Ctor, CTorDTorKernelArgs, AsyncInfo);
- if (Rc != OFFLOAD_SUCCESS) {
- REPORT("Running ctor " DPxMOD " failed.\n", DPxPTR(Ctor));
- return OFFLOAD_FAIL;
- }
- }
- // Clear the list to indicate that this device has been used
- Lib.second.PendingCtors.clear();
- DP("Done with pending ctors for lib " DPxMOD "\n", DPxPTR(Lib.first));
- }
- }
- // All constructors have been issued, wait for them now.
- if (AsyncInfo.synchronize() != OFFLOAD_SUCCESS)
- return OFFLOAD_FAIL;
- }
Device.HasMappedGlobalData = true;
static Int32Envar DumpOffloadEntries =
@@ -435,14 +408,10 @@ bool checkDeviceAndCtors(int64_t &DeviceID, ident_t *Loc) {
FATAL_MESSAGE(DeviceID, "%s", toString(DeviceOrErr.takeError()).data());
// Check whether global data has been mapped for this device
- {
- std::lock_guard<decltype(DeviceOrErr->PendingGlobalsMtx)> LG(
- DeviceOrErr->PendingGlobalsMtx);
- if (initLibrary(*DeviceOrErr) != OFFLOAD_SUCCESS) {
- REPORT("Failed to init globals on device %" PRId64 "\n", DeviceID);
- handleTargetOutcome(false, Loc);
- return true;
- }
+ if (initLibrary(*DeviceOrErr) != OFFLOAD_SUCCESS) {
+ REPORT("Failed to init globals on device %" PRId64 "\n", DeviceID);
+ handleTargetOutcome(false, Loc);
+ return true;
}
return false;
diff --git a/openmp/libomptarget/test/offloading/ctor_dtor.cpp b/openmp/libomptarget/test/offloading/ctor_dtor.cpp
index 1d8b5838c2ccf..7f08798dea103 100644
--- a/openmp/libomptarget/test/offloading/ctor_dtor.cpp
+++ b/openmp/libomptarget/test/offloading/ctor_dtor.cpp
@@ -1,13 +1,6 @@
// RUN: %libomptarget-compilexx-run-and-check-generic
// RUN: %libomptarget-compileoptxx-run-and-check-generic
-// RUN: %libomptarget-compilexx-generic && \
-// RUN: env OMPTARGET_DUMP_OFFLOAD_ENTRIES=0 %libomptarget-run-generic 2>&1 | \
-// RUN: %fcheck-generic --check-prefix=DUMP
-//
-// DUMP: Device 0 offload entries:
-// DUMP-DAG: global var.: s
-// DUMP-DAG: kernel: __omp_offloading_{{.*}}_main_
-//
+
#include <cstdio>
struct S {
S() : i(7) {}
More information about the Openmp-commits
mailing list