2
0

rocprofiler-register support

- Update CMakeLists.txt
  - find_package for rocprofiler-register
    - this is an optional package until rocprofiler-register is added to the CI
  - define HSA_VERSION_{MAJOR,MINOR,PATCH} ppdefs
- Update runtime.cpp
  - include <rocprofiler-register/rocprofiler-register.h>
  - if rocprofiler-register succeeds, do not support v1 unless explicitly requested

Change-Id: I8f48bbf3f6b52fb91ddade2f198491a1256035fe


[ROCm/ROCR-Runtime commit: f9cf1852e5]
Este cometimento está contido em:
Jonathan R. Madsen
2023-10-16 21:07:57 -05:00
cometido por David Yat Sin
ascendente 73ab40ecd3
cometimento 880ddd4387
2 ficheiros modificados com 58 adições e 0 eliminações
+9
Ver ficheiro
@@ -281,6 +281,15 @@ endif()
target_link_libraries ( ${CORE_RUNTIME_TARGET} PRIVATE hsakmt::hsakmt PkgConfig::drm)
target_link_libraries ( ${CORE_RUNTIME_TARGET} PRIVATE elf::elf dl pthread rt )
find_package(rocprofiler-register)
if(rocprofiler-register_FOUND)
target_compile_definitions(${CORE_RUNTIME_TARGET} PRIVATE HSA_ROCPROFILER_REGISTER=1
HSA_VERSION_MAJOR=${VERSION_MAJOR}
HSA_VERSION_MINOR=${VERSION_MINOR}
HSA_VERSION_PATCH=${VERSION_PATCH})
target_link_libraries(${CORE_RUNTIME_TARGET} PRIVATE rocprofiler-register::rocprofiler-register)
endif()
## Set the VERSION and SOVERSION values
set_property ( TARGET ${CORE_RUNTIME_TARGET} PROPERTY VERSION "${SO_VERSION_STRING}" )
set_property ( TARGET ${CORE_RUNTIME_TARGET} PROPERTY SOVERSION "${VERSION_MAJOR}" )
@@ -45,6 +45,7 @@
#include <algorithm>
#include <atomic>
#include <cstring>
#include <regex>
#include <string>
#include <vector>
#include <list>
@@ -52,6 +53,10 @@
#include <amdgpu_drm.h>
#include <sys/mman.h>
#if defined(HSA_ROCPROFILER_REGISTER) && HSA_ROCPROFILER_REGISTER > 0
#include <rocprofiler-register/rocprofiler-register.h>
#endif
#include "core/common/shared.h"
#include "core/inc/hsa_ext_interface.h"
#include "core/inc/amd_cpu_agent.h"
@@ -66,8 +71,22 @@
#include "core/inc/exceptions.h"
#include "inc/hsa_ven_amd_aqlprofile.h"
#ifndef HSA_VERSION_MAJOR
#define HSA_VERSION_MAJOR 1
#endif
#ifndef HSA_VERSION_MINOR
#define HSA_VERSION_MINOR 1
#endif
#ifndef HSA_VERSION_PATCH
#define HSA_VERSION_PATCH 0
#endif
#if defined(HSA_ROCPROFILER_REGISTER) && HSA_ROCPROFILER_REGISTER > 0
#define ROCP_REG_VERSION \
ROCPROFILER_REGISTER_COMPUTE_VERSION_3(HSA_VERSION_MAJOR, HSA_VERSION_MINOR, HSA_VERSION_PATCH)
ROCPROFILER_REGISTER_DEFINE_IMPORT(hsa, ROCP_REG_VERSION)
#endif
const char rocrbuildid[] __attribute__((used)) = "ROCR BUILD ID: " STRING(ROCR_BUILD_ID);
@@ -1720,6 +1739,36 @@ void Runtime::LoadTools() {
typedef Agent* (*tool_wrap_t)(Agent*);
typedef void (*tool_add_t)(Runtime*);
#if defined(HSA_ROCPROFILER_REGISTER) && HSA_ROCPROFILER_REGISTER > 0
auto* profiler_api_table_ = static_cast<void*>(&hsa_api_table_);
auto lib_id = rocprofiler_register_library_indentifier_t{};
auto success =
rocprofiler_register_library_api_table("hsa", &ROCPROFILER_REGISTER_IMPORT_FUNC(hsa),
ROCP_REG_VERSION, &profiler_api_table_, 1, &lib_id);
bool allow_v1_registration = false;
if(os::IsEnvVarSet("HSA_TOOLS_ROCPROFILER_V1_TOOLS"))
{
// assume true if env variable is set
allow_v1_registration = true;
auto allow_v1_value = os::GetEnvVar("HSA_TOOLS_ROCPROFILER_V1_TOOLS");
// support using numbers, off, false, no, n, or f
if (!allow_v1_value.empty()) {
if (allow_v1_value.find_first_not_of("0123456789") == std::string::npos) {
allow_v1_registration = (std::stoi(allow_v1_value) != 0);
} else if (std::regex_match(
allow_v1_value,
std::regex{"^(off|false|no|n|f)$", std::regex_constants::icase})) {
allow_v1_registration = false;
}
}
}
// if rocprofiler library supports registration and v1 support not explicitly requested, do not
// use old method
if (success != 0 && !allow_v1_registration) return;
#endif
std::vector<const char*> failed;
//Get loaded libs and filter to tool libraries.