From 9b33db9b24acf880f03a57de0a4756c31ecb70d7 Mon Sep 17 00:00:00 2001 From: Ioannis Assiouras Date: Thu, 11 Jul 2024 22:50:41 +0100 Subject: [PATCH] SWDEV-472309 - Ensure static maps are destroyed after __hipUnregisterFatBinary hipDeviceSynchronize called from __hipUnregisterFatBinary accesses static maps and monitors. This change ensures these ojects are not destroyed before __hipUnregisterFatBinary is called. Additionally it disables the teardown process for static build. Change-Id: I46b58641d60efcf6637a8e99cdd786ffe9e2c77d --- hipamd/src/hip_context.cpp | 2 +- hipamd/src/hip_graph_internal.cpp | 6 ++++-- rocclr/platform/command.cpp | 2 +- rocclr/platform/runtime.cpp | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/hipamd/src/hip_context.cpp b/hipamd/src/hip_context.cpp index a056e58c98..f58768792f 100644 --- a/hipamd/src/hip_context.cpp +++ b/hipamd/src/hip_context.cpp @@ -28,7 +28,7 @@ namespace hip { std::once_flag g_ihipInitialized; -std::vector g_devices; +std::vector g_devices ROCCLR_INIT_PRIORITY(101); thread_local TlsAggregator tls; amd::Context* host_context = nullptr; diff --git a/hipamd/src/hip_graph_internal.cpp b/hipamd/src/hip_graph_internal.cpp index baa9fa1644..77ce47d490 100644 --- a/hipamd/src/hip_graph_internal.cpp +++ b/hipamd/src/hip_graph_internal.cpp @@ -51,8 +51,10 @@ const char* GetGraphNodeTypeString(uint32_t op) { } namespace hip { -std::unordered_map> GraphExecStatus_; -amd::Monitor GraphExecStatusLock_{"Guards graph execution state"}; +std::unordered_map> + GraphExecStatus_ ROCCLR_INIT_PRIORITY(101); +amd::Monitor GraphExecStatusLock_ ROCCLR_INIT_PRIORITY(101){ + "Guards graph execution state"}; int GraphNode::nextID = 0; int Graph::nextID = 0; diff --git a/rocclr/platform/command.cpp b/rocclr/platform/command.cpp index 2c98c4563d..b61159b99d 100644 --- a/rocclr/platform/command.cpp +++ b/rocclr/platform/command.cpp @@ -318,7 +318,7 @@ Command::Command(HostQueue& queue, cl_command_type type, const EventWaitList& ev } } -SysmemPool Command::command_pool_; +SysmemPool Command::command_pool_ ROCCLR_INIT_PRIORITY(101); // ================================================================================================ void Command::operator delete(void* ptr) { diff --git a/rocclr/platform/runtime.cpp b/rocclr/platform/runtime.cpp index 1b710ca207..945f54527a 100644 --- a/rocclr/platform/runtime.cpp +++ b/rocclr/platform/runtime.cpp @@ -109,7 +109,7 @@ amd::Monitor listenerLock("Hostcall listener lock"); std::vector RuntimeTearDown::external_; RuntimeTearDown::~RuntimeTearDown() { -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(BUILD_STATIC_LIBS) // Only perform destruction if process matches the initialization, // to avoid a call with the child process after fork() if (amd::IS_HIP && amd::Os::getProcessId() == Runtime::pid()) {