From 3c9f80b4e47289ad6bb9f753be92653271b9af7a Mon Sep 17 00:00:00 2001 From: "Kudchadker, Saleel" Date: Tue, 24 Jun 2025 13:00:00 -0700 Subject: [PATCH] SWDEV-535490 - Improve logging (#441) - Include HIP version/githash in the logs - Add a new method to print library path [ROCm/clr commit: 5d53c83806e9f769be82b7a445090847ff4eb214] --- projects/clr/hipamd/src/hip_context.cpp | 7 ++++++- projects/clr/rocclr/device/comgrctx.cpp | 1 - projects/clr/rocclr/device/rocm/rocdevice.cpp | 3 +-- projects/clr/rocclr/os/os.hpp | 3 +++ projects/clr/rocclr/os/os_posix.cpp | 9 +++++++++ projects/clr/rocclr/os/os_win32.cpp | 15 +++++++++++++++ 6 files changed, 34 insertions(+), 4 deletions(-) diff --git a/projects/clr/hipamd/src/hip_context.cpp b/projects/clr/hipamd/src/hip_context.cpp index 8a927ffbb1..ea8482a5d3 100644 --- a/projects/clr/hipamd/src/hip_context.cpp +++ b/projects/clr/hipamd/src/hip_context.cpp @@ -24,6 +24,7 @@ #include "platform/runtime.hpp" #include "rocclr/utils/flags.hpp" #include "rocclr/utils/versions.hpp" +#include "rocclr/os/os.hpp" #include namespace hip { @@ -51,8 +52,12 @@ void init(bool* status) { *status = false; return; } - ClPrint(amd::LOG_INFO, amd::LOG_INIT, "Direct Dispatch: %d", AMD_DIRECT_DISPATCH); + ClPrint(amd::LOG_INFO, amd::LOG_INIT, "HIP Version: %d.%d.%d.%s, Direct Dispatch: %d", + HIP_VERSION_MAJOR, HIP_VERSION_MINOR, HIP_VERSION_PATCH, HIP_VERSION_GITHASH, + AMD_DIRECT_DISPATCH); + // Print the current path of the library + amd::Os::PrintLibraryLocation(); const std::vector& devices = amd::Device::getDevices(CL_DEVICE_TYPE_GPU, false); const size_t deviceCount = devices.size(); g_devices.reserve(deviceCount); // Pre-allocate space for better performance diff --git a/projects/clr/rocclr/device/comgrctx.cpp b/projects/clr/rocclr/device/comgrctx.cpp index 9b5249abb2..5cd68f5982 100644 --- a/projects/clr/rocclr/device/comgrctx.cpp +++ b/projects/clr/rocclr/device/comgrctx.cpp @@ -30,7 +30,6 @@ bool Comgr::is_ready_ = false; bool Comgr::LoadLib(bool is_versioned) { #if defined(COMGR_DYN_DLL) - ClPrint(amd::LOG_INFO, amd::LOG_CODE, "Loading COMGR library."); if (is_versioned) { #if defined(HIP_MAJOR_VERSION) && defined(HIP_MAJOR_VERSION) diff --git a/projects/clr/rocclr/device/rocm/rocdevice.cpp b/projects/clr/rocclr/device/rocm/rocdevice.cpp index 4dd66cbcfc..1cc5851028 100644 --- a/projects/clr/rocclr/device/rocm/rocdevice.cpp +++ b/projects/clr/rocclr/device/rocm/rocdevice.cpp @@ -390,7 +390,6 @@ hsa_status_t Device::loaderQueryHostAddress(const void* device, const void** hos // ================================================================================================ bool Device::init() { - ClPrint(amd::LOG_INFO, amd::LOG_INIT, "Initializing HSA stack."); hsa_status_t status = HSA_STATUS_SUCCESS; // Initialize the compiler if (!initCompiler(offlineDevice_)) { @@ -476,7 +475,7 @@ bool Device::init() { gpu_agents_ = valid_agents; } - LogPrintfInfo("Enumerated GPU agents = %lu", gpu_agents_.size()); + LogPrintfInfo("Initalizing runtime stack, Enumerated GPU agents = %lu", gpu_agents_.size()); for (auto agent : gpu_agents_) { std::unique_ptr roc_device(new Device(agent)); diff --git a/projects/clr/rocclr/os/os.hpp b/projects/clr/rocclr/os/os.hpp index 8509cc3627..e8b7c0d2ad 100644 --- a/projects/clr/rocclr/os/os.hpp +++ b/projects/clr/rocclr/os/os.hpp @@ -328,6 +328,9 @@ class Os : AllStatic { //! Return the current process id static int getProcessId(); + + // Prints the location of the currently loaded library (shared object or DLL) + static void PrintLibraryLocation(); }; /*@}*/ diff --git a/projects/clr/rocclr/os/os_posix.cpp b/projects/clr/rocclr/os/os_posix.cpp index af04650b86..6ee367842c 100644 --- a/projects/clr/rocclr/os/os_posix.cpp +++ b/projects/clr/rocclr/os/os_posix.cpp @@ -960,6 +960,15 @@ void Os::CloseIpcMemory(const FileDesc desc, const void* ptr, size_t size) { } } +void Os::PrintLibraryLocation() { + Dl_info dl_info; + if (dladdr(reinterpret_cast(Os::loadLibrary), &dl_info) && dl_info.dli_fname) { + ClPrint(amd::LOG_INFO, amd::LOG_INIT, "HIP Library Path: %s", dl_info.dli_fname); + } else { + ClPrint(amd::LOG_INFO, amd::LOG_INIT, "HIP Library Path: "); + } +} + } // namespace amd #endif // !defined(_WIN32) && !defined(__CYGWIN__) diff --git a/projects/clr/rocclr/os/os_win32.cpp b/projects/clr/rocclr/os/os_win32.cpp index 08ba2a21f4..f0db1d803f 100644 --- a/projects/clr/rocclr/os/os_win32.cpp +++ b/projects/clr/rocclr/os/os_win32.cpp @@ -732,6 +732,21 @@ void Os::CloseIpcMemory(const FileDesc desc, const void* ptr, size_t size) { } } +void Os::PrintLibraryLocation() { + HMODULE hm = NULL; + if (GetModuleHandleExA( + GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + (LPCSTR)&Os::loadLibrary, &hm)) { + char cszDllPath[1024] = {0}; + if (GetModuleFileNameA(hm, cszDllPath, sizeof(cszDllPath))) { + printf("HIP Library Path: %s\n", cszDllPath); + ClPrint(amd::LOG_INFO, amd::LOG_INIT, "HIP Library Path: %s", cszDllPath); + return; + } + } + ClPrint(amd::LOG_INFO, amd::LOG_INIT, "HIP Library Path: "); +} + } // namespace amd #endif // _WIN32 || __CYGWIN__