diff --git a/rocclr/cmake/ROCclrLC.cmake b/rocclr/cmake/ROCclrLC.cmake index cb78fa2418..504fa018e8 100644 --- a/rocclr/cmake/ROCclrLC.cmake +++ b/rocclr/cmake/ROCclrLC.cmake @@ -30,3 +30,8 @@ if(BUILD_SHARED_LIBS) target_compile_definitions(rocclr PUBLIC COMGR_DYN_DLL) endif() target_link_libraries(rocclr PUBLIC amd_comgr) + +if(${CMAKE_PROJECT_NAME} STREQUAL "hip") + add_definitions(-DHIP_MAJOR_VERSION=${HIP_VERSION_MAJOR}) + add_definitions(-DHIP_MINOR_VERSION=${HIP_VERSION_MINOR}) +endif() diff --git a/rocclr/device/comgrctx.cpp b/rocclr/device/comgrctx.cpp index fd5b8dea4c..90dedadb06 100644 --- a/rocclr/device/comgrctx.cpp +++ b/rocclr/device/comgrctx.cpp @@ -28,13 +28,40 @@ std::once_flag Comgr::initialized; ComgrEntryPoints Comgr::cep_; bool Comgr::is_ready_ = false; -bool Comgr::LoadLib() { +bool Comgr::LoadLib(bool is_versioned) { #if defined(COMGR_DYN_DLL) ClPrint(amd::LOG_INFO, amd::LOG_CODE, "Loading COMGR library."); - static constexpr const char* ComgrLibName = + + if (is_versioned) { +#if defined(HIP_MAJOR_VERSION) && defined(HIP_MAJOR_VERSION) + std::string comgr_versioned_name, major_version, minor_version; + const std::string kComgrPrefix = "amd_comgr"; + + if (HIP_MAJOR_VERSION > 9) { + major_version = std::to_string(HIP_MAJOR_VERSION); + } else { + major_version = "0" + std::to_string(HIP_MAJOR_VERSION); + } + + if (HIP_MINOR_VERSION > 9) { + minor_version = std::to_string(HIP_MINOR_VERSION); + } else { + minor_version = "0" + std::to_string(HIP_MINOR_VERSION); + } + + comgr_versioned_name = kComgrPrefix + major_version + minor_version + std::string(".dll"); + + static const char* comgr_lib_name = + LP64_SWITCH(WINDOWS_SWITCH("amd_comgr32.dll", "libamd_comgr32.so.2"), + WINDOWS_SWITCH(comgr_versioned_name.c_str(), "libamd_comgr.so.2")); + cep_.handle = Os::loadLibrary(comgr_lib_name); +#endif + } else { + static constexpr const char* comgr_lib_name = LP64_SWITCH(WINDOWS_SWITCH("amd_comgr32.dll", "libamd_comgr32.so.2"), WINDOWS_SWITCH("amd_comgr.dll", "libamd_comgr.so.2")); - cep_.handle = Os::loadLibrary(ComgrLibName); + cep_.handle = Os::loadLibrary(comgr_lib_name); + } if (nullptr == cep_.handle) { ClPrint(amd::LOG_ERROR, amd::LOG_CODE, "Failed to load COMGR library."); return false; diff --git a/rocclr/device/comgrctx.hpp b/rocclr/device/comgrctx.hpp index 31ee24e1f1..d008a39528 100644 --- a/rocclr/device/comgrctx.hpp +++ b/rocclr/device/comgrctx.hpp @@ -140,7 +140,7 @@ class Comgr : public amd::AllStatic { public: static std::once_flag initialized; - static bool LoadLib(); + static bool LoadLib(bool is_versioned = false); static bool IsReady() { return is_ready_; } diff --git a/rocclr/device/device.cpp b/rocclr/device/device.cpp index ac229437cc..126b4b7ca0 100644 --- a/rocclr/device/device.cpp +++ b/rocclr/device/device.cpp @@ -531,7 +531,8 @@ bool Device::ValidateComgr() { #if defined(USE_COMGR_LIBRARY) // Check if Lightning compiler was requested if (settings_->useLightning_) { - std::call_once(amd::Comgr::initialized, amd::Comgr::LoadLib); + constexpr bool kComgrVersioned = false; + std::call_once(amd::Comgr::initialized, amd::Comgr::LoadLib, kComgrVersioned); // Use Lightning only if it's available settings_->useLightning_ = amd::Comgr::IsReady(); return settings_->useLightning_;