From 2d7167d068ccfebbd5994920f63b3e0f55722893 Mon Sep 17 00:00:00 2001 From: AravindanC Date: Fri, 16 Feb 2024 21:25:05 -0800 Subject: [PATCH] SWDEV-428381 Remove Hardcoded rocm path Change-Id: I39cfbc9add62813076db1992faea4426638859af --- CMakeLists.txt | 6 ++++++ plugin/ctf/CMakeLists.txt | 15 +++++++++++++++ plugin/ctf/ctf.cpp | 21 +++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 60382f9fc6..480e8b028b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,6 +168,12 @@ if(NOT USE_PROF_API) set(USE_PROF_API 1) endif() +# Enable use of getROCmInstallPath() API +if(USE_GET_ROCM_PATH_API) + set(USE_GET_ROCM_PATH_API 1) + message(STATUS "Enabled Use of getROCmInstallPath() API" ) +endif() + # Protocol header lookup set(PROF_API_HEADER_NAME prof_protocol.h) if(USE_PROF_API EQUAL 1) diff --git a/plugin/ctf/CMakeLists.txt b/plugin/ctf/CMakeLists.txt index f501e97ff9..f6dc7b1806 100644 --- a/plugin/ctf/CMakeLists.txt +++ b/plugin/ctf/CMakeLists.txt @@ -45,6 +45,14 @@ target_compile_definitions( PRIVATE HIP_PROF_HIP_API_STRING=1 __HIP_PLATFORM_AMD__=1 CTF_PLUGIN_METADATA_FILE_PATH="${METADATA_STREAM_FILE_DIR}/metadata" CTF_PLUGIN_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}") + +# Add definitions for getROCmInstallPath() API +if(USE_GET_ROCM_PATH_API) + target_compile_definitions( + ctf_plugin + PRIVATE USE_GET_ROCM_PATH_API=1) +endif() + target_include_directories( ctf_plugin PRIVATE "${PROJECT_SOURCE_DIR}" "${CMAKE_BINARY_DIR}/src/api" "${CMAKE_CURRENT_BINARY_DIR}") @@ -53,6 +61,13 @@ target_link_options( -Wl,--no-undefined) target_link_libraries(ctf_plugin PRIVATE rocprofiler-v2 hsa-runtime64::hsa-runtime64 stdc++fs dl) + +# Add link dependencies for getROCmInstallPath() API +if(USE_GET_ROCM_PATH_API) + find_library(ROCM_CORE_LIB rocm-core HINTS ${ROCM_PATH}/lib) + target_link_libraries(ctf_plugin PRIVATE ${ROCM_CORE_LIB}) +endif() + install(TARGETS ctf_plugin LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}" COMPONENT plugins) diff --git a/plugin/ctf/ctf.cpp b/plugin/ctf/ctf.cpp index 97265f3876..69598cbe68 100644 --- a/plugin/ctf/ctf.cpp +++ b/plugin/ctf/ctf.cpp @@ -35,6 +35,9 @@ #include "rocprofiler_plugin.h" #include "plugin.h" +#ifdef USE_GET_ROCM_PATH_API +#include +#endif namespace fs = std::experimental::filesystem; @@ -84,6 +87,23 @@ ROCPROFILER_EXPORT int rocprofiler_plugin_initialize(const uint32_t rocprofiler_ _replace("\\$ENV\\{PPID\\}", getppid()); // Create the plugin instance. + #ifdef USE_GET_ROCM_PATH_API + char *installPath = nullptr; + unsigned int installPathLen = 0; + PathErrors_t retVal = PathSuccess; + auto metadata_path = std::string{CTF_PLUGIN_METADATA_FILE_PATH}; + // Get ROCM install path + retVal = getROCmInstallPath( &installPath, &installPathLen ); + if(PathSuccess == retVal){ + metadata_path = fs::path(installPath); + }else { + std::cout << "Failed to get ROCm Install Path: " << retVal << std::endl; + } + // free allocated memory + if(nullptr != installPath) { + free(installPath); + } + #else auto* this_plugin_handle = dlopen("libctf_plugin.so", RTLD_LAZY | RTLD_NOLOAD); auto* librocprofiler_handle = dlopen("librocprofiler64.so", RTLD_LAZY | RTLD_NOLOAD); auto metadata_path = std::string{CTF_PLUGIN_METADATA_FILE_PATH}; @@ -100,6 +120,7 @@ ROCPROFILER_EXPORT int rocprofiler_plugin_initialize(const uint32_t rocprofiler_ if (!fs::exists(metadata_path)) { metadata_path = fs::path{CTF_PLUGIN_INSTALL_PREFIX} / CTF_PLUGIN_METADATA_FILE_PATH; } + #endif // USE_GET_ROCM_PATH_API try { the_plugin = new rocm_ctf::Plugin{256 * 1024, fs::path{output_dir} / output_file,