Add rocmtools support
This commit adds integration with ROCmTools Additional changes: - Fix DEB and RPM installation issue when systemd is not present - Fix typos in rdc.h - Wrap negative values in parentheses in rdc.h - CMAKE: Improve rocm_smi searching - README: Improve formatting, add info about ROCmTools Metrics added: 700-714 Metrics can be listed with `rdci dmon --list-all` Majority of the metrics are only supported by Instict (MI) series GPUs 700 RDC_FI_PROF_ELAPSED_CYCLES should be available on most devices See README for more information Change-Id: I907d3eacdc92fc5588ca6c76c2fa1ce0ad900770 Signed-off-by: Galantsev, Dmitrii <dmitrii.galantsev@amd.com>
Dieser Commit ist enthalten in:
@@ -59,6 +59,7 @@ set(RDC_LIB_INC_DIR "${INC_DIR}")
|
||||
set(BOOTSTRAP_LIB "rdc_bootstrap")
|
||||
set(RDC_LIB "rdc")
|
||||
set(RDC_ROCR_LIB "rdc_rocr")
|
||||
set(RDC_ROCP_LIB "rdc_rocp")
|
||||
set(RDCCLIENT_LIB "rdc_client")
|
||||
|
||||
## Set RUNPATH if ROCM_RPATH is defined and passed by the environment
|
||||
@@ -90,7 +91,8 @@ set(CPACK_DEBIAN_PACKAGE_DEPENDS "rocm-core")
|
||||
set(CPACK_RPM_PACKAGE_REQUIRES "rocm-core")
|
||||
|
||||
# link grpc and ROCm to RSMI
|
||||
link_directories(${RSMI_LIB_DIR} "${GRPC_ROOT}/lib" "${GRPC_ROOT}/lib64" "${ROCM_DIR}/lib")
|
||||
#link_directories(${RSMI_LIB_DIR} "${GRPC_ROOT}/lib" "${GRPC_ROOT}/lib64" "${ROCM_DIR}/lib")
|
||||
link_directories(${RSMI_LIB_DIR} "${GRPC_ROOT}/lib" "${GRPC_ROOT}/lib64")
|
||||
|
||||
# add librdc_bootstrap.so
|
||||
add_subdirectory(bootstrap)
|
||||
@@ -98,9 +100,12 @@ add_subdirectory(bootstrap)
|
||||
# add librdc.so
|
||||
add_subdirectory(rdc)
|
||||
|
||||
# add librdc_rocr.so to RDC_LIBS_MODULES
|
||||
# add librdc_rocr.so to RDC_LIB_MODULES
|
||||
add_subdirectory(rdc_modules/rdc_rocr)
|
||||
|
||||
# add librdc_rocp.so to RDC_LIB_MODULES
|
||||
add_subdirectory(rdc_modules/rdc_rocp)
|
||||
|
||||
if(BUILD_STANDALONE)
|
||||
# add librdc_client.so
|
||||
add_subdirectory(rdc_client)
|
||||
@@ -125,7 +130,7 @@ else()
|
||||
endif()
|
||||
|
||||
# Add module directives if those exist
|
||||
if(RDC_LIBS_MODULES)
|
||||
if(RDC_LIB_MODULES)
|
||||
install(TARGETS ${RDC_LIB_MODULES}
|
||||
EXPORT rdcTargets
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${RDC}
|
||||
|
||||
@@ -25,11 +25,11 @@ message("BOOTSTRAP_LIB_INC_LIST=${BOOTSTRAP_LIB_INC_LIST}")
|
||||
add_library(${BOOTSTRAP_LIB} SHARED ${BOOTSTRAP_LIB_SRC_LIST} ${BOOTSTRAP_LIB_INC_LIST})
|
||||
target_link_libraries(${BOOTSTRAP_LIB} pthread dl)
|
||||
target_include_directories(${BOOTSTRAP_LIB} PRIVATE
|
||||
"${RSMI_INC_DIR}"
|
||||
"${ROCM_DIR}/include"
|
||||
"${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/include"
|
||||
"${COMMON_DIR}")
|
||||
"${COMMON_DIR}"
|
||||
"${RSMI_INC_DIR}"
|
||||
"${ROCM_DIR}/include")
|
||||
|
||||
target_include_directories(${BOOTSTRAP_LIB}
|
||||
PUBLIC
|
||||
|
||||
@@ -19,6 +19,7 @@ set(RDC_LIB_SRC_LIST ${RDC_LIB_SRC_LIST}
|
||||
"${SRC_DIR}/RdcNotificationImpl.cc"
|
||||
"${SRC_DIR}/RdcPerfTimer.cc"
|
||||
"${SRC_DIR}/RdcRasLib.cc"
|
||||
"${SRC_DIR}/RdcRocpLib.cc"
|
||||
"${SRC_DIR}/RdcRocrLib.cc"
|
||||
"${SRC_DIR}/RdcSmiDiagnosticImpl.cc"
|
||||
"${SRC_DIR}/RdcSmiLib.cc"
|
||||
@@ -50,6 +51,7 @@ set(RDC_LIB_INC_LIST ${RDC_LIB_INC_LIST}
|
||||
"${INC_DIR}/impl/RdcModuleMgrImpl.h"
|
||||
"${INC_DIR}/impl/RdcNotificationImpl.h"
|
||||
"${INC_DIR}/impl/RdcRasLib.h"
|
||||
"${INC_DIR}/impl/RdcRocpLib.h"
|
||||
"${INC_DIR}/impl/RdcRocrLib.h"
|
||||
"${INC_DIR}/impl/RdcSmiDiagnosticImpl.h"
|
||||
"${INC_DIR}/impl/RdcSmiLib.h"
|
||||
|
||||
@@ -20,20 +20,21 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
#include "rdc_lib/impl/RdcModuleMgrImpl.h"
|
||||
#include "rdc_lib/impl/RdcTelemetryModule.h"
|
||||
|
||||
#include "rdc_lib/impl/RdcDiagnosticModule.h"
|
||||
#include "rdc_lib/impl/RdcRasLib.h"
|
||||
#include "rdc_lib/impl/RdcRocpLib.h"
|
||||
#include "rdc_lib/impl/RdcRocrLib.h"
|
||||
#include "rdc_lib/impl/RdcTelemetryModule.h"
|
||||
|
||||
namespace amd {
|
||||
namespace rdc {
|
||||
|
||||
RdcModuleMgrImpl::RdcModuleMgrImpl(const RdcMetricFetcherPtr& fetcher):
|
||||
smi_lib_(std::make_shared<RdcSmiLib>(fetcher)) {
|
||||
RdcModuleMgrImpl::RdcModuleMgrImpl(const RdcMetricFetcherPtr& fetcher)
|
||||
: smi_lib_(std::make_shared<RdcSmiLib>(fetcher)) {
|
||||
// The smi_lib_ always need to be loaded.
|
||||
}
|
||||
|
||||
|
||||
RdcTelemetryPtr RdcModuleMgrImpl::get_telemetry_module() {
|
||||
if (rdc_telemetry_module_) {
|
||||
return rdc_telemetry_module_;
|
||||
@@ -44,8 +45,13 @@ RdcTelemetryPtr RdcModuleMgrImpl::get_telemetry_module() {
|
||||
ras_lib_.reset(new RdcRasLib("librdc_ras.so"));
|
||||
}
|
||||
|
||||
if (!rocp_lib_) {
|
||||
rocp_lib_.reset(new RdcRocpLib("librdc_rocp.so"));
|
||||
}
|
||||
|
||||
if (!rdc_telemetry_module_) {
|
||||
rdc_telemetry_module_.reset(new RdcTelemetryModule(smi_lib_, ras_lib_));
|
||||
rdc_telemetry_module_.reset(
|
||||
new RdcTelemetryModule(smi_lib_, ras_lib_, rocp_lib_));
|
||||
}
|
||||
|
||||
return rdc_telemetry_module_;
|
||||
@@ -75,4 +81,3 @@ RdcDiagnosticPtr RdcModuleMgrImpl::get_diagnostic_module() {
|
||||
|
||||
} // namespace rdc
|
||||
} // namespace amd
|
||||
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
Copyright (c) 2022 - present Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
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 "rdc_lib/impl/RdcRocpLib.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
#include "rdc_lib/RdcLogger.h"
|
||||
#include "rdc_lib/rdc_common.h"
|
||||
|
||||
namespace amd {
|
||||
namespace rdc {
|
||||
|
||||
// TODO: Add init and destroy calls support
|
||||
RdcRocpLib::RdcRocpLib(const char* lib_name)
|
||||
: telemetry_fields_query_(nullptr),
|
||||
telemetry_fields_value_get_(nullptr),
|
||||
telemetry_fields_watch_(nullptr),
|
||||
telemetry_fields_unwatch_(nullptr) {
|
||||
rdc_status_t status = lib_loader_.load(lib_name);
|
||||
if (status != RDC_ST_OK) {
|
||||
RDC_LOG(RDC_ERROR, "Rocp related function will not work.");
|
||||
return;
|
||||
}
|
||||
|
||||
status = lib_loader_.load_symbol(
|
||||
&telemetry_fields_query_, "rdc_telemetry_fields_query");
|
||||
if (status != RDC_ST_OK) {
|
||||
telemetry_fields_query_ = nullptr;
|
||||
}
|
||||
|
||||
status = lib_loader_.load_symbol(
|
||||
&telemetry_fields_value_get_, "rdc_telemetry_fields_value_get");
|
||||
if (status != RDC_ST_OK) {
|
||||
telemetry_fields_value_get_ = nullptr;
|
||||
}
|
||||
|
||||
status = lib_loader_.load_symbol(
|
||||
&telemetry_fields_watch_, "rdc_telemetry_fields_watch");
|
||||
if (status != RDC_ST_OK) {
|
||||
telemetry_fields_watch_ = nullptr;
|
||||
}
|
||||
|
||||
status = lib_loader_.load_symbol(
|
||||
&telemetry_fields_unwatch_, "rdc_telemetry_fields_unwatch");
|
||||
if (status != RDC_ST_OK) {
|
||||
telemetry_fields_unwatch_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
RdcRocpLib::~RdcRocpLib() = default;
|
||||
|
||||
// get support field ids
|
||||
rdc_status_t RdcRocpLib::rdc_telemetry_fields_query(
|
||||
uint32_t field_ids[MAX_NUM_FIELDS],
|
||||
uint32_t* field_count) {
|
||||
if (field_count == nullptr) {
|
||||
return RDC_ST_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
return telemetry_fields_query_(field_ids, field_count);
|
||||
}
|
||||
|
||||
// Fetch
|
||||
rdc_status_t RdcRocpLib::rdc_telemetry_fields_value_get(
|
||||
rdc_gpu_field_t* fields,
|
||||
uint32_t fields_count,
|
||||
rdc_field_value_f callback,
|
||||
void* user_data) {
|
||||
if (fields == nullptr) {
|
||||
return RDC_ST_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
RDC_LOG(RDC_DEBUG, "Fetch " << fields_count << " fields from rocp_lib.");
|
||||
|
||||
return telemetry_fields_value_get_(
|
||||
fields, fields_count, callback, user_data);
|
||||
}
|
||||
|
||||
rdc_status_t RdcRocpLib::rdc_telemetry_fields_watch(
|
||||
rdc_gpu_field_t* fields,
|
||||
uint32_t fields_count) {
|
||||
if (fields == nullptr) {
|
||||
return RDC_ST_BAD_PARAMETER;
|
||||
}
|
||||
return telemetry_fields_watch_(fields, fields_count);
|
||||
}
|
||||
|
||||
rdc_status_t RdcRocpLib::rdc_telemetry_fields_unwatch(
|
||||
rdc_gpu_field_t* fields,
|
||||
uint32_t fields_count) {
|
||||
if (fields == nullptr) {
|
||||
return RDC_ST_BAD_PARAMETER;
|
||||
}
|
||||
return telemetry_fields_unwatch_(fields, fields_count);
|
||||
}
|
||||
|
||||
} // namespace rdc
|
||||
} // namespace amd
|
||||
@@ -94,11 +94,15 @@ rdc_status_t RdcTelemetryModule::rdc_telemetry_fields_unwatch(
|
||||
|
||||
RdcTelemetryModule::RdcTelemetryModule(
|
||||
const RdcSmiLibPtr& smi_lib,
|
||||
const RdcRasLibPtr& ras_module) {
|
||||
const RdcRasLibPtr& ras_module,
|
||||
const RdcRocpLibPtr& rocp_module) {
|
||||
telemetry_modules_.push_back(smi_lib);
|
||||
if (ras_module) {
|
||||
telemetry_modules_.push_back(ras_module);
|
||||
}
|
||||
if (rocp_module) {
|
||||
telemetry_modules_.push_back(rocp_module);
|
||||
}
|
||||
|
||||
auto ite = telemetry_modules_.begin();
|
||||
for (; ite != telemetry_modules_.end(); ite++) {
|
||||
@@ -166,4 +170,3 @@ rdc_status_t RdcTelemetryModule::rdc_telemetry_fields_value_get(
|
||||
|
||||
} // namespace rdc
|
||||
} // namespace amd
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
message("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
|
||||
message(" Cmake RDC Lib-ROCP ")
|
||||
message("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
|
||||
|
||||
set(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
set(INC_DIR "${PROJECT_SOURCE_DIR}/include/rdc_modules/rdc_rocp")
|
||||
|
||||
set(RDC_ROCP_LIB_COMPONENT "lib${RDC_ROCP_LIB}")
|
||||
set(RDC_ROCP_LIB_SRC_LIST
|
||||
"${BOOTSTRAP_LIB_SRC_DIR}/RdcLogger.cc"
|
||||
"${SRC_DIR}/RdcTelemetryLib.cc"
|
||||
"${SRC_DIR}/RdcRocpBase.cc")
|
||||
set(RDC_ROCP_LIB_INC_LIST
|
||||
"${PROJECT_SOURCE_DIR}/include/rdc/rdc.h"
|
||||
"${RDC_LIB_INC_DIR}/RdcDiagnosticLibInterface.h"
|
||||
"${RDC_LIB_INC_DIR}/rdc_common.h"
|
||||
"${RDC_LIB_INC_DIR}/RdcLogger.h"
|
||||
"${INC_DIR}/RdcTelemetryLib.h"
|
||||
"${INC_DIR}/RdcRocpBase.h")
|
||||
|
||||
if(BUILD_ROCPTEST)
|
||||
message("Build librdc_rocp.so is enabled, make sure ROCmTools is installed.")
|
||||
|
||||
message("RDC_ROCP_LIB_INC_LIST=${RDC_ROCP_LIB_INC_LIST}")
|
||||
|
||||
set(ROCMTOOLS_LIB rocmtools::rocmtools)
|
||||
# below provides rocmtools::rocmtools package
|
||||
include(Findrocmtools)
|
||||
|
||||
set(HSA_LIB "hsa-runtime64")
|
||||
set(RDC_LIB_MODULES ${RDC_LIB_MODULES} ${RDC_ROCP_LIB} PARENT_SCOPE)
|
||||
add_library(${RDC_ROCP_LIB} SHARED ${RDC_ROCP_LIB_SRC_LIST} ${RDC_ROCP_LIB_INC_LIST})
|
||||
target_link_libraries(${RDC_ROCP_LIB} ${RDC_LIB} ${BOOTSTRAP_LIB} ${HSA_LIB} ${ROCMTOOLS_LIB} pthread dl)
|
||||
target_include_directories(${RDC_ROCP_LIB} PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/include"
|
||||
"${COMMON_DIR}"
|
||||
"${RSMI_INC_DIR}"
|
||||
"${ROCM_DIR}/include"
|
||||
"${ROCM_DIR}/include/hsa")
|
||||
|
||||
# Set the VERSION and SOVERSION values
|
||||
set_property(TARGET ${RDC_ROCP_LIB} PROPERTY
|
||||
SOVERSION "${VERSION_MAJOR}")
|
||||
set_property(TARGET ${RDC_ROCP_LIB} PROPERTY
|
||||
VERSION "${SO_VERSION_STRING}")
|
||||
|
||||
# If the library is a release, strip the target library
|
||||
if("${CMAKE_BUILD_TYPE}" STREQUAL Release)
|
||||
add_custom_command(
|
||||
TARGET ${RDC_ROCP_LIB}
|
||||
POST_BUILD COMMAND ${CMAKE_STRIP} ${RDC_ROCP_LIB_COMPONENT}.so)
|
||||
endif()
|
||||
endif()
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
Copyright (c) 2022 - present Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
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 <rocmtools.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include "rdc/rdc.h"
|
||||
#include "rdc_lib/RdcLogger.h"
|
||||
#include "rdc_lib/rdc_common.h"
|
||||
#include "rdc_modules/rdc_rocp/RdcRocpBase.h"
|
||||
|
||||
namespace amd {
|
||||
namespace rdc {
|
||||
|
||||
RdcRocpBase::RdcRocpBase() {
|
||||
auto status = rocmtools_initialize();
|
||||
RDC_LOG(RDC_INFO, "rocmtools_initialize status: " << status);
|
||||
}
|
||||
|
||||
RdcRocpBase::~RdcRocpBase() {
|
||||
for (auto& session : sessions) {
|
||||
const rdc_status_t status = destroy_session(session.first);
|
||||
assert(status == RDC_ST_OK);
|
||||
}
|
||||
sessions.clear();
|
||||
auto status = rocmtools_finalize();
|
||||
RDC_LOG(RDC_INFO, "rocmtools_finalize status: " << status);
|
||||
}
|
||||
|
||||
rdc_status_t RdcRocpBase::rocp_lookup(
|
||||
pair_gpu_field_t gpu_field,
|
||||
double* value) {
|
||||
if (sessions.empty()) {
|
||||
return RDC_ST_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (value == nullptr) {
|
||||
return RDC_ST_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
rocmtools_device_profile_metric_t counter;
|
||||
session_info_t session = sessions.at(gpu_field);
|
||||
const rocmtools_status_t status =
|
||||
rocmtools_device_profiling_session_poll(session.id, &counter);
|
||||
session.stop_time = std::chrono::high_resolution_clock::now();
|
||||
if (status != ROCMTOOLS_STATUS_SUCCESS) {
|
||||
return Rocp2RdcError(status);
|
||||
}
|
||||
const auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
session.stop_time - session.start_time)
|
||||
.count();
|
||||
// some metrics are derived from others and depend on time passed
|
||||
switch (gpu_field.second) {
|
||||
case RDC_FI_PROF_GFLOPS_16:
|
||||
case RDC_FI_PROF_GFLOPS_32:
|
||||
case RDC_FI_PROF_GFLOPS_64:
|
||||
case RDC_FI_PROF_MEMR_BW_KBPNS:
|
||||
case RDC_FI_PROF_MEMW_BW_KBPNS:
|
||||
*value = counter.value.value / elapsed;
|
||||
break;
|
||||
default:
|
||||
*value = counter.value.value;
|
||||
break;
|
||||
}
|
||||
return Rocp2RdcError(status);
|
||||
}
|
||||
|
||||
rdc_status_t RdcRocpBase::create_session(pair_gpu_field_t gpu_field) {
|
||||
if (sessions.count(gpu_field) != 0) {
|
||||
RDC_LOG(
|
||||
RDC_DEBUG, "Session for field (" << gpu_field.second << ") on GPU ["
|
||||
<< gpu_field.first
|
||||
<< "] already exists!");
|
||||
return RDC_ST_ALREADY_EXIST;
|
||||
}
|
||||
|
||||
session_info_t session = {};
|
||||
|
||||
std::vector<const char*> rocmtools_fields = {
|
||||
counter_map_k.at(gpu_field.second)};
|
||||
// create session
|
||||
rocmtools_status_t status = rocmtools_device_profiling_session_create(
|
||||
rocmtools_fields.data(), rocmtools_fields.size(), &session.id, 0,
|
||||
gpu_field.first);
|
||||
|
||||
if (status != ROCMTOOLS_STATUS_SUCCESS) {
|
||||
return Rocp2RdcError(status);
|
||||
}
|
||||
|
||||
// add start time
|
||||
session.start_time = std::chrono::high_resolution_clock::now();
|
||||
sessions.emplace(gpu_field, session);
|
||||
|
||||
// start session
|
||||
status = rocmtools_device_profiling_session_start(session.id);
|
||||
|
||||
return Rocp2RdcError(status);
|
||||
}
|
||||
|
||||
rdc_status_t RdcRocpBase::destroy_session(pair_gpu_field_t gpu_field) {
|
||||
if (sessions.empty()) {
|
||||
RDC_LOG(RDC_DEBUG, "Cannot destroy empty session...");
|
||||
return RDC_ST_OK;
|
||||
}
|
||||
|
||||
// no session with field
|
||||
if (sessions.count(gpu_field) == 0) {
|
||||
RDC_LOG(
|
||||
RDC_DEBUG, "Cannot destroy session with field ("
|
||||
<< gpu_field.second << ") on GPU ["
|
||||
<< gpu_field.first
|
||||
<< "] because it doesn't exist...");
|
||||
return RDC_ST_OK;
|
||||
}
|
||||
|
||||
const rocmtools_session_id_t session_id = sessions.at(gpu_field).id;
|
||||
const rocmtools_status_t status =
|
||||
rocmtools_device_profiling_session_destroy(session_id);
|
||||
if (status == ROCMTOOLS_STATUS_SUCCESS) {
|
||||
const auto num_of_destroyed_sessions = sessions.erase(gpu_field);
|
||||
RDC_LOG(
|
||||
RDC_DEBUG,
|
||||
"destroyed (" << num_of_destroyed_sessions << ") sessions");
|
||||
}
|
||||
return Rocp2RdcError(status);
|
||||
}
|
||||
|
||||
rdc_status_t RdcRocpBase::Rocp2RdcError(rocmtools_status_t rocm_status) {
|
||||
switch (rocm_status) {
|
||||
case ROCMTOOLS_STATUS_SUCCESS:
|
||||
return RDC_ST_OK;
|
||||
case ROCMTOOLS_STATUS_ERROR_HAS_ACTIVE_SESSION:
|
||||
return RDC_ST_ALREADY_EXIST;
|
||||
case ROCMTOOLS_STATUS_ERROR_SESSION_FILTER_DATA_MISMATCH:
|
||||
case ROCMTOOLS_STATUS_ERROR_SESSION_MISSING_FILTER:
|
||||
case ROCMTOOLS_STATUS_ERROR_SESSION_NOT_FOUND:
|
||||
return RDC_ST_BAD_PARAMETER;
|
||||
default:
|
||||
return RDC_ST_UNKNOWN_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace rdc
|
||||
} // namespace amd
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
Copyright (c) 2022 - present Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
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 <sys/time.h>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
#include "rdc/rdc.h"
|
||||
#include "rdc_lib/RdcLogger.h"
|
||||
#include "rdc_lib/RdcTelemetryLibInterface.h"
|
||||
#include "rdc_lib/rdc_common.h"
|
||||
#include "rdc_modules/rdc_rocp/RdcRocpBase.h"
|
||||
|
||||
amd::rdc::RdcRocpBase rocp;
|
||||
|
||||
// get supported field ids
|
||||
// TODO: Query fields with rocprofiler
|
||||
rdc_status_t rdc_telemetry_fields_query(
|
||||
uint32_t field_ids[MAX_NUM_FIELDS],
|
||||
uint32_t* field_count) {
|
||||
// extract all keys from counter_map
|
||||
std::vector<uint32_t> counter_keys;
|
||||
counter_keys.reserve(amd::rdc::counter_map_k.size());
|
||||
for (auto it : amd::rdc::counter_map_k) {
|
||||
counter_keys.push_back(it.first);
|
||||
}
|
||||
|
||||
*field_count = counter_keys.size();
|
||||
// copy from vector into array
|
||||
std::copy(counter_keys.begin(), counter_keys.end(), field_ids);
|
||||
|
||||
return RDC_ST_OK;
|
||||
}
|
||||
|
||||
// Fetch
|
||||
rdc_status_t rdc_telemetry_fields_value_get(
|
||||
rdc_gpu_field_t* fields,
|
||||
uint32_t fields_count,
|
||||
rdc_field_value_f callback,
|
||||
void* user_data) {
|
||||
//
|
||||
// Bulk fetch fields
|
||||
std::vector<rdc_gpu_field_value_t> bulk_results;
|
||||
|
||||
struct timeval tv {};
|
||||
gettimeofday(&tv, nullptr);
|
||||
const uint64_t curTime =
|
||||
static_cast<uint64_t>(tv.tv_sec) * 1000 + tv.tv_usec / 1000;
|
||||
|
||||
// Fetch it one by one for left fields
|
||||
const int BULK_FIELDS_MAX = 16;
|
||||
rdc_gpu_field_value_t values[BULK_FIELDS_MAX];
|
||||
uint32_t bulk_count = 0;
|
||||
rdc_status_t status = RDC_ST_UNKNOWN_ERROR;
|
||||
double value = 0;
|
||||
for (uint32_t i = 0; i < fields_count; i++) {
|
||||
if (bulk_count >= BULK_FIELDS_MAX) {
|
||||
status = callback(values, bulk_count, user_data);
|
||||
// When the callback returns errors, stop processing and return.
|
||||
if (status != RDC_ST_OK) {
|
||||
return status;
|
||||
}
|
||||
bulk_count = 0;
|
||||
}
|
||||
|
||||
RDC_LOG(RDC_DEBUG, "ID: " << fields[i].field_id);
|
||||
|
||||
status = rocp.rocp_lookup(
|
||||
std::make_pair(fields[i].gpu_index, fields[i].field_id), &value);
|
||||
|
||||
// get value
|
||||
values[bulk_count].gpu_index = fields[i].gpu_index;
|
||||
values[bulk_count].field_value.type = DOUBLE;
|
||||
values[bulk_count].field_value.status = status;
|
||||
values[bulk_count].field_value.ts = curTime;
|
||||
values[bulk_count].field_value.value.dbl = value;
|
||||
values[bulk_count].field_value.field_id = fields[i].field_id;
|
||||
RDC_LOG(RDC_DEBUG, "VALUE: " << value);
|
||||
bulk_count++;
|
||||
}
|
||||
if (bulk_count != 0) {
|
||||
rdc_status_t status = callback(values, bulk_count, user_data);
|
||||
if (status != RDC_ST_OK) {
|
||||
return status;
|
||||
}
|
||||
bulk_count = 0;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
rdc_status_t rdc_telemetry_fields_watch(
|
||||
rdc_gpu_field_t* fields,
|
||||
uint32_t fields_count) {
|
||||
rdc_status_t status = RDC_ST_OK;
|
||||
for (uint32_t i = 0; i < fields_count; i++) {
|
||||
RDC_LOG(RDC_DEBUG, "WATCH: " << fields[i].field_id);
|
||||
const rdc_status_t temp_status = rocp.create_session(
|
||||
std::make_pair(fields[i].gpu_index, fields[i].field_id));
|
||||
if (temp_status != RDC_ST_OK) {
|
||||
status = temp_status;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
rdc_status_t rdc_telemetry_fields_unwatch(
|
||||
rdc_gpu_field_t* fields,
|
||||
uint32_t fields_count) {
|
||||
rdc_status_t status = RDC_ST_OK;
|
||||
for (uint32_t i = 0; i < fields_count; i++) {
|
||||
RDC_LOG(RDC_DEBUG, "UNWATCH: " << fields[i].field_id);
|
||||
const rdc_status_t temp_status = rocp.destroy_session(
|
||||
std::make_pair(fields[i].gpu_index, fields[i].field_id));
|
||||
// return last non-ok status
|
||||
if (temp_status != RDC_ST_OK) {
|
||||
status = temp_status;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
@@ -36,15 +36,15 @@ if(BUILD_ROCRTEST)
|
||||
message("RDC_ROCR_LIB_INC_LIST=${RDC_ROCR_LIB_INC_LIST}")
|
||||
|
||||
set(HSA_LIB "hsa-runtime64")
|
||||
set(RDC_LIBS_MODULES ${RDC_LIBS_MODULES} ${RDC_ROCR_LIB} PARENT_SCOPE)
|
||||
set(RDC_LIB_MODULES ${RDC_LIB_MODULES} ${RDC_ROCR_LIB} PARENT_SCOPE)
|
||||
add_library(${RDC_ROCR_LIB} SHARED ${RDC_ROCR_LIB_SRC_LIST} ${RDC_ROCR_LIB_INC_LIST})
|
||||
target_link_libraries(${RDC_ROCR_LIB} ${RDC_LIB} ${BOOTSTRAP_LIB} ${HSA_LIB} pthread dl)
|
||||
target_include_directories(${RDC_ROCR_LIB} PRIVATE
|
||||
"${RSMI_INC_DIR}"
|
||||
"${ROCM_DIR}/include"
|
||||
"${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/include"
|
||||
"${COMMON_DIR}")
|
||||
"${COMMON_DIR}"
|
||||
"${RSMI_INC_DIR}"
|
||||
"${ROCM_DIR}/include")
|
||||
|
||||
# Set the VERSION and SOVERSION values
|
||||
set_property(TARGET ${RDC_ROCR_LIB} PROPERTY
|
||||
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren