Support ROCP_TOOL_LIBRARIES env + librocprofiler-sdk.so (#48)
* Fix support for version in find_package(rocprofiler-register <version>) * Update lib/rocprofiler-register/rocprofiler-register.cpp - change rocprofiler library name to librocprofiler-sdk.so - add helper function rocp_load_rocprofiler_lib for dlopen of rocprofiler library - support ROCP_TOOL_LIBRARIES environment variable - reworked rocprofiler_register_error_string * Update tests/rocprofiler - rename library to librocprofiler-sdk - remove rocprofiler_configure within librocprofiler-sdk.so * Add tests/generic-tool - provides implementation of rocprofiler_configure * Update tests/CMakeLists.txt - use libgeneric-tool.so - LD_PRELOAD libgeneric-tool.so instead of librocprofiler - Add tests which use ROCP_TOOL_LIBRARIES * Update tests/generic-tool/generic-tool.cpp - include <cstdint>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b04c8478f2
Коммит
ab02cb6570
@@ -9,7 +9,7 @@
|
||||
get_filename_component(@PROJECT_NAME@_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||
|
||||
# version
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-version.cmake)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-config-version.cmake)
|
||||
|
||||
set(@PROJECT_NAME@_VERSION ${PACKAGE_VERSION})
|
||||
|
||||
|
||||
@@ -46,14 +46,14 @@ configure_package_config_file(
|
||||
PATH_VARS PROJECT_INSTALL_DIR INCLUDE_INSTALL_DIR LIB_INSTALL_DIR)
|
||||
|
||||
write_basic_package_version_file(
|
||||
${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-version.cmake
|
||||
${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-config-version.cmake
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY SameMinorVersion)
|
||||
|
||||
install(
|
||||
FILES
|
||||
${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-config.cmake
|
||||
${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-version.cmake
|
||||
${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-config-version.cmake
|
||||
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}
|
||||
OPTIONAL)
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ namespace
|
||||
{
|
||||
using namespace rocprofiler_register;
|
||||
using rocprofiler_set_api_table_t = decltype(::rocprofiler_set_api_table)*;
|
||||
using rocp_set_api_table_data_t = std::tuple<void*, rocprofiler_set_api_table_t>;
|
||||
using bitset_t = std::bitset<sizeof(rocprofiler_register_library_indentifier_t::handle)>;
|
||||
|
||||
static_assert(sizeof(bitset_t) ==
|
||||
@@ -85,7 +86,7 @@ static_assert(sizeof(bitset_t) ==
|
||||
|
||||
int rocprofiler_register_verbose = common::get_env("ROCPROFILER_REGISTER_VERBOSE", 0);
|
||||
constexpr int rocprofiler_register_info_level = 2;
|
||||
constexpr auto rocprofiler_lib_name = "librocprofiler64.so";
|
||||
constexpr auto rocprofiler_lib_name = "librocprofiler-sdk.so";
|
||||
constexpr auto rocprofiler_lib_register_entrypoint = "rocprofiler_set_api_table";
|
||||
constexpr auto rocprofiler_register_lib_name =
|
||||
"librocprofiler-register.so." ROCPROFILER_REGISTER_SOVERSION;
|
||||
@@ -108,6 +109,9 @@ struct supported_library_trait
|
||||
static constexpr const char* const library_name = nullptr;
|
||||
};
|
||||
|
||||
template <size_t Idx>
|
||||
struct rocp_reg_error_message;
|
||||
|
||||
#define ROCP_REG_DEFINE_LIBRARY_TRAITS(ENUM, NAME, SYM_NAME, LIB_NAME) \
|
||||
template <> \
|
||||
struct supported_library_trait<ENUM> \
|
||||
@@ -119,6 +123,13 @@ struct supported_library_trait
|
||||
static constexpr auto library_name = LIB_NAME; \
|
||||
};
|
||||
|
||||
#define ROCP_REG_DEFINE_ERROR_MESSAGE(ENUM, MSG) \
|
||||
template <> \
|
||||
struct rocp_reg_error_message<ENUM> \
|
||||
{ \
|
||||
static constexpr auto value = MSG; \
|
||||
};
|
||||
|
||||
ROCP_REG_DEFINE_LIBRARY_TRAITS(ROCP_REG_HSA,
|
||||
"hsa",
|
||||
"rocprofiler_register_import_hsa",
|
||||
@@ -134,6 +145,20 @@ ROCP_REG_DEFINE_LIBRARY_TRAITS(ROCP_REG_ROCTX,
|
||||
"rocprofiler_register_import_roctx",
|
||||
"libroctx64.so.[4-9]($|\\.[0-9\\.]+)")
|
||||
|
||||
ROCP_REG_DEFINE_ERROR_MESSAGE(ROCP_REG_SUCCESS, "Success")
|
||||
ROCP_REG_DEFINE_ERROR_MESSAGE(ROCP_REG_NO_TOOLS, "rocprofiler-register found no tools")
|
||||
ROCP_REG_DEFINE_ERROR_MESSAGE(ROCP_REG_DEADLOCK, "rocprofiler-register deadlocked")
|
||||
ROCP_REG_DEFINE_ERROR_MESSAGE(ROCP_REG_BAD_API_TABLE_LENGTH,
|
||||
"Library passed an invalid number of API tables")
|
||||
ROCP_REG_DEFINE_ERROR_MESSAGE(ROCP_REG_UNSUPPORTED_API, "Library's API is not supported")
|
||||
ROCP_REG_DEFINE_ERROR_MESSAGE(ROCP_REG_INVALID_API_ADDRESS,
|
||||
"Invalid API address (secure mode enabled)")
|
||||
ROCP_REG_DEFINE_ERROR_MESSAGE(ROCP_REG_ROCPROFILER_ERROR,
|
||||
"Unspecified rocprofiler-register error")
|
||||
ROCP_REG_DEFINE_ERROR_MESSAGE(
|
||||
ROCP_REG_EXCESS_API_INSTANCES,
|
||||
"Too many instances of the same library API were registered")
|
||||
|
||||
auto
|
||||
get_this_library_path()
|
||||
{
|
||||
@@ -145,6 +170,23 @@ get_this_library_path()
|
||||
return fs::path{ *_this_lib_path }.parent_path().string();
|
||||
}
|
||||
|
||||
template <size_t Idx, size_t... Tail>
|
||||
constexpr auto
|
||||
rocprofiler_register_error_string(rocprofiler_register_error_code_t _ec,
|
||||
std::index_sequence<Idx, Tail...>)
|
||||
{
|
||||
if(_ec == Idx) return rocp_reg_error_message<Idx>::value;
|
||||
|
||||
if constexpr(sizeof...(Tail) > 0)
|
||||
{
|
||||
return rocprofiler_register_error_string(_ec, std::index_sequence<Tail...>{});
|
||||
}
|
||||
else
|
||||
{
|
||||
return "rocprofiler_register_unknown_error";
|
||||
}
|
||||
}
|
||||
|
||||
struct rocp_import
|
||||
{
|
||||
rocp_reg_supported_library library_idx = ROCP_REG_LAST;
|
||||
@@ -169,71 +211,35 @@ auto rocp_reg_get_imports(std::index_sequence<Idx...>)
|
||||
return _data;
|
||||
}
|
||||
|
||||
rocp_set_api_table_data_t
|
||||
rocp_load_rocprofiler_lib(std::string _rocp_reg_lib);
|
||||
|
||||
auto
|
||||
rocp_reg_scan_for_tools()
|
||||
{
|
||||
auto _rocp_reg_lib = common::get_env("ROCPROFILER_REGISTER_LIBRARY", std::string{});
|
||||
bool _force_tool =
|
||||
common::get_env("ROCPROFILER_REGISTER_FORCE_LOAD", !_rocp_reg_lib.empty());
|
||||
bool _found_tool = (rocprofiler_configure != nullptr || _force_tool);
|
||||
auto* _configure_func = dlsym(RTLD_DEFAULT, "rocprofiler_configure");
|
||||
auto _rocp_tool_libs = common::get_env("ROCP_TOOL_LIBRARIES", std::string{});
|
||||
auto _rocp_reg_lib = common::get_env("ROCPROFILER_REGISTER_LIBRARY", std::string{});
|
||||
bool _force_tool =
|
||||
common::get_env("ROCPROFILER_REGISTER_FORCE_LOAD",
|
||||
!_rocp_reg_lib.empty() || !_rocp_tool_libs.empty());
|
||||
bool _found_tool =
|
||||
(rocprofiler_configure != nullptr || _configure_func != nullptr || _force_tool);
|
||||
|
||||
static void* rocprofiler_lib_handle = nullptr;
|
||||
static rocprofiler_set_api_table_t rocprofiler_lib_config_fn = nullptr;
|
||||
|
||||
if(_force_tool)
|
||||
if(_found_tool)
|
||||
{
|
||||
if(rocprofiler_lib_handle && rocprofiler_lib_config_fn)
|
||||
return std::make_pair(rocprofiler_lib_handle, rocprofiler_lib_config_fn);
|
||||
|
||||
if(_rocp_reg_lib.empty()) _rocp_reg_lib = rocprofiler_lib_name;
|
||||
std::tie(rocprofiler_lib_handle, rocprofiler_lib_config_fn) =
|
||||
rocp_load_rocprofiler_lib(rocprofiler_lib_name);
|
||||
|
||||
auto _rocp_reg_lib_path = fs::path{ _rocp_reg_lib };
|
||||
auto _rocp_reg_lib_path_fname = _rocp_reg_lib_path.filename();
|
||||
auto _rocp_reg_lib_path_abs =
|
||||
(_rocp_reg_lib_path.is_absolute())
|
||||
? _rocp_reg_lib_path
|
||||
: (fs::path{ get_this_library_path() } / _rocp_reg_lib_path_fname);
|
||||
|
||||
// check to see if the rocprofiler library is already loaded
|
||||
rocprofiler_lib_handle =
|
||||
dlopen(_rocp_reg_lib_path.c_str(), RTLD_NOLOAD | RTLD_LAZY);
|
||||
|
||||
// try to load with the given path
|
||||
if(!rocprofiler_lib_handle)
|
||||
{
|
||||
rocprofiler_lib_handle =
|
||||
dlopen(_rocp_reg_lib_path.c_str(), RTLD_GLOBAL | RTLD_LAZY);
|
||||
}
|
||||
|
||||
// try to load with the absoulte path
|
||||
if(!rocprofiler_lib_handle)
|
||||
{
|
||||
_rocp_reg_lib_path = _rocp_reg_lib_path_abs;
|
||||
rocprofiler_lib_handle =
|
||||
dlopen(_rocp_reg_lib_path.c_str(), RTLD_GLOBAL | RTLD_LAZY);
|
||||
}
|
||||
|
||||
// try to load with the basename path
|
||||
if(!rocprofiler_lib_handle)
|
||||
{
|
||||
_rocp_reg_lib_path = _rocp_reg_lib_path_fname;
|
||||
rocprofiler_lib_handle =
|
||||
dlopen(_rocp_reg_lib_path.c_str(), RTLD_GLOBAL | RTLD_LAZY);
|
||||
}
|
||||
|
||||
if(rocprofiler_register_verbose >= rocprofiler_register_info_level)
|
||||
LOG(INFO) << "loaded " << _rocp_reg_lib_path_fname.string() << " library at "
|
||||
<< _rocp_reg_lib_path.string();
|
||||
|
||||
LOG_IF(FATAL, rocprofiler_lib_handle == nullptr)
|
||||
<< _rocp_reg_lib << " failed to load\n";
|
||||
|
||||
*(void**) (&rocprofiler_lib_config_fn) =
|
||||
dlsym(rocprofiler_lib_handle, rocprofiler_lib_register_entrypoint);
|
||||
|
||||
LOG_IF(FATAL, rocprofiler_lib_config_fn == nullptr)
|
||||
<< _rocp_reg_lib << " did not contain '"
|
||||
<< rocprofiler_lib_register_entrypoint << "' symbol\n";
|
||||
if(!rocprofiler_lib_config_fn)
|
||||
std::tie(rocprofiler_lib_handle, rocprofiler_lib_config_fn) =
|
||||
rocp_load_rocprofiler_lib("librocprofiler64.so");
|
||||
}
|
||||
else if(_found_tool && rocprofiler_set_api_table)
|
||||
{
|
||||
@@ -243,6 +249,66 @@ rocp_reg_scan_for_tools()
|
||||
return std::make_pair(rocprofiler_lib_handle, rocprofiler_lib_config_fn);
|
||||
}
|
||||
|
||||
rocp_set_api_table_data_t
|
||||
rocp_load_rocprofiler_lib(std::string _rocp_reg_lib)
|
||||
{
|
||||
void* rocprofiler_lib_handle = nullptr;
|
||||
rocprofiler_set_api_table_t rocprofiler_lib_config_fn = nullptr;
|
||||
|
||||
if(rocprofiler_set_api_table) rocprofiler_lib_config_fn = &rocprofiler_set_api_table;
|
||||
|
||||
if(_rocp_reg_lib.empty()) _rocp_reg_lib = rocprofiler_lib_name;
|
||||
|
||||
auto _rocp_reg_lib_path = fs::path{ _rocp_reg_lib };
|
||||
auto _rocp_reg_lib_path_fname = _rocp_reg_lib_path.filename();
|
||||
auto _rocp_reg_lib_path_abs =
|
||||
(_rocp_reg_lib_path.is_absolute())
|
||||
? _rocp_reg_lib_path
|
||||
: (fs::path{ get_this_library_path() } / _rocp_reg_lib_path_fname);
|
||||
|
||||
// check to see if the rocprofiler library is already loaded
|
||||
rocprofiler_lib_handle = dlopen(_rocp_reg_lib_path.c_str(), RTLD_NOLOAD | RTLD_LAZY);
|
||||
|
||||
// try to load with the given path
|
||||
if(!rocprofiler_lib_handle)
|
||||
{
|
||||
rocprofiler_lib_handle =
|
||||
dlopen(_rocp_reg_lib_path.c_str(), RTLD_GLOBAL | RTLD_LAZY);
|
||||
}
|
||||
|
||||
// try to load with the absoulte path
|
||||
if(!rocprofiler_lib_handle)
|
||||
{
|
||||
_rocp_reg_lib_path = _rocp_reg_lib_path_abs;
|
||||
rocprofiler_lib_handle =
|
||||
dlopen(_rocp_reg_lib_path.c_str(), RTLD_GLOBAL | RTLD_LAZY);
|
||||
}
|
||||
|
||||
// try to load with the basename path
|
||||
if(!rocprofiler_lib_handle)
|
||||
{
|
||||
_rocp_reg_lib_path = _rocp_reg_lib_path_fname;
|
||||
rocprofiler_lib_handle =
|
||||
dlopen(_rocp_reg_lib_path.c_str(), RTLD_GLOBAL | RTLD_LAZY);
|
||||
}
|
||||
|
||||
if(rocprofiler_register_verbose >= rocprofiler_register_info_level)
|
||||
LOG(INFO) << "loaded " << _rocp_reg_lib_path_fname.string() << " library at "
|
||||
<< _rocp_reg_lib_path.string();
|
||||
|
||||
LOG_IF(FATAL, rocprofiler_lib_handle == nullptr)
|
||||
<< _rocp_reg_lib << " failed to load\n";
|
||||
|
||||
*(void**) (&rocprofiler_lib_config_fn) =
|
||||
dlsym(rocprofiler_lib_handle, rocprofiler_lib_register_entrypoint);
|
||||
|
||||
LOG_IF(FATAL, rocprofiler_lib_config_fn == nullptr)
|
||||
<< _rocp_reg_lib << " did not contain '" << rocprofiler_lib_register_entrypoint
|
||||
<< "' symbol\n";
|
||||
|
||||
return std::make_tuple(rocprofiler_lib_handle, rocprofiler_lib_config_fn);
|
||||
}
|
||||
|
||||
constexpr auto library_seq = std::make_index_sequence<ROCP_REG_LAST>{};
|
||||
auto global_mutex = std::recursive_mutex{};
|
||||
auto import_info = rocp_reg_get_imports(library_seq);
|
||||
@@ -353,21 +419,7 @@ rocprofiler_register_library_api_table(
|
||||
const char*
|
||||
rocprofiler_register_error_string(rocprofiler_register_error_code_t _ec)
|
||||
{
|
||||
switch(_ec)
|
||||
{
|
||||
case ROCP_REG_SUCCESS: return "rocprofiler_register_success";
|
||||
case ROCP_REG_NO_TOOLS: return "rocprofiler_register_no_tools";
|
||||
case ROCP_REG_DEADLOCK: return "rocprofiler_register_deadlock";
|
||||
case ROCP_REG_BAD_API_TABLE_LENGTH:
|
||||
return "rocprofiler_register_bad_api_table_length";
|
||||
case ROCP_REG_UNSUPPORTED_API: return "rocprofiler_register_unsupported_api";
|
||||
case ROCP_REG_INVALID_API_ADDRESS:
|
||||
return "rocprofiler_register_invalid_api_address";
|
||||
case ROCP_REG_ROCPROFILER_ERROR: return "rocprofiler_register_rocprofiler_error";
|
||||
case ROCP_REG_EXCESS_API_INSTANCES:
|
||||
return "rocprofiler_register_excess_api_instances";
|
||||
case ROCP_REG_ERROR_CODE_END: return "rocprofiler_register_unknown_error";
|
||||
}
|
||||
return "rocprofiler_register_unknown_error";
|
||||
return rocprofiler_register_error_string(
|
||||
_ec, std::make_index_sequence<ROCP_REG_ERROR_CODE_END>{});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,11 @@ add_subdirectory(amdhip)
|
||||
add_subdirectory(roctx)
|
||||
add_subdirectory(rocprofiler)
|
||||
|
||||
#
|
||||
# mock tool library
|
||||
#
|
||||
add_subdirectory(generic-tool)
|
||||
|
||||
#
|
||||
# common to multiple tests
|
||||
#
|
||||
@@ -90,13 +95,20 @@ target_compile_definitions(rocprofiler-register-tests-strong
|
||||
add_library(rocprofiler-register-tests-weak INTERFACE)
|
||||
target_compile_definitions(rocprofiler-register-tests-weak INTERFACE ROCP_REG_TEST_WEAK=1)
|
||||
|
||||
add_library(rocprofiler-register-tests-tool INTERFACE)
|
||||
target_link_options(rocprofiler-register-tests-tool INTERFACE -Wl,--no-as-needed)
|
||||
target_link_libraries(rocprofiler-register-tests-tool
|
||||
INTERFACE generic-tool::generic-tool)
|
||||
|
||||
add_library(rocprofiler-register-tests-rocp INTERFACE)
|
||||
target_link_options(rocprofiler-register-tests-rocp INTERFACE -Wl,--no-as-needed)
|
||||
target_link_libraries(rocprofiler-register-tests-rocp INTERFACE rocprofiler::rocprofiler)
|
||||
target_link_libraries(rocprofiler-register-tests-rocp
|
||||
INTERFACE rocprofiler::rocprofiler generic-tool::generic-tool)
|
||||
|
||||
add_library(rocprofiler-register::tests-common ALIAS rocprofiler-register-tests-common)
|
||||
add_library(rocprofiler-register::tests-strong ALIAS rocprofiler-register-tests-strong)
|
||||
add_library(rocprofiler-register::tests-weak ALIAS rocprofiler-register-tests-weak)
|
||||
add_library(rocprofiler-register::tests-tool ALIAS rocprofiler-register-tests-tool)
|
||||
add_library(rocprofiler-register::tests-rocp ALIAS rocprofiler-register-tests-rocp)
|
||||
|
||||
#
|
||||
@@ -146,7 +158,10 @@ function(rocp_register_test_executable _NAME)
|
||||
rocp_register_add_test(${_NAME} ${_NAME} "" "${RRTE_CORE_PASS_REGEX}"
|
||||
"${RRTE_CORE_FAIL_REGEX}")
|
||||
|
||||
rocp_register_add_test(${_NAME}-preload ${_NAME} "LD_PRELOAD=librocprofiler64.so"
|
||||
rocp_register_add_test(${_NAME}-preload ${_NAME} "LD_PRELOAD=libgeneric-tool.so"
|
||||
"${RRTE_PRELOAD_PASS_REGEX}" "${RRTE_PRELOAD_FAIL_REGEX}")
|
||||
|
||||
rocp_register_add_test(${_NAME}-env ${_NAME} "ROCP_TOOL_LIBRARIES=libgeneric-tool.so"
|
||||
"${RRTE_PRELOAD_PASS_REGEX}" "${RRTE_PRELOAD_FAIL_REGEX}")
|
||||
|
||||
rocp_register_add_test(${_NAME}-wrap ${_NAME} "ROCP_REG_TEST_WRAP=1"
|
||||
@@ -154,7 +169,12 @@ function(rocp_register_test_executable _NAME)
|
||||
|
||||
rocp_register_add_test(
|
||||
${_NAME}-preload-wrap ${_NAME}
|
||||
"LD_PRELOAD=librocprofiler64.so;ROCP_REG_TEST_WRAP=1"
|
||||
"LD_PRELOAD=libgeneric-tool.so;ROCP_REG_TEST_WRAP=1"
|
||||
"${RRTE_PRELOAD_WRAP_PASS_REGEX}" "${RRTE_PRELOAD_WRAP_FAIL_REGEX}")
|
||||
|
||||
rocp_register_add_test(
|
||||
${_NAME}-env-wrap ${_NAME}
|
||||
"ROCP_TOOL_LIBRARIES=libgeneric-tool.so;ROCP_REG_TEST_WRAP=1"
|
||||
"${RRTE_PRELOAD_WRAP_PASS_REGEX}" "${RRTE_PRELOAD_WRAP_FAIL_REGEX}")
|
||||
|
||||
endfunction()
|
||||
@@ -189,6 +209,21 @@ rocp_register_test_executable(
|
||||
".fwd.hpp. dlopen libamdhip64.so, 1\n.fwd.hpp. dlopen libroctx64.so, 1\n.rocprofiler.cpp. rocp_ctor\n.rocprofiler.cpp. hsa :: 20100 :: 0 :: 1\n.hsa-runtime.cpp. hsa identifier 0\n.rocprofiler.cpp. hsa_init\n.rocprofiler.cpp. hip :: 60001 :: 0 :: 1\n.amdhip.cpp. hip identifier 8\n.rocprofiler.cpp. hip_init\n.rocprofiler.cpp. roctx :: 40601 :: 0 :: 1\n.roctx.cpp. roctx identifier 16\n.rocprofiler.cpp..push. thread-main\n.rocprofiler.cpp..pop. thread-main\n"
|
||||
)
|
||||
|
||||
rocp_register_test_executable(
|
||||
test-amdhip-roctx-tool
|
||||
SOURCES test-amdhip-roctx.cpp
|
||||
LIBRARIES rocprofiler-register::tests-strong amdhip::amdhip roctx::roctx
|
||||
rocprofiler-register::tests-tool
|
||||
CORE_PASS_REGEX
|
||||
".rocprofiler.cpp. rocp_ctor\n.rocprofiler.cpp. hsa :: 20100 :: 0 :: 1\n.hsa-runtime.cpp. hsa identifier 0\n.hsa-runtime.cpp. hsa_init\n.rocprofiler.cpp. hip :: 60001 :: 0 :: 1\n.amdhip.cpp. hip identifier 8\n.amdhip.cpp. hip_init\n.rocprofiler.cpp. roctx :: 40601 :: 0 :: 1\n.roctx.cpp. roctx identifier 16\n.roctx.cpp..push. thread-main\n.roctx.cpp..pop. thread-main\n"
|
||||
PRELOAD_PASS_REGEX
|
||||
".rocprofiler.cpp. rocp_ctor\n.rocprofiler.cpp. hsa :: 20100 :: 0 :: 1\n.hsa-runtime.cpp. hsa identifier 0\n.hsa-runtime.cpp. hsa_init\n.rocprofiler.cpp. hip :: 60001 :: 0 :: 1\n.amdhip.cpp. hip identifier 8\n.amdhip.cpp. hip_init\n.rocprofiler.cpp. roctx :: 40601 :: 0 :: 1\n.roctx.cpp. roctx identifier 16\n.roctx.cpp..push. thread-main\n.roctx.cpp..pop. thread-main\n"
|
||||
WRAP_PASS_REGEX
|
||||
".rocprofiler.cpp. rocp_ctor\n.rocprofiler.cpp. hsa :: 20100 :: 0 :: 1\n.hsa-runtime.cpp. hsa identifier 0\n.rocprofiler.cpp. hsa_init\n.rocprofiler.cpp. hip :: 60001 :: 0 :: 1\n.amdhip.cpp. hip identifier 8\n.rocprofiler.cpp. hip_init\n.rocprofiler.cpp. roctx :: 40601 :: 0 :: 1\n.roctx.cpp. roctx identifier 16\n.rocprofiler.cpp..push. thread-main\n.rocprofiler.cpp..pop. thread-main\n"
|
||||
PRELOAD_WRAP_PASS_REGEX
|
||||
".rocprofiler.cpp. rocp_ctor\n.rocprofiler.cpp. hsa :: 20100 :: 0 :: 1\n.hsa-runtime.cpp. hsa identifier 0\n.rocprofiler.cpp. hsa_init\n.rocprofiler.cpp. hip :: 60001 :: 0 :: 1\n.amdhip.cpp. hip identifier 8\n.rocprofiler.cpp. hip_init\n.rocprofiler.cpp. roctx :: 40601 :: 0 :: 1\n.roctx.cpp. roctx identifier 16\n.rocprofiler.cpp..push. thread-main\n.rocprofiler.cpp..pop. thread-main\n"
|
||||
)
|
||||
|
||||
rocp_register_test_executable(
|
||||
test-amdhip-roctx-rocp
|
||||
SOURCES test-amdhip-roctx.cpp
|
||||
@@ -204,6 +239,20 @@ rocp_register_test_executable(
|
||||
".rocprofiler.cpp. rocp_ctor\n.rocprofiler.cpp. hsa :: 20100 :: 0 :: 1\n.hsa-runtime.cpp. hsa identifier 0\n.rocprofiler.cpp. hsa_init\n.rocprofiler.cpp. hip :: 60001 :: 0 :: 1\n.amdhip.cpp. hip identifier 8\n.rocprofiler.cpp. hip_init\n.rocprofiler.cpp. roctx :: 40601 :: 0 :: 1\n.roctx.cpp. roctx identifier 16\n.rocprofiler.cpp..push. thread-main\n.rocprofiler.cpp..pop. thread-main\n"
|
||||
)
|
||||
|
||||
rocp_register_test_executable(
|
||||
test-amdhip-roctx-weak-tool
|
||||
SOURCES test-amdhip-roctx.cpp
|
||||
LIBRARIES rocprofiler-register::tests-weak rocprofiler-register::tests-tool
|
||||
CORE_PASS_REGEX
|
||||
".fwd.hpp. dlopen libamdhip64.so, 1\n.fwd.hpp. dlopen libroctx64.so, 1\n.rocprofiler.cpp. rocp_ctor\n.rocprofiler.cpp. hsa :: 20100 :: 0 :: 1\n.hsa-runtime.cpp. hsa identifier 0\n.hsa-runtime.cpp. hsa_init\n.rocprofiler.cpp. hip :: 60001 :: 0 :: 1\n.amdhip.cpp. hip identifier 8\n.amdhip.cpp. hip_init\n.rocprofiler.cpp. roctx :: 40601 :: 0 :: 1\n.roctx.cpp. roctx identifier 16\n.roctx.cpp..push. thread-main\n.roctx.cpp..pop. thread-main\n"
|
||||
PRELOAD_PASS_REGEX
|
||||
".fwd.hpp. dlopen libamdhip64.so, 1\n.fwd.hpp. dlopen libroctx64.so, 1\n.rocprofiler.cpp. rocp_ctor\n.rocprofiler.cpp. hsa :: 20100 :: 0 :: 1\n.hsa-runtime.cpp. hsa identifier 0\n.hsa-runtime.cpp. hsa_init\n.rocprofiler.cpp. hip :: 60001 :: 0 :: 1\n.amdhip.cpp. hip identifier 8\n.amdhip.cpp. hip_init\n.rocprofiler.cpp. roctx :: 40601 :: 0 :: 1\n.roctx.cpp. roctx identifier 16\n.roctx.cpp..push. thread-main\n.roctx.cpp..pop. thread-main\n"
|
||||
WRAP_PASS_REGEX
|
||||
".fwd.hpp. dlopen libamdhip64.so, 1\n.fwd.hpp. dlopen libroctx64.so, 1\n.rocprofiler.cpp. rocp_ctor\n.rocprofiler.cpp. hsa :: 20100 :: 0 :: 1\n.hsa-runtime.cpp. hsa identifier 0\n.rocprofiler.cpp. hsa_init\n.rocprofiler.cpp. hip :: 60001 :: 0 :: 1\n.amdhip.cpp. hip identifier 8\n.rocprofiler.cpp. hip_init\n.rocprofiler.cpp. roctx :: 40601 :: 0 :: 1\n.roctx.cpp. roctx identifier 16\n.rocprofiler.cpp..push. thread-main\n.rocprofiler.cpp..pop. thread-main\n"
|
||||
PRELOAD_WRAP_PASS_REGEX
|
||||
".fwd.hpp. dlopen libamdhip64.so, 1\n.fwd.hpp. dlopen libroctx64.so, 1\n.rocprofiler.cpp. rocp_ctor\n.rocprofiler.cpp. hsa :: 20100 :: 0 :: 1\n.hsa-runtime.cpp. hsa identifier 0\n.rocprofiler.cpp. hsa_init\n.rocprofiler.cpp. hip :: 60001 :: 0 :: 1\n.amdhip.cpp. hip identifier 8\n.rocprofiler.cpp. hip_init\n.rocprofiler.cpp. roctx :: 40601 :: 0 :: 1\n.roctx.cpp. roctx identifier 16\n.rocprofiler.cpp..push. thread-main\n.rocprofiler.cpp..pop. thread-main\n"
|
||||
)
|
||||
|
||||
rocp_register_test_executable(
|
||||
test-amdhip-roctx-weak-rocp
|
||||
SOURCES test-amdhip-roctx.cpp
|
||||
@@ -456,7 +505,7 @@ set_tests_properties(
|
||||
test-rocprofiler-register-library-base-path
|
||||
PROPERTIES
|
||||
ENVIRONMENT
|
||||
"LD_LIBRARY_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY};ROCPROFILER_REGISTER_LIBRARY=librocprofiler64.so;ROCPROFILER_REGISTER_SECURE=yes;ROCPROFILER_REGISTER_VERBOSE=3;ROCPROFILER_REGISTER_MONOCHROME=true"
|
||||
"LD_LIBRARY_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY};ROCPROFILER_REGISTER_LIBRARY=librocprofiler-sdk.so.0;ROCPROFILER_REGISTER_SECURE=yes;ROCPROFILER_REGISTER_VERBOSE=3;ROCPROFILER_REGISTER_MONOCHROME=true"
|
||||
LABELS
|
||||
"dlopen;secure")
|
||||
|
||||
@@ -469,6 +518,6 @@ set_tests_properties(
|
||||
test-rocprofiler-register-library-absolute-path
|
||||
PROPERTIES
|
||||
ENVIRONMENT
|
||||
"LD_LIBRARY_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY};ROCPROFILER_REGISTER_LIBRARY=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/librocprofiler64.so;ROCPROFILER_REGISTER_SECURE=yes;ROCPROFILER_REGISTER_VERBOSE=3;ROCPROFILER_REGISTER_MONOCHROME=true"
|
||||
"LD_LIBRARY_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY};ROCPROFILER_REGISTER_LIBRARY=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/librocprofiler-sdk.so.0;ROCPROFILER_REGISTER_SECURE=yes;ROCPROFILER_REGISTER_VERBOSE=3;ROCPROFILER_REGISTER_MONOCHROME=true"
|
||||
LABELS
|
||||
"dlopen;secure")
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#
|
||||
# mock generic-tool library
|
||||
#
|
||||
add_library(generic-tool SHARED)
|
||||
add_library(generic-tool::generic-tool ALIAS generic-tool)
|
||||
target_sources(generic-tool PRIVATE generic-tool.cpp)
|
||||
target_include_directories(
|
||||
generic-tool PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>)
|
||||
# target_link_libraries(generic-tool PRIVATE rocprofiler)
|
||||
rocp_register_strip_target(generic-tool)
|
||||
@@ -0,0 +1,46 @@
|
||||
|
||||
#include <pthread.h>
|
||||
#include <cstdint>
|
||||
#include <stdexcept>
|
||||
#include <string_view>
|
||||
|
||||
extern "C" {
|
||||
typedef struct
|
||||
{
|
||||
const char* name; ///< clients should set this value for debugging
|
||||
const uint32_t handle; ///< internal handle
|
||||
} rocprofiler_client_id_t;
|
||||
|
||||
typedef void (*rocprofiler_client_finalize_t)(rocprofiler_client_id_t);
|
||||
|
||||
typedef int (*rocprofiler_tool_initialize_t)(rocprofiler_client_finalize_t finalize_func,
|
||||
void* tool_data);
|
||||
|
||||
typedef void (*rocprofiler_tool_finalize_t)(void* tool_data);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t size; ///< in case of future extensions
|
||||
rocprofiler_tool_initialize_t initialize; ///< context creation
|
||||
rocprofiler_tool_finalize_t finalize; ///< cleanup
|
||||
void* tool_data; ///< data to provide to init and fini callbacks
|
||||
} rocprofiler_tool_configure_result_t;
|
||||
|
||||
rocprofiler_tool_configure_result_t*
|
||||
rocprofiler_configure(uint32_t, const char*, uint32_t, rocprofiler_client_id_t*)
|
||||
__attribute__((visibility("default")));
|
||||
|
||||
rocprofiler_tool_configure_result_t*
|
||||
rocprofiler_configure(uint32_t version,
|
||||
const char* runtime_version,
|
||||
uint32_t priority,
|
||||
rocprofiler_client_id_t* tool_id)
|
||||
{
|
||||
(void) version;
|
||||
(void) runtime_version;
|
||||
(void) priority;
|
||||
(void) tool_id;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ target_include_directories(rocprofiler PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>)
|
||||
set_target_properties(
|
||||
rocprofiler
|
||||
PROPERTIES OUTPUT_NAME rocprofiler64
|
||||
SOVERSION 2
|
||||
VERSION 2.0.0)
|
||||
PROPERTIES OUTPUT_NAME rocprofiler-sdk
|
||||
SOVERSION 0
|
||||
VERSION 0.0.0)
|
||||
rocp_register_strip_target(rocprofiler)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <hsa-runtime/hsa-runtime.hpp>
|
||||
#include <roctx/roctx.hpp>
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <pthread.h>
|
||||
#include <stdexcept>
|
||||
#include <string_view>
|
||||
@@ -42,49 +43,10 @@ roctx_range_pop(const char* name)
|
||||
} // namespace rocprofiler
|
||||
|
||||
extern "C" {
|
||||
typedef struct
|
||||
{
|
||||
const char* name; ///< clients should set this value for debugging
|
||||
const uint32_t handle; ///< internal handle
|
||||
} rocprofiler_client_id_t;
|
||||
|
||||
typedef void (*rocprofiler_client_finalize_t)(rocprofiler_client_id_t);
|
||||
|
||||
typedef int (*rocprofiler_tool_initialize_t)(rocprofiler_client_finalize_t finalize_func,
|
||||
void* tool_data);
|
||||
|
||||
typedef void (*rocprofiler_tool_finalize_t)(void* tool_data);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t size; ///< in case of future extensions
|
||||
rocprofiler_tool_initialize_t initialize; ///< context creation
|
||||
rocprofiler_tool_finalize_t finalize; ///< cleanup
|
||||
void* tool_data; ///< data to provide to init and fini callbacks
|
||||
} rocprofiler_tool_configure_result_t;
|
||||
|
||||
rocprofiler_tool_configure_result_t*
|
||||
rocprofiler_configure(uint32_t, const char*, uint32_t, rocprofiler_client_id_t*)
|
||||
__attribute__((visibility("default")));
|
||||
|
||||
int
|
||||
rocprofiler_set_api_table(const char*, uint64_t, uint64_t, void**, uint64_t)
|
||||
__attribute__((visibility("default")));
|
||||
|
||||
rocprofiler_tool_configure_result_t*
|
||||
rocprofiler_configure(uint32_t version,
|
||||
const char* runtime_version,
|
||||
uint32_t priority,
|
||||
rocprofiler_client_id_t* tool_id)
|
||||
{
|
||||
(void) version;
|
||||
(void) runtime_version;
|
||||
(void) priority;
|
||||
(void) tool_id;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int
|
||||
rocprofiler_set_api_table(const char* name,
|
||||
uint64_t lib_version,
|
||||
@@ -99,6 +61,20 @@ rocprofiler_set_api_table(const char* name,
|
||||
lib_instance,
|
||||
num_tables);
|
||||
|
||||
auto* _tool_libs = std::getenv("ROCP_TOOL_LIBRARIES");
|
||||
if(_tool_libs)
|
||||
{
|
||||
auto* _handle = dlopen(_tool_libs, RTLD_GLOBAL | RTLD_LAZY);
|
||||
if(!_handle)
|
||||
throw std::runtime_error{ std::string{ "error opening tool library " } +
|
||||
_tool_libs };
|
||||
auto* _sym = dlsym(_handle, "rocprofiler_configure");
|
||||
if(!_sym)
|
||||
throw std::runtime_error{ std::string{ "tool library " } +
|
||||
std::string{ _tool_libs } +
|
||||
" did not contain rocprofiler_configure symbol" };
|
||||
}
|
||||
|
||||
using hip_table_t = hip::HipApiTable;
|
||||
using hsa_table_t = hsa::HsaApiTable;
|
||||
using roctx_table_t = roctx::ROCTxApiTable;
|
||||
|
||||
Ссылка в новой задаче
Block a user