Adding rocprofilerv2

Change-Id: Ic0cc280ba207d2b8f6ccae1cd4ac3184152fc1ad


[ROCm/rocprofiler commit: 8032adb64f]
This commit is contained in:
Ammar ELWazir
2023-02-03 12:31:39 -06:00
rodzic b23a2f3029
commit de4abd0d0f
263 zmienionych plików z 607729 dodań i 307 usunięć
@@ -0,0 +1,258 @@
# ############################################################################################################################################
# ROCMTOOL General Requirements
# ############################################################################################################################################
find_package(Python3 COMPONENTS Interpreter REQUIRED)
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import lxml"
RESULT_VARIABLE CPP_HEADER_PARSER
OUTPUT_QUIET)
if(NOT ${CPP_HEADER_PARSER} EQUAL 0)
message(FATAL_ERROR "\
The \"lxml\" Python3 package is not installed. \
Please install it using the following command: \"${Python3_EXECUTABLE} -m pip install lxml\".\
")
endif()
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import CppHeaderParser"
RESULT_VARIABLE CPP_HEADER_PARSER
OUTPUT_QUIET)
if(NOT ${CPP_HEADER_PARSER} EQUAL 0)
message(FATAL_ERROR "\
The \"CppHeaderParser\" Python3 package is not installed. \
Please install it using the following command: \"${Python3_EXECUTABLE} -m pip install CppHeaderParser\".\
")
endif()
# Setting Default Binary output directory
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
# Getting HSA Include Directory
get_property(HSA_RUNTIME_INCLUDE_DIRECTORIES TARGET hsa-runtime64::hsa-runtime64 PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
find_file(HSA_H hsa.h
PATHS ${HSA_RUNTIME_INCLUDE_DIRECTORIES}
PATH_SUFFIXES hsa
NO_DEFAULT_PATH
REQUIRED)
get_filename_component(HSA_RUNTIME_INC_PATH ${HSA_H} DIRECTORY)
find_library(AQLPROFILE_LIB "libhsa-amd-aqlprofile64.so" HINTS ${CMAKE_PREFIX_PATH} PATHS ${ROCM_PATH} PATH_SUFFIXES lib)
if(NOT AQLPROFILE_LIB)
message(FATAL_ERROR "AQL_PROFILE not installed. Please install hsa-amd-aqlprofile!")
endif()
# ############################################################################################################################################
# Adding Old Library Files
# ############################################################################################################################################
set (OLD_LIB_SRC
${LIB_DIR}/core/rocprofiler.cpp
${LIB_DIR}/core/gpu_command.cpp
${LIB_DIR}/core/proxy_queue.cpp
${LIB_DIR}/core/simple_proxy_queue.cpp
${LIB_DIR}/core/intercept_queue.cpp
${LIB_DIR}/core/metrics.cpp
${LIB_DIR}/core/activity.cpp
${LIB_DIR}/util/hsa_rsrc_factory.cpp
)
# ############################################################################################################################################
# Configuring Basic/Derived Counters
# ############################################################################################################################################
set(COUNTERS_DIR ${PROJECT_SOURCE_DIR}/src/core/counters)
execute_process(
COMMAND ${Python3_EXECUTABLE} ${COUNTERS_DIR}/basic/xml_parser_basic.py ${COUNTERS_DIR}/basic ${CMAKE_CURRENT_BINARY_DIR}/basic_counter.cpp
COMMENT "Generating basic_counter.cpp...")
# execute_process(
# COMMAND ${Python3_EXECUTABLE} ${COUNTERS_DIR}/derived/xml_parser_derived.py ${COUNTERS_DIR}/derived ${CMAKE_CURRENT_BINARY_DIR}/derived_counter.cpp
# COMMENT "Generating derived_counter.cpp...")
# ############################################################################################################################################
# ROCMTOOL Tracer HIP/HSA Parsing
# ############################################################################################################################################
get_property(HIP_INCLUDE_DIRECTORIES TARGET hip::amdhip64 PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
find_file(HIP_RUNTIME_API_H hip_runtime_api.h
PATHS ${HIP_INCLUDE_DIRECTORIES}
PATH_SUFFIXES hip
NO_DEFAULT_PATH
REQUIRED)
# # Generate the HSA wrapper functions header
add_custom_command(
OUTPUT hsa_prof_str.h hsa_prof_str.inline.h
COMMAND ${Python3_EXECUTABLE} ${PROJECT_SOURCE_DIR}/script/hsaap.py ${CMAKE_CURRENT_BINARY_DIR} "${HSA_RUNTIME_INC_PATH}" > /dev/null
DEPENDS ${PROJECT_SOURCE_DIR}/script/hsaap.py
"${HSA_RUNTIME_INC_PATH}/hsa.h" "${HSA_RUNTIME_INC_PATH}/hsa_ext_amd.h"
"${HSA_RUNTIME_INC_PATH}/hsa_ext_image.h" "${HSA_RUNTIME_INC_PATH}/hsa_api_trace.h"
COMMENT "Generating hsa_prof_str.h,hsa_prof_str.inline.h...")
# # Generate the HSA pretty printers
add_custom_command(
OUTPUT hsa_ostream_ops.h
COMMAND ${CMAKE_C_COMPILER} -E "${HSA_RUNTIME_INC_PATH}/hsa.h" -o hsa.h.i
COMMAND ${CMAKE_C_COMPILER} -E "${HSA_RUNTIME_INC_PATH}/hsa_ext_amd.h" -o hsa_ext_amd.h.i
BYPRODUCTS hsa.h.i hsa_ext_amd.h.i
COMMAND ${Python3_EXECUTABLE} ${PROJECT_SOURCE_DIR}/script/gen_ostream_ops.py
-in hsa.h.i,hsa_ext_amd.h.i -out hsa_ostream_ops.h > /dev/null
DEPENDS ${PROJECT_SOURCE_DIR}/script/gen_ostream_ops.py
"${HSA_RUNTIME_INC_PATH}/hsa.h" "${HSA_RUNTIME_INC_PATH}/hsa_ext_amd.h"
COMMENT "Generating hsa_ostream_ops.h...")
get_property(HIP_INCLUDE_DIRECTORIES TARGET hip::amdhip64 PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
find_file(HIP_RUNTIME_API_H hip_runtime_api.h
PATHS ${HIP_INCLUDE_DIRECTORIES}
PATH_SUFFIXES hip
NO_DEFAULT_PATH
REQUIRED)
## Generate the HIP pretty printers
add_custom_command(
OUTPUT hip_ostream_ops.h
COMMAND ${CMAKE_C_COMPILER} "$<$<BOOL:${HIP_INCLUDE_DIRECTORIES}>:-I$<JOIN:${HIP_INCLUDE_DIRECTORIES},$<SEMICOLON>-I>>"
-E "${HIP_RUNTIME_API_H}" -D__HIP_PLATFORM_HCC__=1 -D__HIP_ROCclr__=1 -o hip_runtime_api.h.i
BYPRODUCTS hip_runtime_api.h.i
COMMAND ${Python3_EXECUTABLE} ${PROJECT_SOURCE_DIR}/script/gen_ostream_ops.py
-in hip_runtime_api.h.i -out hip_ostream_ops.h > /dev/null
DEPENDS ${PROJECT_SOURCE_DIR}/script/gen_ostream_ops.py "${HIP_RUNTIME_API_H}"
COMMENT "Generating hip_ostream_ops.h..."
COMMAND_EXPAND_LISTS)
set(GENERATED_SOURCES
hip_ostream_ops.h
hsa_prof_str.h
hsa_ostream_ops.h
hsa_prof_str.inline.h)
# ############################################################################################################################################
# ROCMTOOL API
# ############################################################################################################################################
# PC sampling uses libpciaccess as a fallback if the debugfs ioctl is
# unavailable
find_path(PCIACCESS_INCLUDE_DIR pciaccess.h REQUIRED)
find_library(PCIACCESS_LIBRARIES pciaccess REQUIRED)
set(PUBLIC_HEADERS
rocprofiler_plugin.h
rocprofiler.h)
foreach(header ${PUBLIC_HEADERS})
install(FILES ${PROJECT_SOURCE_DIR}/inc/${header}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
COMPONENT dev)
endforeach()
# Getting Source files for ROCProfiler, Hardware, HSA, Memory, Session, Counters, Utils
file(GLOB ROCPROFILER_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
file(GLOB ROCPROFILER_PROFILER_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/session/profiler/profiler.cpp)
file(GLOB ROCPROFILER_TRACER_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/session/tracer/*.cpp)
file(GLOB ROCPROFILER_ROCTRACER_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/session/tracer/src/*.cpp)
file(GLOB ROCMTOOL_CLASS_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rocmtool.cpp)
file(GLOB ROCPROFILER_SPM_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/session/spm/spm.cpp)
set(CORE_HARDWARE_DIR ${PROJECT_SOURCE_DIR}/src/core/hardware)
file(GLOB CORE_HARDWARE_SRC_FILES ${CORE_HARDWARE_DIR}/*.cpp)
set(CORE_HSA_QUEUES_DIR ${PROJECT_SOURCE_DIR}/src/core/hsa/queues)
file(GLOB CORE_HSA_QUEUES_SRC_FILES ${CORE_HSA_QUEUES_DIR}/queue.cpp)
set(CORE_HSA_PACKETS_DIR ${PROJECT_SOURCE_DIR}/src/core/hsa/packets)
file(GLOB CORE_HSA_PACKETS_SRC_FILES ${CORE_HSA_PACKETS_DIR}/packets_generator.cpp)
set(CORE_HSA_DIR ${PROJECT_SOURCE_DIR}/src/core/hsa)
file(GLOB CORE_HSA_SRC_FILES ${CORE_HSA_DIR}/*.cpp)
set(CORE_MEMORY_DIR ${PROJECT_SOURCE_DIR}/src/core/memory)
file(GLOB CORE_MEMORY_SRC_FILES ${CORE_MEMORY_DIR}/*.cpp)
set(CORE_SESSION_DIR ${PROJECT_SOURCE_DIR}/src/core/session)
file(GLOB CORE_SESSION_SRC_FILES ${CORE_SESSION_DIR}/session.cpp)
file(GLOB CORE_FILTER_SRC_FILES ${CORE_SESSION_DIR}/filter.cpp)
file(GLOB CORE_DEVICE_PROFILING_SRC_FILES ${CORE_SESSION_DIR}/device_profiling.cpp)
file(GLOB CORE_COUNTERS_SRC_FILES ${PROJECT_BINARY_DIR}/src/api/*_counter.cpp)
file(GLOB CORE_COUNTERS_PARENT_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/counters/*.cpp)
file(GLOB CORE_COUNTERS_METRICS_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/counters/metrics/*.cpp)
set(CORE_UTILS_DIR ${PROJECT_SOURCE_DIR}/src/utils)
file(GLOB CORE_UTILS_SRC_FILES ${CORE_UTILS_DIR}/*.cpp)
set(CORE_PC_SAMPLING_DIR ${PROJECT_SOURCE_DIR}/src/pcsampler)
file(GLOB CORE_PC_SAMPLING_FILES ${CORE_PC_SAMPLING_DIR}/core/*.cpp ${CORE_PC_SAMPLING_DIR}/gfxip/*.cpp ${CORE_PC_SAMPLING_DIR}/session/*.cpp)
# Compiling/Installing ROCProfiler API
add_library(${ROCPROFILER_TARGET} SHARED
${ROCPROFILER_SRC_FILES}
${ROCMTOOL_CLASS_SRC_FILES}
${ROCPROFILER_PROFILER_SRC_FILES}
${CORE_HARDWARE_SRC_FILES}
${CORE_HSA_SRC_FILES}
${ROCPROFILER_SPM_SRC_FILES}
${CORE_MEMORY_SRC_FILES}
${CORE_SESSION_SRC_FILES}
${CORE_FILTER_SRC_FILES}
${CORE_DEVICE_PROFILING_SRC_FILES}
${CORE_COUNTERS_PARENT_SRC_FILES}
${CORE_COUNTERS_METRICS_SRC_FILES}
${CORE_UTILS_SRC_FILES}
${CORE_HSA_PACKETS_SRC_FILES}
${CORE_HSA_QUEUES_SRC_FILES}
${ROCPROFILER_TRACER_SRC_FILES}
${ROCPROFILER_ROCTRACER_SRC_FILES}
${GENERATED_SOURCES}
${CORE_COUNTERS_SRC_FILES}
${CORE_PC_SAMPLING_FILES}
${OLD_LIB_SRC})
set_target_properties(${ROCPROFILER_TARGET} PROPERTIES
CXX_VISIBILITY_PRESET hidden
DEFINE_SYMBOL "ROCPROFILER_EXPORTS"
LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/exportmap
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR})
target_compile_definitions(${ROCPROFILER_TARGET}
PUBLIC AMD_INTERNAL_BUILD
PRIVATE PROF_API_IMPL HIP_PROF_HIP_API_STRING=1 __HIP_PLATFORM_AMD__=1)
target_include_directories(${ROCPROFILER_TARGET}
PUBLIC
${ROCM_PATH}/include
${HIP_INCLUDE_DIRECTORIES} ${HSA_RUNTIME_INCLUDE_DIRECTORIES}
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/tools>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/inc>
PRIVATE
${LIB_DIR} ${ROOT_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/tools
${PROJECT_SOURCE_DIR}/inc)
if(ASAN)
target_compile_options(${ROCPROFILER_TARGET} PRIVATE -fsanitize=address)
target_link_options(${ROCPROFILER_TARGET} PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exportmap -Wl,--no-undefined,-fsanitize=address)
target_link_libraries(${ROCPROFILER_TARGET} PRIVATE ${AQLPROFILE_LIB} hsa-runtime64::hsa-runtime64 Threads::Threads atomic asan dl c stdc++ stdc++fs amd_comgr ${PCIACCESS_LIBRARIES})
else()
target_link_options(${ROCPROFILER_TARGET} PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exportmap -Wl,--no-undefined)
target_link_libraries(${ROCPROFILER_TARGET} PRIVATE ${AQLPROFILE_LIB} hsa-runtime64::hsa-runtime64 Threads::Threads atomic dl c stdc++ stdc++fs amd_comgr ${PCIACCESS_LIBRARIES})
endif()
## Install libraries: Non versioned lib file in dev package
install ( TARGETS ${ROCPROFILER_TARGET} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dev NAMELINK_ONLY )
install ( TARGETS ${ROCPROFILER_TARGET} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime NAMELINK_SKIP )
configure_file(${PROJECT_SOURCE_DIR}/src/core/counters/metrics/basic_counters.xml ${PROJECT_BINARY_DIR}/counters/basic_counters.xml COPYONLY)
configure_file(${PROJECT_SOURCE_DIR}/src/core/counters/metrics/derived_counters.xml ${PROJECT_BINARY_DIR}/counters/derived_counters.xml COPYONLY)
install(DIRECTORY
${PROJECT_BINARY_DIR}/counters
DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/${PROJECT_NAME}
USE_SOURCE_PERMISSIONS
COMPONENT runtime)
# ############################################################################################################################################
@@ -0,0 +1,88 @@
ROCPROFILER_1.0 {
global: OnLoad;
OnUnload;
rocprofiler_version_major;
rocprofiler_version_minor;
rocprofiler_error_string;
rocprofiler_open;
rocprofiler_add_feature;
rocprofiler_features_set_open;
rocprofiler_close;
rocprofiler_reset;
rocprofiler_get_agent;
rocprofiler_get_time;
rocprofiler_set_queue_callbacks;
rocprofiler_remove_queue_callbacks;
rocprofiler_start_queue_callbacks;
rocprofiler_stop_queue_callbacks;
rocprofiler_start;
rocprofiler_stop;
rocprofiler_read;
rocprofiler_get_data;
rocprofiler_group_count;
rocprofiler_get_group;
rocprofiler_group_start;
rocprofiler_group_stop;
rocprofiler_group_read;
rocprofiler_group_get_data;
rocprofiler_get_metrics;
rocprofiler_iterate_trace_data;
rocprofiler_get_info;
rocprofiler_iterate_info;
rocprofiler_query_info;
rocprofiler_queue_create_profiled;
rocprofiler_pool_open;
rocprofiler_pool_close;
rocprofiler_pool_fetch;
rocprofiler_pool_release;
rocprofiler_pool_iterate;
rocprofiler_pool_flush;
rocprofiler_set_hsa_callbacks;
local: *;
};
ROCPROFILER_2.0 {
global: HSA_AMD_TOOL_PRIORITY;
rocprofiler_error_str;
rocprofiler_initialize;
rocprofiler_finalize;
rocprofiler_get_timestamp;
rocprofiler_iterate_counters;
rocprofiler_query_agent_info_size;
rocprofiler_query_agent_info;
rocprofiler_query_queue_info_size;
rocprofiler_query_queue_info;
rocprofiler_query_kernel_info_size;
rocprofiler_query_kernel_info;
rocprofiler_query_counter_info_size;
rocprofiler_query_counter_info;
rocprofiler_query_roctx_tracer_api_data_info_size;
rocprofiler_query_roctx_tracer_api_data_info;
rocprofiler_query_hsa_tracer_api_data_info_size;
rocprofiler_query_hsa_tracer_api_data_info;
rocprofiler_query_hip_tracer_api_data_info_size;
rocprofiler_query_hip_tracer_api_data_info;
rocprofiler_flush_data;
rocprofiler_next_record;
rocprofiler_create_session;
rocprofiler_create_ready_session;
rocprofiler_create_filter;
rocprofiler_create_buffer;
rocprofiler_destroy_session;
rocprofiler_destroy_filter;
rocprofiler_destroy_buffer;
rocprofiler_set_filter_buffer;
rocprofiler_set_api_trace_sync_callback;
rocprofiler_set_buffer_properties;
rocprofiler_start_session;
rocprofiler_terminate_session;
rocprofiler_push_range;
rocprofiler_pop_range;
rocprofiler_start_replay_pass;
rocprofiler_end_replay_pass;
rocprofiler_device_profiling_session_create;
rocprofiler_device_profiling_session_start;
rocprofiler_device_profiling_session_poll;
rocprofiler_device_profiling_session_stop;
rocprofiler_device_profiling_session_destroy;
} ROCPROFILER_1.0;
@@ -0,0 +1,242 @@
/* Copyright (c) 2022 Advanced Micro Devices, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. */
#include "rocmtool.h"
#include <sys/syscall.h>
#include <unistd.h>
#include <atomic>
#include <optional>
#include <thread>
#include "src/core/hardware/hsa_info.h"
#include "src/core/hsa/hsa_support.h"
#include "src/core/hsa/queues/queue.h"
#include "src/utils/helper.h"
#include "src/utils/logger.h"
#include "src/core/memory/generic_buffer.h"
#define ASSERTM(exp, msg) assert(((void)msg, exp))
extern std::mutex sessions_pending_signal_lock;
static inline uint32_t GetTid() { return syscall(__NR_gettid); }
namespace rocmtools {
rocmtool* rocmtool_obj;
// Constructor of rocmtool
// Takes the buffer size, a buffer callback function and a buffer flush
// interval to allocate a buffer pool using GenericStorage Also takes the
// replay mode (application replay/kernel replay/user replay) to set the replay
// mode for the rocmtool class object
rocmtool::rocmtool() : current_session_id_(rocprofiler_session_id_t{0}) {}
// Destructor of rocmtool
// deletes the buffer pool
// Iterates over its session map and resets each session in its internal
// session map and clears them from the map. Pops labels from the range stack
// and deletes the stack.
rocmtool::~rocmtool() {
// {
// std::lock_guard<std::mutex> lock(session_map_lock_);
// if (!sessions_.empty()) {
// // TODO(aelwazir): throw an exception user need to destroy all created
// // session (document)
// // fatal("Error: Sessions are not destroyed yet!");
// sessions_.clear();
// }
// }
Counter::ClearBasicCounters();
}
bool rocmtool::FindAgent(rocprofiler_agent_id_t agent_id) { return true; }
size_t rocmtool::GetAgentInfoSize(rocprofiler_agent_info_kind_t kind, rocprofiler_agent_id_t agent_id) {
return 0;
}
const char* rocmtool::GetAgentInfo(rocprofiler_agent_info_kind_t kind,
rocprofiler_agent_id_t agent_id) {
return "";
}
// TODO(aelwazir): Implement Queue Query
bool rocmtool::FindQueue(rocprofiler_queue_id_t queue_id) { return true; }
size_t rocmtool::GetQueueInfoSize(rocprofiler_queue_info_kind_t kind, rocprofiler_queue_id_t queue_id) {
return 0;
}
const char* rocmtool::GetQueueInfo(rocprofiler_queue_info_kind_t kind,
rocprofiler_queue_id_t queue_id) {
return "";
}
bool rocmtool::FindSession(rocprofiler_session_id_t session_id) {
std::lock_guard<std::mutex> lock(session_map_lock_);
return sessions_.find(session_id.handle) != sessions_.end();
}
rocprofiler_session_id_t rocmtool::CreateSession(rocprofiler_replay_mode_t replay_mode) {
rocprofiler_session_id_t session_id = rocprofiler_session_id_t{GenerateUniqueSessionId()};
{
std::lock_guard<std::mutex> lock(session_map_lock_);
sessions_.emplace(session_id.handle, new Session(replay_mode, session_id));
}
return session_id;
}
void rocmtool::DestroySession(rocprofiler_session_id_t session_id) {
while (GetCurrentActiveInterruptSignalsCount() != 0) {
}
// if (GetSession(session_id)->GetTracer()) {
// GetSession(session_id)->GetTracer().reset();
// GetSession(session_id)
// ->GetBuffer(
// GetSession(session_id)
// ->GetFilter(GetSession(session_id)->GetFilterIdWithKind(ROCPROFILER_API_TRACE))
// .GetBufferId())
// .reset();
// }
{
std::lock_guard<std::mutex> lock(session_map_lock_);
ASSERTM(sessions_.find(session_id.handle) != sessions_.end(),
"Error: Couldn't find a created session with given id");
delete sessions_.at(session_id.handle);
sessions_.erase(session_id.handle);
}
}
bool rocmtool::FindDeviceProfilingSession(rocprofiler_session_id_t session_id) {
std::lock_guard<std::mutex> lock(device_profiling_session_map_lock_);
return dev_profiling_sessions_.find(session_id.handle) != dev_profiling_sessions_.end();
}
rocprofiler_session_id_t rocmtool::CreateDeviceProfilingSession(std::vector<std::string> counters,
int cpu_agent_index,
int gpu_agent_index) {
rocprofiler_session_id_t session_id;
{
std::lock_guard<std::mutex> lock(device_profiling_session_map_lock_);
hsa_agent_t cpu_agent;
hsa_agent_t gpu_agent;
find_hsa_agent_cpu(cpu_agent_index, &cpu_agent);
find_hsa_agent_gpu(gpu_agent_index, &gpu_agent);
dev_profiling_sessions_.emplace(
session_id.handle,
new DeviceProfileSession(counters, cpu_agent, gpu_agent, &session_id.handle));
}
return session_id;
}
void rocmtool::DestroyDeviceProfilingSession(rocprofiler_session_id_t session_id) {
{
std::lock_guard<std::mutex> lock(device_profiling_session_map_lock_);
ASSERTM(dev_profiling_sessions_.find(session_id.handle) != dev_profiling_sessions_.end(),
"Error: Couldn't find a created session with given id");
delete dev_profiling_sessions_.at(session_id.handle);
dev_profiling_sessions_.erase(session_id.handle);
}
}
DeviceProfileSession* rocmtool::GetDeviceProfilingSession(rocprofiler_session_id_t session_id) {
std::lock_guard<std::mutex> lock(device_profiling_session_map_lock_);
assert(dev_profiling_sessions_.find(session_id.handle) != dev_profiling_sessions_.end() &&
"Error: Can't find the session!");
return dev_profiling_sessions_.at(session_id.handle);
}
bool rocmtool::HasActiveSession() { return GetCurrentSessionId().handle > 0; }
bool rocmtool::IsActiveSession(rocprofiler_session_id_t session_id) {
return (GetCurrentSessionId().handle == session_id.handle);
}
// Get the session by its id
// Looks up the session object for an input session id in the internal map.
// If a given session id doesn't exist, it throws an assertion.
// If a session object exists for the given session id, the session object is
// returned.
Session* rocmtool::GetSession(rocprofiler_session_id_t session_id) {
std::lock_guard<std::mutex> lock(session_map_lock_);
assert(sessions_.find(session_id.handle) != sessions_.end() && "Error: Can't find the session!");
return sessions_.at(session_id.handle);
}
// Get Current Session ID
rocprofiler_session_id_t rocmtool::GetCurrentSessionId() { return current_session_id_; }
void rocmtool::SetCurrentActiveSession(rocprofiler_session_id_t session_id) {
current_session_id_ = session_id;
}
uint64_t rocmtool::GetUniqueRecordId() { return records_counter_.fetch_add(1); }
uint64_t rocmtool::GetUniqueKernelDispatchId() {
return kernel_dispatch_counter_.fetch_add(1, std::memory_order_relaxed);
}
size_t rocmtool::GetKernelInfoSize(rocprofiler_kernel_info_kind_t kind,
rocprofiler_kernel_id_t kernel_id) {
switch (kind) {
case ROCPROFILER_KERNEL_NAME:
return GetKernelNameFromKsymbols(kernel_id.handle).size();
default:
warning("The provided Kernel Kind is not yet supported!");
return 0;
}
}
const char* rocmtool::GetKernelInfo(rocprofiler_kernel_info_kind_t kind,
rocprofiler_kernel_id_t kernel_id) {
switch (kind) {
case ROCPROFILER_KERNEL_NAME:
return strdup(GetKernelNameFromKsymbols(kernel_id.handle).c_str());
default:
warning("The provided Kernel Kind is not yet supported!");
return "";
}
}
// TODO(aelwazir): To be implemented
bool rocmtool::CheckFilterData(rocprofiler_filter_kind_t filter_kind,
rocprofiler_filter_data_t filter_data) {
return true;
}
// End of ROCMTool Class
rocmtool* GetROCMToolObj() { return rocmtool_obj; }
void InitROCMToolObj() { rocmtool_obj = new rocmtool; }
void ResetROCMToolObj() {
delete rocmtool_obj;
// if (rocmtool_obj) rocmtool_obj.reset();
}
rocprofiler_timestamp_t GetCurrentTimestamp() { return hsa_support::GetCurrentTimestampNS(); }
rocprofiler_status_t IterateCounters(rocprofiler_counters_info_callback_t counters_info_callback) {
if (hsa_support::IterateCounters(counters_info_callback)) return ROCPROFILER_STATUS_SUCCESS;
return ROCPROFILER_STATUS_ERROR;
}
} // namespace rocmtools
@@ -0,0 +1,122 @@
/* Copyright (c) 2022 Advanced Micro Devices, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. */
#ifndef SRC_TOOLS_ROCMTOOL_H_
#define SRC_TOOLS_ROCMTOOL_H_
#include <hsa/hsa_ven_amd_aqlprofile.h>
#include <atomic>
#include <chrono>
#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <mutex>
#include <optional>
#include <stack>
#include <string>
#include <thread>
#include <unordered_map>
#include <utility>
#include <vector>
#include "src/core/session/session.h"
#include "src/core/session/device_profiling.h"
namespace rocmtools {
class rocmtool {
public:
rocmtool();
~rocmtool();
bool FindAgent(rocprofiler_agent_id_t agent_id);
size_t GetAgentInfoSize(rocprofiler_agent_info_kind_t kind, rocprofiler_agent_id_t agent_id);
const char* GetAgentInfo(rocprofiler_agent_info_kind_t kind, rocprofiler_agent_id_t agent_id);
bool FindQueue(rocprofiler_queue_id_t queue_id);
size_t GetQueueInfoSize(rocprofiler_queue_info_kind_t kind, rocprofiler_queue_id_t queue_id);
const char* GetQueueInfo(rocprofiler_queue_info_kind_t kind, rocprofiler_queue_id_t queue_id);
bool FindKernel(rocprofiler_kernel_id_t kernel_id);
size_t GetKernelInfoSize(rocprofiler_kernel_info_kind_t kind, rocprofiler_kernel_id_t kernel_id);
const char* GetKernelInfo(rocprofiler_kernel_info_kind_t kind, rocprofiler_kernel_id_t kernel_id);
// Session
rocprofiler_session_id_t CreateSession(rocprofiler_replay_mode_t replay_mode);
void DestroySession(rocprofiler_session_id_t session_id);
bool HasActiveSession();
rocprofiler_session_id_t GetCurrentSessionId();
void SetCurrentActiveSession(rocprofiler_session_id_t session_id);
bool FindSession(rocprofiler_session_id_t session_id);
bool IsActiveSession(rocprofiler_session_id_t session_id);
Session* GetSession(rocprofiler_session_id_t session_id);
// Device Profiling Session
bool FindDeviceProfilingSession(rocprofiler_session_id_t session_id);
rocprofiler_session_id_t CreateDeviceProfilingSession(std::vector<std::string> counters,
int cpu_agent_index, int gpu_agent_index);
void DestroyDeviceProfilingSession(rocprofiler_session_id_t session_id);
DeviceProfileSession* GetDeviceProfilingSession(rocprofiler_session_id_t session_id);
// Generic
bool CheckFilterData(rocprofiler_filter_kind_t filter_kind, rocprofiler_filter_data_t filter_data);
uint64_t GetUniqueRecordId();
uint64_t GetUniqueKernelDispatchId();
private:
rocprofiler_session_id_t current_session_id_{0};
std::mutex session_map_lock_;
std::map<uint64_t, Session*> sessions_;
std::atomic<uint64_t> records_counter_{1};
std::mutex device_profiling_session_map_lock_;
std::map<uint64_t, DeviceProfileSession*> dev_profiling_sessions_;
/*
* XXX: Associating PC samples with a running kernel requires an identifier
* that will be unique across all kernel executions. It is not enough to use
* the name of a kernel or the address of a kernel object, as these will be
* identical if the same kernel is dispatched twice. Currently, this
* identifier is written to the `reserved2` field of the dispatch packet when
* its launch is intercepted, but this could change: a future version of
* ROCmtools may instead attempt to identify a kernel by a key with high
* _probability_ of uniqueness: for example, a combination of the kernel's
* name, the queue ID to which it was dispatched, and the offset of the queue
* write pointer is likely sufficient to associate PC samples with a running
* kernel and have the PC sample records consumed by the user-provided async
* callback before the write pointer wraps to the same position in the ring
* buffer.
*/
std::atomic<uint64_t> kernel_dispatch_counter_{1};
};
void InitROCMToolObj();
void ResetROCMToolObj();
rocmtool* GetROCMToolObj();
rocprofiler_timestamp_t GetCurrentTimestamp();
rocprofiler_status_t IterateCounters(rocprofiler_counters_info_callback_t counters_info_callback);
} // namespace rocmtools
#endif // SRC_TOOLS_ROCMTOOL_H_
@@ -0,0 +1,755 @@
#include <atomic>
#include "src/core/hsa/hsa_support.h"
#include "src/api/rocmtool.h"
#include "src/utils/helper.h"
#include "rocprofiler.h"
// TODO(aelwazir): change that to adapt with our own Exception
// What about outside exceptions and callbacks exceptions!!
#define API_METHOD_PREFIX \
rocprofiler_status_t err = ROCPROFILER_STATUS_SUCCESS; \
try {
#define API_METHOD_SUFFIX \
} \
catch (rocmtools::Exception & e) { \
std::cout << __FUNCTION__ << "(), " << e.what(); \
} \
return err;
#define API_INIT_CHECKER \
API_METHOD_PREFIX \
if (!api_started.load(std::memory_order_relaxed)) \
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_NOT_INITIALIZED);
std::atomic<bool> api_started{false};
// Returns library version
ROCPROFILER_API uint32_t rocprofiler_version_major() { return ROCPROFILER_VERSION_MAJOR; }
ROCPROFILER_API uint32_t rocprofiler_version_minor() { return ROCPROFILER_VERSION_MINOR; }
// Return the error string representing the status
ROCPROFILER_API const char* rocprofiler_error_str(rocprofiler_status_t status) {
switch (status) {
case ROCPROFILER_STATUS_ERROR_ALREADY_INITIALIZED:
return "ROCMTool is already initialized\n";
case ROCPROFILER_STATUS_ERROR_NOT_INITIALIZED:
return "ROCMTool is not initialized or already destroyed\n";
case ROCPROFILER_STATUS_ERROR_SESSION_MISSING_BUFFER:
return "Missing Buffer for a session\n";
case ROCPROFILER_STATUS_ERROR_TIMESTAMP_NOT_APPLICABLE:
return "Timestamps can't be collected\n";
case ROCPROFILER_STATUS_ERROR_AGENT_NOT_FOUND:
return "Agent is not found with given identifier\n";
case ROCPROFILER_STATUS_ERROR_AGENT_INFORMATION_MISSING:
return "Agent information is missing for the given identifier\n";
case ROCPROFILER_STATUS_ERROR_QUEUE_NOT_FOUND:
return "Queue is not found for the given identifier\n";
case ROCPROFILER_STATUS_ERROR_QUEUE_INFORMATION_MISSING:
return "The requested information about the queue is not found\n";
case ROCPROFILER_STATUS_ERROR_KERNEL_NOT_FOUND:
return "Kernel is not found with given identifier\n";
case ROCPROFILER_STATUS_ERROR_KERNEL_INFORMATION_MISSING:
return "The requested information about the kernel is not found\n";
case ROCPROFILER_STATUS_ERROR_COUNTER_NOT_FOUND:
return "Counter is not found with the given identifier\n";
case ROCPROFILER_STATUS_ERROR_COUNTER_INFORMATION_MISSING:
return "The requested Counter information for the given kernel is "
"missing\n";
case ROCPROFILER_STATUS_ERROR_TRACER_API_DATA_NOT_FOUND:
return "The requested Tracing API Data for the given data identifier is "
"missing\n";
case ROCPROFILER_STATUS_ERROR_TRACER_API_DATA_INFORMATION_MISSING:
return "The requested information for the tracing API Data is missing\n";
case ROCPROFILER_STATUS_ERROR_INCORRECT_DOMAIN:
return "The given Domain is incorrect\n";
case ROCPROFILER_STATUS_ERROR_SESSION_NOT_FOUND:
return "The requested Session given the session identifier is not "
"found\n";
case ROCPROFILER_STATUS_ERROR_CORRUPTED_SESSION_BUFFER:
return "The requested Session Buffer given the session identifier is "
"corrupted or deleted\n";
case ROCPROFILER_STATUS_ERROR_RECORD_CORRUPTED:
return "The requested record given the record identifier is corrupted "
"or deleted\n";
case ROCPROFILER_STATUS_ERROR_INCORRECT_REPLAY_MODE:
return "Incorrect Replay mode\n";
case ROCPROFILER_STATUS_ERROR_SESSION_MISSING_FILTER:
return "Missing Filter for a session\n";
case ROCPROFILER_STATUS_ERROR_INCORRECT_SIZE:
return "The size given for the buffer is not applicable\n";
case ROCPROFILER_STATUS_ERROR_INCORRECT_FLUSH_INTERVAL:
return "Incorrect Flush interval\n";
case ROCPROFILER_STATUS_ERROR_SESSION_FILTER_DATA_MISMATCH:
return "The session filter can't accept the given data\n";
case ROCPROFILER_STATUS_ERROR_FILTER_DATA_CORRUPTED:
return "The given filter data is corrupted\n";
case ROCPROFILER_STATUS_ERROR_CORRUPTED_LABEL_DATA:
return "The given label is corrupted\n";
case ROCPROFILER_STATUS_ERROR_RANGE_STACK_IS_EMPTY:
return "There is no label in the labels stack to be popped\n";
case ROCPROFILER_STATUS_ERROR_PASS_NOT_STARTED:
return "There is no pass that started\n";
case ROCPROFILER_STATUS_ERROR_HAS_ACTIVE_SESSION:
return "There is already Active session, Can't activate two session at "
"the same time\n";
case ROCPROFILER_STATUS_ERROR_SESSION_NOT_ACTIVE:
return "Can't terminate a non active session\n";
case ROCPROFILER_STATUS_ERROR_FILTER_NOT_FOUND:
return "The required filter is not found for the given session\n";
case ROCPROFILER_STATUS_ERROR_BUFFER_NOT_FOUND:
return "The required buffer is not found for the given session\n";
case ROCPROFILER_STATUS_ERROR_FILTER_NOT_SUPPORTED:
return "The required filter is not supported\n";
default:
return "Unkown error has occurred\n";
}
return "\n";
}
// Initialize the API
ROCPROFILER_API rocprofiler_status_t rocprofiler_initialize() {
API_METHOD_PREFIX
if (api_started.load(std::memory_order_relaxed))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_ALREADY_INITIALIZED);
rocmtools::InitROCMToolObj();
api_started.exchange(true, std::memory_order_release);
API_METHOD_SUFFIX
}
// Finalize the API
ROCPROFILER_API rocprofiler_status_t rocprofiler_finalize() {
API_INIT_CHECKER
rocmtools::ResetROCMToolObj();
api_started.exchange(false, std::memory_order_release);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_get_timestamp(rocprofiler_timestamp_t* timestamp) {
API_INIT_CHECKER
*timestamp = rocmtools::GetCurrentTimestamp();
if (timestamp->value <= 0)
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_TIMESTAMP_NOT_APPLICABLE);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t
rocprofiler_iterate_counters(rocprofiler_counters_info_callback_t counters_info_callback) {
API_INIT_CHECKER
return rocmtools::IterateCounters(counters_info_callback);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_query_agent_info_size(rocprofiler_agent_info_kind_t kind,
rocprofiler_agent_id_t agent_id,
size_t* data_size) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->FindAgent(agent_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_AGENT_NOT_FOUND);
*data_size = rocmtools::GetROCMToolObj()->GetAgentInfoSize(kind, agent_id);
if (*data_size <= 0) throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_AGENT_INFORMATION_MISSING);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_query_agent_info(rocprofiler_agent_info_kind_t kind,
rocprofiler_agent_id_t agent_id,
const char** data) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->FindAgent(agent_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_AGENT_NOT_FOUND);
if (!(*data = rocmtools::GetROCMToolObj()->GetAgentInfo(kind, agent_id)))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_AGENT_INFORMATION_MISSING);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_query_queue_info_size(rocprofiler_queue_info_kind_t kind,
rocprofiler_queue_id_t queue_id,
size_t* data_size) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->FindQueue(queue_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_QUEUE_NOT_FOUND);
*data_size = rocmtools::GetROCMToolObj()->GetQueueInfoSize(kind, queue_id);
if (*data_size <= 0) throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_QUEUE_INFORMATION_MISSING);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_query_queue_info(rocprofiler_queue_info_kind_t kind,
rocprofiler_queue_id_t queue_id,
const char** data) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->FindQueue(queue_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_QUEUE_NOT_FOUND);
if (!(*data = rocmtools::GetROCMToolObj()->GetQueueInfo(kind, queue_id)))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_QUEUE_INFORMATION_MISSING);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_query_kernel_info_size(rocprofiler_kernel_info_kind_t kind,
rocprofiler_kernel_id_t kernel_id,
size_t* data_size) {
API_INIT_CHECKER
// if (!rocmtools::GetROCMToolObj()->FindKernel(kernel_id))
// throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_KERNEL_NOT_FOUND);
*data_size = rocmtools::GetROCMToolObj()->GetKernelInfoSize(kind, kernel_id);
if (*data_size <= 0)
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_KERNEL_INFORMATION_MISSING);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_query_kernel_info(rocprofiler_kernel_info_kind_t kind,
rocprofiler_kernel_id_t kernel_id,
const char** data) {
API_INIT_CHECKER
// if (!rocmtools::GetROCMToolObj()->FindKernel(kernel_id))
// throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_KERNEL_NOT_FOUND);
if (!(*data = rocmtools::GetROCMToolObj()->GetKernelInfo(kind, kernel_id)))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_KERNEL_INFORMATION_MISSING);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_query_counter_info_size(
rocprofiler_session_id_t session_id, rocprofiler_counter_info_kind_t kind,
rocprofiler_counter_id_t counter_id, size_t* data_size) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->GetSession(session_id)->GetProfiler()->FindCounter(counter_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_COUNTER_NOT_FOUND);
*data_size = rocmtools::GetROCMToolObj()
->GetSession(session_id)
->GetProfiler()
->GetCounterInfoSize(kind, counter_id);
if (*data_size <= 0)
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_COUNTER_INFORMATION_MISSING);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_query_counter_info(rocprofiler_session_id_t session_id,
rocprofiler_counter_info_kind_t kind,
rocprofiler_counter_id_t counter_id,
const char** data) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->GetSession(session_id)->GetProfiler()->FindCounter(counter_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_COUNTER_NOT_FOUND);
if (!(*data = rocmtools::GetROCMToolObj()
->GetSession(session_id)
->GetProfiler()
->GetCounterInfo(kind, counter_id)))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_COUNTER_INFORMATION_MISSING);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_query_roctx_tracer_api_data_info_size(
rocprofiler_session_id_t session_id, rocprofiler_tracer_roctx_api_data_info_t kind,
rocprofiler_tracer_api_data_handle_t api_data_id, rocprofiler_tracer_operation_id_t operation_id,
size_t* data_size) {
API_INIT_CHECKER
// TODO(aelwazir): To be implemented
// if (!rocmtools::GetROCMToolObj()
// ->GetSession(session_id)
// ->GetTracer()
// ->FindROCTxApiData(api_data_id)) {
// if (rocmtools::GetROCMToolObj()
// ->GetSession(session_id)
// ->GetTracer()
// ->FindHSAApiData(api_data_id) ||
// rocmtools::GetROCMToolObj()
// ->GetSession(session_id)
// ->GetTracer()
// ->FindHIPApiData(api_data_id)) {
// throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_INCORRECT_DOMAIN);
// } else {
// throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_TRACER_API_DATA_NOT_FOUND);
// }
// }
*data_size = rocmtools::GetROCMToolObj()
->GetSession(session_id)
->GetTracer()
->GetROCTxApiDataInfoSize(kind, api_data_id, operation_id);
// if (*data_size <= 0)
// throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_TRACER_API_DATA_INFORMATION_MISSING);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_query_roctx_tracer_api_data_info(
rocprofiler_session_id_t session_id, rocprofiler_tracer_roctx_api_data_info_t kind,
rocprofiler_tracer_api_data_handle_t api_data_id, rocprofiler_tracer_operation_id_t operation_id,
char** data) {
API_INIT_CHECKER
// TODO(aelwazir): To be implemented
// if (!rocmtools::GetROCMToolObj()
// ->GetSession(session_id)
// ->GetTracer()
// ->FindROCTxApiData(api_data_id)) {
// if (rocmtools::GetROCMToolObj()
// ->GetSession(session_id)
// ->GetTracer()
// ->FindHSAApiData(api_data_id) ||
// rocmtools::GetROCMToolObj()
// ->GetSession(session_id)
// ->GetTracer()
// ->FindHIPApiData(api_data_id)) {
// throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_INCORRECT_DOMAIN);
// } else {
// throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_TRACER_API_DATA_NOT_FOUND);
// }
// }
if (!(*data = rocmtools::GetROCMToolObj()
->GetSession(session_id)
->GetTracer()
->GetROCTxApiDataInfo(kind, api_data_id, operation_id)))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_TRACER_API_DATA_INFORMATION_MISSING);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_query_hsa_tracer_api_data_info_size(
rocprofiler_session_id_t session_id, rocprofiler_tracer_hsa_api_data_info_t kind,
rocprofiler_tracer_api_data_handle_t api_data_id, rocprofiler_tracer_operation_id_t operation_id,
size_t* data_size) {
API_INIT_CHECKER
// TODO(aelwazir): To be implemented
// if (!rocmtools::GetROCMToolObj()
// ->GetSession(session_id)
// ->GetTracer()
// ->FindHSAApiData(api_data_id)) {
// if (rocmtools::GetROCMToolObj()
// ->GetSession(session_id)
// ->GetTracer()
// ->FindROCTxApiData(api_data_id) ||
// rocmtools::GetROCMToolObj()
// ->GetSession(session_id)
// ->GetTracer()
// ->FindHIPApiData(api_data_id)) {
// throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_INCORRECT_DOMAIN);
// } else {
// throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_TRACER_API_DATA_NOT_FOUND);
// }
// }
*data_size = rocmtools::GetROCMToolObj()
->GetSession(session_id)
->GetTracer()
->GetHSAApiDataInfoSize(kind, api_data_id, operation_id);
if (*data_size <= 0)
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_TRACER_API_DATA_INFORMATION_MISSING);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_query_hsa_tracer_api_data_info(
rocprofiler_session_id_t session_id, rocprofiler_tracer_hsa_api_data_info_t kind,
rocprofiler_tracer_api_data_handle_t api_data_id, rocprofiler_tracer_operation_id_t operation_id,
char** data) {
API_INIT_CHECKER
// TODO(aelwazir): To be implemented
// if (!rocmtools::GetROCMToolObj()
// ->GetSession(session_id)
// ->GetTracer()
// ->FindHSAApiData(api_data_id)) {
// if (rocmtools::GetROCMToolObj()
// ->GetSession(session_id)
// ->GetTracer()
// ->FindROCTxApiData(api_data_id) ||
// rocmtools::GetROCMToolObj()
// ->GetSession(session_id)
// ->GetTracer()
// ->FindHIPApiData(api_data_id)) {
// throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_INCORRECT_DOMAIN);
// } else {
// throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_TRACER_API_DATA_NOT_FOUND);
// }
// }
if (!(*data = rocmtools::GetROCMToolObj()
->GetSession(session_id)
->GetTracer()
->GetHSAApiDataInfo(kind, api_data_id, operation_id)))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_TRACER_API_DATA_INFORMATION_MISSING);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_query_hip_tracer_api_data_info_size(
rocprofiler_session_id_t session_id, rocprofiler_tracer_hip_api_data_info_t kind,
rocprofiler_tracer_api_data_handle_t api_data_id, rocprofiler_tracer_operation_id_t operation_id,
size_t* data_size) {
API_INIT_CHECKER
// TODO(aelwazir): To be implemented
// if (!rocmtools::GetROCMToolObj()
// ->GetSession(session_id)
// ->GetTracer()
// ->FindHIPApiData(api_data_id)) {
// if (rocmtools::GetROCMToolObj()
// ->GetSession(session_id)
// ->GetTracer()
// ->FindHSAApiData(api_data_id) ||
// rocmtools::GetROCMToolObj()
// ->GetSession(session_id)
// ->GetTracer()
// ->FindROCTxApiData(api_data_id)) {
// throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_INCORRECT_DOMAIN);
// } else {
// throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_TRACER_API_DATA_NOT_FOUND);
// }
// }
*data_size = rocmtools::GetROCMToolObj()
->GetSession(session_id)
->GetTracer()
->GetHIPApiDataInfoSize(kind, api_data_id, operation_id);
// if (*data_size <= 0)
// throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_TRACER_API_DATA_INFORMATION_MISSING);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_query_hip_tracer_api_data_info(
rocprofiler_session_id_t session_id, rocprofiler_tracer_hip_api_data_info_t kind,
rocprofiler_tracer_api_data_handle_t api_data_id, rocprofiler_tracer_operation_id_t operation_id,
char** data) {
API_INIT_CHECKER
// TODO(aelwazir): To be implemented
// if (!rocmtools::GetROCMToolObj()
// ->GetSession(session_id)
// ->GetTracer()
// ->FindHIPApiData(api_data_id)) {
// if (rocmtools::GetROCMToolObj()
// ->GetSession(session_id)
// ->GetTracer()
// ->FindHSAApiData(api_data_id) ||
// rocmtools::GetROCMToolObj()
// ->GetSession(session_id)
// ->GetTracer()
// ->FindROCTxApiData(api_data_id)) {
// throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_INCORRECT_DOMAIN);
// } else {
// throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_TRACER_API_DATA_NOT_FOUND);
// }
// }
// if (!(
*data = rocmtools::GetROCMToolObj()
->GetSession(session_id)
->GetTracer()
->GetHIPApiDataInfo(kind, api_data_id, operation_id);
// ))
// throw
// rocmtools::Exception(ROCPROFILER_STATUS_ERROR_TRACER_API_DATA_INFORMATION_MISSING);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_flush_data(rocprofiler_session_id_t session_id,
rocprofiler_buffer_id_t buffer_id) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->FindSession(session_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_SESSION_NOT_FOUND);
if (!rocmtools::GetROCMToolObj()->GetSession(session_id)->FindBuffer(buffer_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_BUFFER_NOT_FOUND);
if (!rocmtools::GetROCMToolObj()->GetSession(session_id)->GetBuffer(buffer_id)->Flush())
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_CORRUPTED_SESSION_BUFFER);
API_METHOD_SUFFIX
}
#include "src/core/memory/generic_buffer.h"
ROCPROFILER_API rocprofiler_status_t rocprofiler_next_record(const rocprofiler_record_header_t* record,
const rocprofiler_record_header_t** next,
rocprofiler_session_id_t session_id,
rocprofiler_buffer_id_t buffer_id) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->FindSession(session_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_SESSION_NOT_FOUND);
if (!rocmtools::GetROCMToolObj()->GetSession(session_id)->FindBuffer(buffer_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_BUFFER_NOT_FOUND);
if (!Memory::GetNextRecord(record, next))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_RECORD_CORRUPTED);
API_METHOD_SUFFIX
}
// API to create a session with a given profiling mode and input data
ROCPROFILER_API rocprofiler_status_t rocprofiler_create_session(rocprofiler_replay_mode_t replay_mode,
rocprofiler_session_id_t* session_id) {
API_INIT_CHECKER
*session_id = rocmtools::GetROCMToolObj()->CreateSession(replay_mode);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_create_filter(rocprofiler_session_id_t session_id,
rocprofiler_filter_kind_t filter_kind,
rocprofiler_filter_data_t filter_data,
uint64_t data_count,
rocprofiler_filter_id_t* filter_id,
rocprofiler_filter_property_t property) {
API_INIT_CHECKER
// TODO(aelwazir): CheckFilterData to be implemented
// int error_code =
// rocmtools::GetROCMToolObj()->CheckFilterData(filter_kind,
// filter_data);
// if (error_code == -1) throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_FILTER_DATA_CORRUPTED);
// if (error_code == 0)
// throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_SESSION_FILTER_DATA_MISMATCH);
if (!rocmtools::GetROCMToolObj()->FindSession(session_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_SESSION_NOT_FOUND);
*filter_id = rocmtools::GetROCMToolObj()
->GetSession(session_id)
->CreateFilter(filter_kind, filter_data, data_count, property);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_destroy_filter(rocprofiler_session_id_t session_id,
rocprofiler_filter_id_t filter_id) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->FindSession(session_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_SESSION_NOT_FOUND);
if (!rocmtools::GetROCMToolObj()->GetSession(session_id)->FindFilter(filter_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_FILTER_NOT_FOUND);
rocmtools::GetROCMToolObj()->GetSession(session_id)->DestroyFilter(filter_id);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_create_buffer(
rocprofiler_session_id_t session_id, rocprofiler_buffer_callback_t buffer_callback,
size_t buffer_size, rocprofiler_buffer_id_t* buffer_id) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->FindSession(session_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_SESSION_NOT_FOUND);
*buffer_id = rocmtools::GetROCMToolObj()
->GetSession(session_id)
->CreateBuffer(buffer_callback, buffer_size);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_set_buffer_properties(
rocprofiler_session_id_t session_id, rocprofiler_buffer_id_t buffer_id,
rocprofiler_buffer_property_t* buffer_properties, uint32_t buffer_properties_count) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->FindSession(session_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_SESSION_NOT_FOUND);
if (!rocmtools::GetROCMToolObj()->GetSession(session_id)->FindBuffer(buffer_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_BUFFER_NOT_FOUND);
rocmtools::GetROCMToolObj()
->GetSession(session_id)
->GetBuffer(buffer_id)
->SetProperties(buffer_properties, buffer_properties_count);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_destroy_buffer(rocprofiler_session_id_t session_id,
rocprofiler_buffer_id_t buffer_id) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->FindSession(session_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_SESSION_NOT_FOUND);
if (!rocmtools::GetROCMToolObj()->GetSession(session_id)->FindBuffer(buffer_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_BUFFER_NOT_FOUND);
rocmtools::GetROCMToolObj()->GetSession(session_id)->DestroyBuffer(buffer_id);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_set_filter_buffer(rocprofiler_session_id_t session_id,
rocprofiler_filter_id_t filter_id,
rocprofiler_buffer_id_t buffer_id) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->FindSession(session_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_SESSION_NOT_FOUND);
if (!rocmtools::GetROCMToolObj()->GetSession(session_id)->FindBuffer(buffer_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_BUFFER_NOT_FOUND);
if (!rocmtools::GetROCMToolObj()->GetSession(session_id)->FindFilter(filter_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_FILTER_NOT_FOUND);
if (!rocmtools::GetROCMToolObj()
->GetSession(session_id)
->CheckFilterBufferSize(filter_id, buffer_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_INCORRECT_SIZE);
rocmtools::GetROCMToolObj()->GetSession(session_id)->GetFilter(filter_id)->SetBufferId(buffer_id);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_set_api_trace_sync_callback(
rocprofiler_session_id_t session_id, rocprofiler_filter_id_t filter_id,
rocprofiler_sync_callback_t callback) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->FindSession(session_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_SESSION_NOT_FOUND);
if (!rocmtools::GetROCMToolObj()->GetSession(session_id)->FindFilter(filter_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_FILTER_NOT_FOUND);
if (rocmtools::GetROCMToolObj()->GetSession(session_id)->GetFilter(filter_id)->GetKind() !=
ROCPROFILER_API_TRACE)
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_FILTER_NOT_SUPPORTED);
rocmtools::GetROCMToolObj()->GetSession(session_id)->GetFilter(filter_id)->SetCallback(callback);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_create_ready_session(
rocprofiler_replay_mode_t replay_mode, rocprofiler_filter_kind_t filter_kind,
rocprofiler_filter_data_t filter_data, uint64_t data_count, size_t buffer_size,
rocprofiler_buffer_callback_t buffer_callback, rocprofiler_session_id_t* session_id,
rocprofiler_filter_property_t property, rocprofiler_sync_callback_t callback) {
API_INIT_CHECKER
// TODO(aelwazir): CheckFilterData to be implemented
// int error_code =
// rocmtools::GetROCMToolObj()->CheckFilterData(filter_kind,
// filter_data);
// if (error_code == -1) throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_FILTER_DATA_CORRUPTED);
// if (error_code == 0)
// throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_SESSION_FILTER_DATA_MISMATCH);
*session_id = rocmtools::GetROCMToolObj()->CreateSession(replay_mode);
rocprofiler_filter_id_t filter_id =
rocmtools::GetROCMToolObj()
->GetSession(*session_id)
->CreateFilter(filter_kind, filter_data, data_count, property);
rocprofiler_buffer_id_t buffer_id = rocmtools::GetROCMToolObj()
->GetSession(*session_id)
->CreateBuffer(buffer_callback, buffer_size);
if (filter_kind == ROCPROFILER_API_TRACE)
rocmtools::GetROCMToolObj()
->GetSession(*session_id)
->GetFilter(filter_id)
->SetCallback(callback);
if (!rocmtools::GetROCMToolObj()
->GetSession(*session_id)
->CheckFilterBufferSize(filter_id, buffer_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_INCORRECT_SIZE);
rocmtools::GetROCMToolObj()
->GetSession(*session_id)
->GetFilter(filter_id)
->SetBufferId(buffer_id);
API_METHOD_SUFFIX
}
// API to destroy a session by id
ROCPROFILER_API rocprofiler_status_t rocprofiler_destroy_session(rocprofiler_session_id_t session_id) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->FindSession(session_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_SESSION_NOT_FOUND);
rocmtools::GetROCMToolObj()->DestroySession(session_id);
API_METHOD_SUFFIX
}
// API to activate a session by id
ROCPROFILER_API rocprofiler_status_t rocprofiler_start_session(rocprofiler_session_id_t session_id) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->FindSession(session_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_SESSION_NOT_FOUND);
if (!rocmtools::GetROCMToolObj()->GetSession(session_id)->HasFilter())
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_SESSION_MISSING_FILTER);
if (!rocmtools::GetROCMToolObj()->GetSession(session_id)->HasBuffer())
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_SESSION_MISSING_BUFFER);
if (rocmtools::GetROCMToolObj()->HasActiveSession())
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_HAS_ACTIVE_SESSION);
rocmtools::GetROCMToolObj()->GetSession(session_id)->Start();
rocmtools::GetROCMToolObj()->SetCurrentActiveSession(session_id);
API_METHOD_SUFFIX
}
// API to deactivate a session by id
ROCPROFILER_API rocprofiler_status_t rocprofiler_terminate_session(rocprofiler_session_id_t session_id) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->FindSession(session_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_SESSION_NOT_FOUND);
if (!rocmtools::GetROCMToolObj()->IsActiveSession(session_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_SESSION_NOT_ACTIVE);
rocmtools::GetROCMToolObj()->GetSession(session_id)->Terminate();
rocmtools::GetROCMToolObj()->SetCurrentActiveSession(rocprofiler_session_id_t{0});
API_METHOD_SUFFIX
}
// API to push a custom label for defining a code section
ROCPROFILER_API rocprofiler_status_t rocprofiler_push_range(rocprofiler_session_id_t session_id,
const char* label) {
API_INIT_CHECKER
if (!label) throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_CORRUPTED_LABEL_DATA);
rocmtools::GetROCMToolObj()->GetSession(session_id)->PushRangeLabels(label);
API_METHOD_SUFFIX
}
// API to pop a custom label defined for a code section
ROCPROFILER_API rocprofiler_status_t rocprofiler_pop_range(rocprofiler_session_id_t session_id) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->GetSession(session_id)->PopRangeLabels())
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_RANGE_STACK_IS_EMPTY);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_start_replay_pass(rocprofiler_session_id_t session_id) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->FindSession(session_id))
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_SESSION_NOT_FOUND);
rocmtools::GetROCMToolObj()->GetSession(session_id)->GetProfiler()->StartReplayPass(session_id);
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_end_replay_pass(rocprofiler_session_id_t session_id) {
API_INIT_CHECKER
if (!rocmtools::GetROCMToolObj()->GetSession(session_id)->GetProfiler()->HasActivePass())
throw rocmtools::Exception(ROCPROFILER_STATUS_ERROR_PASS_NOT_STARTED);
rocmtools::GetROCMToolObj()->GetSession(session_id)->GetProfiler()->EndReplayPass();
API_METHOD_SUFFIX
}
ROCPROFILER_API rocprofiler_status_t rocprofiler_device_profiling_session_create(
const char** counter_names, uint64_t num_counters, rocprofiler_session_id_t* session_id,
int cpu_index, int gpu_index) {
API_METHOD_PREFIX
std::vector<std::string> counters(counter_names, counter_names + num_counters);
*session_id =
rocmtools::GetROCMToolObj()->CreateDeviceProfilingSession(counters, cpu_index, gpu_index);
API_METHOD_SUFFIX
}
// API to start a device profiling session
ROCPROFILER_API rocprofiler_status_t
rocprofiler_device_profiling_session_start(rocprofiler_session_id_t session_id) {
API_METHOD_PREFIX
rocmtools::GetROCMToolObj()->GetDeviceProfilingSession(session_id)->StartSession();
API_METHOD_SUFFIX
}
// API to poll a device profiling session
ROCPROFILER_API rocprofiler_status_t rocprofiler_device_profiling_session_poll(
rocprofiler_session_id_t session_id, rocprofiler_device_profile_metric_t* data) {
API_METHOD_PREFIX
rocmtools::GetROCMToolObj()->GetDeviceProfilingSession(session_id)->PollMetrics(data);
API_METHOD_SUFFIX
}
// API to stop a device profiling session
ROCPROFILER_API rocprofiler_status_t
rocprofiler_device_profiling_session_stop(rocprofiler_session_id_t session_id) {
API_METHOD_PREFIX
rocmtools::GetROCMToolObj()->GetDeviceProfilingSession(session_id)->StopSession();
API_METHOD_SUFFIX
}
// API to destroy a device profiling session
ROCPROFILER_API rocprofiler_status_t
rocprofiler_device_profiling_session_destroy(rocprofiler_session_id_t session_id) {
API_METHOD_PREFIX
rocmtools::GetROCMToolObj()->DestroyDeviceProfilingSession(session_id);
API_METHOD_SUFFIX
}
// static bool started{false};
extern "C" {
// TODO(aelwazir): To be enabled if old API is deprecated
// The HSA_AMD_TOOL_PRIORITY variable must be a constant value type
// initialized by the loader itself, not by code during _init. 'extern const'
// seems do that although that is not a guarantee.
// ROCPROFILER_EXPORT extern const uint32_t HSA_AMD_TOOL_PRIORITY = 25;
/**
* @brief Callback function called upon loading the HSA.
* The function updates the core api table function pointers to point to the
* interceptor functions in this file.
*/
// ROCPROFILER_EXPORT bool OnLoad(HsaApiTable* table, uint64_t runtime_version,
// uint64_t failed_tool_count, const char* const* failed_tool_names) {
// if (started) rocmtools::fatal("HSA Tool started already!");
// started = true;
// rocmtools::hsa_support::Initialize(table);
// return true;
// }
/**
* @brief Callback function upon unloading the HSA.
*/
// ROCPROFILER_EXPORT void OnUnload() {
// if (!started) rocmtools::fatal("HSA Tool hasn't started yet!");
// rocmtools::hsa_support::Finalize();
// }
} // extern "C"