From a14c15ea28bf6d02b8946dfae6f136889413aada Mon Sep 17 00:00:00 2001 From: "Galantsev, Dmitrii" Date: Tue, 25 Mar 2025 14:47:22 -0500 Subject: [PATCH] Profiler - Update to 1.0 Change-Id: Iee6d5e7a87a5eb8eed61adccf6729e4d6a144bf8 Signed-off-by: Galantsev, Dmitrii [ROCm/rdc commit: 2adc8f82c600f4d24ff1fd1384e0602bcc1706bb] --- .../rdc_rocp/RdcRocpCounterSampler.h | 8 +- .../rdc_modules/rdc_rocp/CMakeLists.txt | 2 +- .../rdc_rocp/RdcRocpCounterSampler.cc | 80 ++++++++----------- 3 files changed, 38 insertions(+), 52 deletions(-) diff --git a/projects/rdc/include/rdc_modules/rdc_rocp/RdcRocpCounterSampler.h b/projects/rdc/include/rdc_modules/rdc_rocp/RdcRocpCounterSampler.h index 357a96243b..5838a96a52 100644 --- a/projects/rdc/include/rdc_modules/rdc_rocp/RdcRocpCounterSampler.h +++ b/projects/rdc/include/rdc_modules/rdc_rocp/RdcRocpCounterSampler.h @@ -67,13 +67,13 @@ class CounterSampler { private: rocprofiler_agent_id_t agent_ = {}; rocprofiler_context_id_t ctx_ = {}; - rocprofiler_profile_config_id_t profile_ = {.handle = 0}; + rocprofiler_counter_config_id_t counter_ = {.handle = 0}; - std::map, rocprofiler_profile_config_id_t> cached_profiles_; - std::map profile_sizes_; + std::map, rocprofiler_counter_config_id_t> cached_counter_; + std::map counter_sizes_; // Internal function used to set the profile for the agent when start_context is called - void set_profile(rocprofiler_context_id_t ctx, rocprofiler_agent_set_profile_callback_t cb) const; + void set_profile(rocprofiler_context_id_t ctx, rocprofiler_device_counting_agent_cb_t cb) const; // Get the size of a counter in number of records size_t get_counter_size(rocprofiler_counter_id_t counter); diff --git a/projects/rdc/rdc_libs/rdc_modules/rdc_rocp/CMakeLists.txt b/projects/rdc/rdc_libs/rdc_modules/rdc_rocp/CMakeLists.txt index 848b274402..0ea1b51e96 100644 --- a/projects/rdc/rdc_libs/rdc_modules/rdc_rocp/CMakeLists.txt +++ b/projects/rdc/rdc_libs/rdc_modules/rdc_rocp/CMakeLists.txt @@ -22,7 +22,7 @@ if(BUILD_PROFILER) message("RDC_ROCP_LIB_INC_LIST=${RDC_ROCP_LIB_INC_LIST}") - find_package(rocprofiler-sdk HINTS ${ROCM_DIR}/lib/cmake CONFIGURE REQUIRED) + find_package(rocprofiler-sdk 1.0.0 HINTS ${ROCM_DIR}/lib/cmake CONFIGURE REQUIRED) find_package( hsa-runtime64 NAMES diff --git a/projects/rdc/rdc_libs/rdc_modules/rdc_rocp/RdcRocpCounterSampler.cc b/projects/rdc/rdc_libs/rdc_modules/rdc_rocp/RdcRocpCounterSampler.cc index 0affac6ff7..cbf31e10a2 100644 --- a/projects/rdc/rdc_libs/rdc_modules/rdc_rocp/RdcRocpCounterSampler.cc +++ b/projects/rdc/rdc_libs/rdc_modules/rdc_rocp/RdcRocpCounterSampler.cc @@ -71,10 +71,10 @@ CounterSampler::CounterSampler(rocprofiler_agent_id_t agent) : agent_(agent) { return rocprofiler_configure_device_counting_service( ctx_, {.handle = 0}, agent, [](rocprofiler_context_id_t context_id, rocprofiler_agent_id_t, - rocprofiler_agent_set_profile_callback_t set_config, void* user_data) { + rocprofiler_device_counting_agent_cb_t cb, void* user_data) { if (user_data) { auto* sampler = static_cast(user_data); - sampler->set_profile(context_id, set_config); + sampler->set_profile(context_id, cb); } }, this); @@ -125,10 +125,10 @@ std::unordered_map CounterSampler::get_record_dimensions( void CounterSampler::sample_counter_values(const std::vector& counters, std::vector& out, uint64_t duration) { - auto profile_cached = cached_profiles_.find(counters); - if (profile_cached == cached_profiles_.end()) { + auto counter_cached = cached_counter_.find(counters); + if (counter_cached == cached_counter_.end()) { size_t expected_size = 0; - rocprofiler_profile_config_id_t profile = {}; + rocprofiler_counter_config_id_t counter = {}; std::vector gpu_counters; auto roc_counters = get_supported_counters(agent_); for (const auto& counter : counters) { @@ -142,22 +142,22 @@ void CounterSampler::sample_counter_values(const std::vector& count } RocprofilerCall( [&]() { - return rocprofiler_create_profile_config(agent_, gpu_counters.data(), gpu_counters.size(), - &profile); + return rocprofiler_create_counter_config(agent_, gpu_counters.data(), gpu_counters.size(), + &counter); }, - "Could not create profile", __FILE__, __LINE__); - cached_profiles_.emplace(counters, profile); - profile_sizes_.emplace(profile.handle, expected_size); - profile_cached = cached_profiles_.find(counters); + "Could not create counter", __FILE__, __LINE__); + cached_counter_.emplace(counters, counter); + counter_sizes_.emplace(counter.handle, expected_size); + counter_cached = cached_counter_.find(counters); } - if (profile_sizes_.find(profile_cached->second.handle) == profile_sizes_.end()) { - RDC_LOG(RDC_ERROR, "Error: Profile handle " << profile_cached->second.handle - << " not found in profile_sizes_." << std::endl); - throw std::runtime_error("Profile handle not found in profile_sizes_"); + if (counter_sizes_.find(counter_cached->second.handle) == counter_sizes_.end()) { + RDC_LOG(RDC_ERROR, "Error: Profile handle " << counter_cached->second.handle + << " not found in counter_sizes_." << std::endl); + throw std::runtime_error("Profile handle not found in counter_sizes_"); } - out.resize(profile_sizes_.at(profile_cached->second.handle)); - profile_ = profile_cached->second; + out.resize(counter_sizes_.at(counter_cached->second.handle)); + counter_ = counter_cached->second; rocprofiler_start_context(ctx_); size_t out_size = out.size(); // Wait for sampling window to collect metrics @@ -194,26 +194,17 @@ std::vector CounterSampler::get_available_agents() { } void CounterSampler::set_profile(rocprofiler_context_id_t ctx, - rocprofiler_agent_set_profile_callback_t cb) const { - if (profile_.handle != 0) { - cb(ctx, profile_); + rocprofiler_device_counting_agent_cb_t cb) const { + if (counter_.handle != 0) { + cb(ctx, counter_); } } size_t CounterSampler::get_counter_size(rocprofiler_counter_id_t counter) { - size_t size = 1; - rocprofiler_iterate_counter_dimensions( - counter, - [](rocprofiler_counter_id_t, const rocprofiler_record_dimension_info_t* dim_info, - size_t num_dims, void* user_data) { - size_t* s = static_cast(user_data); - for (size_t i = 0; i < num_dims; i++) { - *s *= dim_info[i].instance_size; - } - return ROCPROFILER_STATUS_SUCCESS; - }, - static_cast(&size)); - return size; + rocprofiler_counter_info_v1_t info; + rocprofiler_query_counter_info(counter, ROCPROFILER_COUNTER_INFO_VERSION_1, + static_cast(&info)); + return info.instance_ids_count; } std::unordered_map CounterSampler::get_supported_counters( @@ -252,20 +243,15 @@ std::unordered_map CounterSampler::get_su std::vector CounterSampler::get_counter_dimensions( rocprofiler_counter_id_t counter) { - std::vector dims; - rocprofiler_available_dimensions_cb_t cb = [](rocprofiler_counter_id_t, - const rocprofiler_record_dimension_info_t* dim_info, - size_t num_dims, void* user_data) { - std::vector* vec = - static_cast*>(user_data); - for (size_t i = 0; i < num_dims; i++) { - vec->push_back(dim_info[i]); - } - return ROCPROFILER_STATUS_SUCCESS; - }; - RocprofilerCall([&]() { return rocprofiler_iterate_counter_dimensions(counter, cb, &dims); }, - "Could not iterate counter dimensions", __FILE__, __LINE__); - return dims; + rocprofiler_counter_info_v1_t info; + RocprofilerCall( + [&]() { + return rocprofiler_query_counter_info(counter, ROCPROFILER_COUNTER_INFO_VERSION_1, + static_cast(&info)); + }, + "Could not query info for counter", __FILE__, __LINE__); + return std::vector{info.dimensions, + info.dimensions + info.dimensions_count}; } int tool_init(rocprofiler_client_finalize_t, void*) {