From f615e85f710df890e0537173aba5cacdeb17027a Mon Sep 17 00:00:00 2001 From: "Welton, Benjamin" Date: Tue, 4 Feb 2025 04:06:03 -0800 Subject: [PATCH] [SWDEV-509876] Remove buffer requirement from device counting service (#132) * [SWDEV-509876] Remove buffer requirement from device counting service No longer require a buffer to be given when setting up device counting service. This is to reduce performance overhead in cases where immediate return of counting samples is being used (synchronous mode). * Missed file * Update source/include/rocprofiler-sdk/device_counting_service.h Co-authored-by: Madsen, Jonathan * Update source/lib/rocprofiler-sdk/counters/controller.cpp Co-authored-by: Madsen, Jonathan * Update source/lib/rocprofiler-sdk/counters/device_counting.cpp Co-authored-by: Madsen, Jonathan * Fixes for build --------- Co-authored-by: Benjamin Welton Co-authored-by: Madsen, Jonathan Co-authored-by: Benjamin Welton [ROCm/rocprofiler-sdk commit: 0c4a56c6bbac559fc205b655d1743342b2707392] --- .../include/rocprofiler-sdk/device_counting_service.h | 4 +++- .../source/lib/rocprofiler-sdk/counters/controller.cpp | 3 ++- .../lib/rocprofiler-sdk/counters/device_counting.cpp | 7 ++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/device_counting_service.h b/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/device_counting_service.h index 1dcf9789cf..665b975da3 100644 --- a/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/device_counting_service.h +++ b/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/device_counting_service.h @@ -76,7 +76,9 @@ typedef void (*rocprofiler_device_counting_service_callback_t)( * @param [in] context_id context id * @param [in] buffer_id id of the buffer to use for the counting service. When * rocprofiler_sample_device_counting_service is called, counter data will be written - * to this buffer. + * to this buffer. If the input buffer id is null (i.e. `rocprofiler_buffer_id_t{.handle = 0}`), the + * counter data will not be written to a buffer and will only be returned in the output_records of + * rocprofiler_sample_device_counting_service * @param [in] agent_id agent to configure profiling on. * @param [in] cb Callback called when the context is started for the tool to specify what * counters to collect (rocprofiler_profile_config_id_t). diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/controller.cpp b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/controller.cpp index 5a8680215b..546107839d 100644 --- a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/controller.cpp +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/controller.cpp @@ -82,7 +82,8 @@ CounterController::configure_agent_collection(rocprofiler_context_id_t context_i // cannot coexist in the same context for now. if(ctx.pc_sampler) return ROCPROFILER_STATUS_ERROR_CONTEXT_CONFLICT; - if(!rocprofiler::buffer::get_buffer(buffer_id.handle)) + if(!rocprofiler::buffer::get_buffer(buffer_id) && + buffer_id != rocprofiler_buffer_id_t{.handle = 0}) { return ROCPROFILER_STATUS_ERROR_BUFFER_NOT_FOUND; } diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/device_counting.cpp b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/device_counting.cpp index f0840b5f14..88543a834b 100644 --- a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/device_counting.cpp +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/device_counting.cpp @@ -132,7 +132,7 @@ agent_async_handler(hsa_signal_value_t /*signal_v*/, void* data) *prof_config->agent, prof_config->required_special_counters, decoded_pkt); auto* buf = buffer::get_buffer(callback_data.buffer.handle); - if(!buf) + if(!buf && callback_data.buffer != rocprofiler_buffer_id_t{.handle = 0}) { ROCP_FATAL << fmt::format("Buffer {} destroyed before record was written", callback_data.buffer.handle); @@ -160,8 +160,9 @@ agent_async_handler(hsa_signal_value_t /*signal_v*/, void* data) { callback_data.cached_counters->push_back(val); } - buf->emplace( - ROCPROFILER_BUFFER_CATEGORY_COUNTERS, ROCPROFILER_COUNTER_RECORD_VALUE, val); + if(buf) + buf->emplace( + ROCPROFILER_BUFFER_CATEGORY_COUNTERS, ROCPROFILER_COUNTER_RECORD_VALUE, val); } }