From af089a21715ec3f51daafec0403f5fc0ce4380e2 Mon Sep 17 00:00:00 2001 From: Ioannis Assiouras Date: Fri, 7 Jun 2024 15:02:50 +0100 Subject: [PATCH] SWDEV-463865 - namespace changes to prevent symbol conflicts in static builds Change-Id: I09ceb5962b7aa19156909f47167c87d6887c9cd1 [ROCm/clr commit: 3edf1501cccf5a8ffb053c3c019c781698273ae8] --- projects/clr/CMakeLists.txt | 3 +++ projects/clr/hipamd/src/fixme.cpp | 7 ------- projects/clr/hipamd/src/hip_activity.cpp | 2 +- projects/clr/hipamd/src/hip_context.cpp | 2 +- projects/clr/hipamd/src/hip_graph_internal.cpp | 2 ++ projects/clr/hipamd/src/hip_internal.hpp | 10 +++++----- projects/clr/rocclr/device/appprofile.cpp | 15 --------------- projects/clr/rocclr/platform/activity.cpp | 3 ++- projects/clr/rocclr/platform/activity.hpp | 3 ++- projects/clr/rocclr/platform/command.cpp | 2 +- projects/clr/rocclr/platform/commandqueue.cpp | 10 +++++++--- projects/clr/rocclr/utils/flags.cpp | 6 ++++++ projects/clr/rocclr/utils/flags.hpp | 9 ++++++++- 13 files changed, 38 insertions(+), 36 deletions(-) diff --git a/projects/clr/CMakeLists.txt b/projects/clr/CMakeLists.txt index 97999bab8c..2ff7b7bd33 100644 --- a/projects/clr/CMakeLists.txt +++ b/projects/clr/CMakeLists.txt @@ -69,6 +69,9 @@ if(CLR_BUILD_HIP) endif() if(CLR_BUILD_HIP) option(BUILD_SHARED_LIBS "Build the shared library" ON) + if (NOT BUILD_SHARED_LIBS) + add_compile_definitions(BUILD_STATIC_LIBS) + endif() endif() if((CLR_BUILD_HIP AND HIP_PLATFORM STREQUAL "amd") OR CLR_BUILD_OCL) add_subdirectory(rocclr) diff --git a/projects/clr/hipamd/src/fixme.cpp b/projects/clr/hipamd/src/fixme.cpp index 3560eff8c1..9ea3876427 100644 --- a/projects/clr/hipamd/src/fixme.cpp +++ b/projects/clr/hipamd/src/fixme.cpp @@ -31,10 +31,3 @@ cl_icd_dispatch amd::ICDDispatchedObject::icdVendorDispatch_[] = {0}; amd::PlatformIDS amd::PlatformID::Platform = {amd::ICDDispatchedObject::icdVendorDispatch_}; - -RUNTIME_ENTRY(cl_int, clGetDeviceIDs, - (cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, - cl_device_id* devices, cl_uint* num_devices)) { - return CL_SUCCESS; -} -RUNTIME_EXIT diff --git a/projects/clr/hipamd/src/hip_activity.cpp b/projects/clr/hipamd/src/hip_activity.cpp index a13a33126b..e2f7f63830 100644 --- a/projects/clr/hipamd/src/hip_activity.cpp +++ b/projects/clr/hipamd/src/hip_activity.cpp @@ -22,5 +22,5 @@ #include extern "C" const char* hipGetCmdName(unsigned op) { - return getOclCommandKindString(static_cast(op)); + return amd::activity_prof::getOclCommandKindString(static_cast(op)); } \ No newline at end of file diff --git a/projects/clr/hipamd/src/hip_context.cpp b/projects/clr/hipamd/src/hip_context.cpp index 107711d8ca..a056e58c98 100644 --- a/projects/clr/hipamd/src/hip_context.cpp +++ b/projects/clr/hipamd/src/hip_context.cpp @@ -25,9 +25,9 @@ #include "utils/flags.hpp" #include "utils/versions.hpp" +namespace hip { std::once_flag g_ihipInitialized; -namespace hip { std::vector g_devices; thread_local TlsAggregator tls; amd::Context* host_context = nullptr; diff --git a/projects/clr/hipamd/src/hip_graph_internal.cpp b/projects/clr/hipamd/src/hip_graph_internal.cpp index 8a40964c05..5da0d6ba4c 100644 --- a/projects/clr/hipamd/src/hip_graph_internal.cpp +++ b/projects/clr/hipamd/src/hip_graph_internal.cpp @@ -25,6 +25,7 @@ case X: \ case_string = #C; \ break; +namespace { const char* GetGraphNodeTypeString(uint32_t op) { const char* case_string; switch (static_cast(op)) { @@ -47,6 +48,7 @@ const char* GetGraphNodeTypeString(uint32_t op) { }; return case_string; }; +} namespace hip { std::unordered_map> GraphExecStatus_; diff --git a/projects/clr/hipamd/src/hip_internal.hpp b/projects/clr/hipamd/src/hip_internal.hpp index fd9a61385f..eab70a0f99 100644 --- a/projects/clr/hipamd/src/hip_internal.hpp +++ b/projects/clr/hipamd/src/hip_internal.hpp @@ -51,9 +51,9 @@ /*! IHIP IPC MEMORY Structure */ #define IHIP_IPC_MEM_HANDLE_SIZE 32 #define IHIP_IPC_MEM_RESERVED_SIZE LP64_SWITCH(20,12) - -extern std::once_flag g_ihipInitialized; - +namespace hip{ + extern std::once_flag g_ihipInitialized; +} typedef struct hipArray { void* data; // FIXME: generalize this struct hipChannelFormatDesc desc; @@ -99,7 +99,7 @@ const char* ihipGetErrorName(hipError_t hip_error); #define HIP_INIT(noReturn) \ { \ bool status = true; \ - std::call_once(g_ihipInitialized, hip::init, &status); \ + std::call_once(hip::g_ihipInitialized, hip::init, &status); \ if (!status && !noReturn) { \ HIP_RETURN(hipErrorInvalidDevice); \ } \ @@ -112,7 +112,7 @@ const char* ihipGetErrorName(hipError_t hip_error); #define HIP_INIT_VOID() \ { \ bool status = true; \ - std::call_once(g_ihipInitialized, hip::init, &status); \ + std::call_once(hip::g_ihipInitialized, hip::init, &status); \ if (hip::tls.device_ == nullptr && hip::g_devices.size() > 0) { \ hip::tls.device_ = hip::g_devices[0]; \ amd::Os::setPreferredNumaNode(hip::g_devices[0]->devices()[0]->getPreferredNumaNode()); \ diff --git a/projects/clr/rocclr/device/appprofile.cpp b/projects/clr/rocclr/device/appprofile.cpp index 23255ecde4..ec1006b5a7 100644 --- a/projects/clr/rocclr/device/appprofile.cpp +++ b/projects/clr/rocclr/device/appprofile.cpp @@ -25,11 +25,6 @@ #include #include -typedef void* ADLApplicationProfile; -int SearchProfileOfAnApplication(const wchar_t* fileName, ADLApplicationProfile** lppProfile) -{ - return 0; -} #define GETPROCADDRESS(_adltype_, _adlfunc_) (_adltype_) amd::Os::getSymbol(adlHandle_, #_adlfunc_); @@ -77,16 +72,6 @@ bool AppProfile::init() { } bool AppProfile::ParseApplicationProfile() { - ADLApplicationProfile* pProfile = NULL; - - if (!SearchProfileOfAnApplication(wsAppFileName_.c_str(), &pProfile)) { - return false; - } - - if (pProfile == NULL) { - return false; - } - return true; } } diff --git a/projects/clr/rocclr/platform/activity.cpp b/projects/clr/rocclr/platform/activity.cpp index 2f9bed578b..184969803a 100644 --- a/projects/clr/rocclr/platform/activity.cpp +++ b/projects/clr/rocclr/platform/activity.cpp @@ -122,7 +122,7 @@ void ReportActivity(const amd::Command& command) { } } -} // namespace amd::activity_prof + #define CASE_STRING(X, C) \ case X: \ @@ -168,3 +168,4 @@ const char* getOclCommandKindString(cl_command_type commandType) { }; return "Unknown command kind"; }; +} // namespace amd::activity_prof \ No newline at end of file diff --git a/projects/clr/rocclr/platform/activity.hpp b/projects/clr/rocclr/platform/activity.hpp index 7dbd0adef6..168bfcc23b 100644 --- a/projects/clr/rocclr/platform/activity.hpp +++ b/projects/clr/rocclr/platform/activity.hpp @@ -76,6 +76,7 @@ constexpr OpId OperationId(cl_command_type commandType) { bool IsEnabled(OpId operation_id); void ReportActivity(const amd::Command& command); -} // namespace amd::activity_prof + const char* getOclCommandKindString(cl_command_type kind); +} // namespace amd::activity_prof \ No newline at end of file diff --git a/projects/clr/rocclr/platform/command.cpp b/projects/clr/rocclr/platform/command.cpp index 5fa0cc6445..9829290b02 100644 --- a/projects/clr/rocclr/platform/command.cpp +++ b/projects/clr/rocclr/platform/command.cpp @@ -349,7 +349,7 @@ void Command::enqueue() { } ClPrint(LOG_DEBUG, LOG_CMD, "Command (%s) enqueued: %p", - getOclCommandKindString(this->type()), this); + amd::activity_prof::getOclCommandKindString(this->type()), this); // Direct dispatch logic below will submit the command immediately, but the command status // update will occur later after flush() with a wait diff --git a/projects/clr/rocclr/platform/commandqueue.cpp b/projects/clr/rocclr/platform/commandqueue.cpp index 91749a5e10..c8edb13b5a 100644 --- a/projects/clr/rocclr/platform/commandqueue.cpp +++ b/projects/clr/rocclr/platform/commandqueue.cpp @@ -192,13 +192,15 @@ void HostQueue::loop(device::VirtualDevice* virtualDevice) { const Command::EventWaitList& events = command->eventWaitList(); bool dependencyFailed = false; ClPrint(LOG_DEBUG, LOG_CMD, "Command (%s) processing: %p ,events.size(): %d", - getOclCommandKindString(command->type()), command, events.size()); + amd::activity_prof::getOclCommandKindString(command->type()), command, events.size()); for (const auto& it : events) { // Only wait if the command is enqueued into another queue. if (it->command().queue() != this) { // Runtime has to flush the current batch only if the dependent wait is blocking if (it->command().status() != CL_COMPLETE) { - ClPrint(LOG_DEBUG, LOG_CMD, "Command (%s) %p awaiting event: %p", getOclCommandKindString(command->type()), command, it); + ClPrint(LOG_DEBUG, LOG_CMD, "Command (%s) %p awaiting event: %p", + amd::activity_prof::getOclCommandKindString(command->type()), + command, it); virtualDevice->flush(head, true); tail = head = NULL; dependencyFailed |= !it->awaitCompletion(); @@ -219,7 +221,9 @@ void HostQueue::loop(device::VirtualDevice* virtualDevice) { continue; } - ClPrint(LOG_DEBUG, LOG_CMD, "Command (%s) submitted: %p", getOclCommandKindString(command->type()), command); + ClPrint(LOG_DEBUG, LOG_CMD, "Command (%s) submitted: %p", + amd::activity_prof::getOclCommandKindString(command->type()), + command); command->setStatus(CL_SUBMITTED); diff --git a/projects/clr/rocclr/utils/flags.cpp b/projects/clr/rocclr/utils/flags.cpp index 9ac9421b8f..96df2ed509 100644 --- a/projects/clr/rocclr/utils/flags.cpp +++ b/projects/clr/rocclr/utils/flags.cpp @@ -204,6 +204,9 @@ Flag Flag::flags_[] = { } // namespace amd +#ifndef _WIN32 +namespace { +#endif #define DEFINE_RELEASE_FLAG_VALUE(type, name, value, help) type name = value; #define DEFINE_DEBUG_FLAG_VALUE(type, name, value, help) DEBUG_ONLY(type name = value); @@ -211,3 +214,6 @@ RUNTIME_FLAGS(DEFINE_DEBUG_FLAG_VALUE, DEFINE_RELEASE_FLAG_VALUE, DEFINE_DEBUG_F #undef DEFINE_DEBUG_FLAG_VALUE #undef DEFINE_RELEASE_FLAG_VALUE +#ifndef _WIN32 +} +#endif diff --git a/projects/clr/rocclr/utils/flags.hpp b/projects/clr/rocclr/utils/flags.hpp index b6553cb78e..273a3dd911 100644 --- a/projects/clr/rocclr/utils/flags.hpp +++ b/projects/clr/rocclr/utils/flags.hpp @@ -328,7 +328,12 @@ struct Flag { #ifdef _WIN32 # define EXPORT_FLAG extern "C" __declspec(dllexport) #else // !_WIN32 +#ifdef BUILD_STATIC_LIBS +# define EXPORT_FLAG extern +#else # define EXPORT_FLAG extern "C" +#endif +namespace { #endif // !_WIN32 #define DECLARE_RELEASE_FLAG(type, name, value, help) EXPORT_FLAG type name; @@ -342,5 +347,7 @@ RUNTIME_FLAGS(DECLARE_DEBUG_FLAG, DECLARE_RELEASE_FLAG, DECLARE_DEBUG_FLAG); #undef DECLARE_DEBUG_FLAG #undef DECLARE_RELEASE_FLAG - +#ifndef _WIN32 +} +#endif // !_WIN32 #endif /*FLAGS_HPP_*/