Adding --collection-period feature in rocprofv3 to match v1/v2 parity (#9)

* Adding Trace Period feature to rocprofv3

* Adding feature documentation

* Update source/bin/rocprofv3.py

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Fixing format

* Moving to Collection Period and changing the input params

* Format Fixes

* Fixing rebasing issues

* Removing atomic include from the tool

* Adding more options for units, optimizing the code

* Fixing rocprofv3.py

* Fixing time conv & adding time controlled app

* Fixing format

* Changing to shared memory testing methodology

* use of shmem use

* Fix include headers for transpose-time-controlled.cpp

* Format upload-image-to-github.py

* Removing shmem and using only env var to dump timestamps from the tool

* Tool Fixes + Test Config

* Adding Tests

* Fixing Review comments

* Update trace period implementation

* Update trace period tests

* check between start and stop timestamps

* Merge Fix

* Update validate.py

* Improve safety of rocprofiler_stop_context after finalization

* Pass context id to collection_period_cntrl by value

* Adding 20 us error margin

* Ensure log level for collection-period test is not more than warning

---------

Co-authored-by: Ammar ELWazir <aelwazir@amd.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>

[ROCm/rocprofiler-sdk commit: a579c70b71]
This commit is contained in:
Elwazir, Ammar
2024-12-05 20:17:24 -06:00
کامیت شده توسط GitHub
والد c2f9e2aca8
کامیت 90e3a30627
15فایلهای تغییر یافته به همراه429 افزوده شده و 22 حذف شده
@@ -60,16 +60,21 @@
#include <fmt/core.h>
#include <sys/mman.h>
#include <unistd.h>
#include <algorithm>
#include <cassert>
#include <chrono>
#include <csignal>
#include <cstring>
#include <fstream>
#include <future>
#include <iomanip>
#include <limits>
#include <mutex>
#include <optional>
#include <shared_mutex>
#include <thread>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
@@ -265,6 +270,77 @@ flush()
ROCP_INFO << "Buffers flushed";
}
void
collection_period_cntrl(std::promise<void>&& _promise, rocprofiler_context_id_t _ctx)
{
bool testing_cp = tool::get_env("ROCPROF_COLLECTION_PERIOD_TESTING", false);
auto log_fname = get_output_filename(tool::get_config(), "collection_periods", "log");
auto output_testing_file = std::ofstream{};
if(testing_cp)
{
ROCP_INFO << "collection period test logging enabled: " << log_fname;
output_testing_file.open(log_fname);
}
auto log_period = [testing_cp, &output_testing_file](
std::string_view label, auto _func, auto... _args) {
ROCP_INFO << "collection period: " << label;
auto beg = rocprofiler_timestamp_t{};
if(testing_cp)
{
rocprofiler_get_timestamp(&beg);
}
_func(_args...);
if(testing_cp)
{
auto end = rocprofiler_timestamp_t{};
rocprofiler_get_timestamp(&end);
output_testing_file << label << ":" << beg << ":" << end << '\n' << std::flush;
}
};
auto sleep_for_nsec = [](auto _value) {
if(_value > 0)
{
std::this_thread::yield();
std::this_thread::sleep_for(std::chrono::nanoseconds{_value});
}
};
auto periods = tool::get_config().collection_periods;
_promise.set_value(); // allow the launching thread to proceed
while(!periods.empty())
{
auto _period = periods.front();
periods.pop();
auto execute_period = [&]() {
if(testing_cp) output_testing_file << "--" << '\n';
log_period("delay", sleep_for_nsec, _period.delay);
log_period("start", rocprofiler_start_context, _ctx);
log_period("duration", sleep_for_nsec, _period.duration);
log_period("stop", rocprofiler_stop_context, _ctx);
};
if(_period.repeat == 0)
{
execute_period();
}
else
{
for(size_t i = 0; i < _period.repeat; ++i)
{
execute_period();
}
}
}
}
int
set_kernel_rename_correlation_id(rocprofiler_thread_id_t thr_id,
rocprofiler_context_id_t ctx_id,
@@ -553,8 +629,8 @@ code_object_tracing_callback(rocprofiler_callback_tracing_record_t record,
// add the kernel to the kernel_targets if
if(success)
{
// if kernel name is provided by user then by default all kernels in the application
// are targeted
// if kernel name is provided by user then by default all kernels in the
// application are targeted
const auto* kernel_info =
CHECK_NOTNULL(tool_metadata)->get_kernel_symbol(sym_data->kernel_id);
auto kernel_filter_include = tool::get_config().kernel_filter_include;
@@ -711,12 +787,14 @@ get_device_counting_service(rocprofiler_agent_id_t agent_id)
ROCP_FATAL_IF(dev_id_s.empty() ||
dev_id_s.find_first_not_of("0123456789") != std::string::npos)
<< "invalid device qualifier format (':device=N) where N is the GPU id: "
<< "invalid device qualifier format (':device=N) where N is the "
"GPU "
"id: "
<< itr;
auto dev_id_v = std::stol(dev_id_s);
// skip this counter if the counter is for a specific device id (which doesn't
// this agent's device id)
// skip this counter if the counter is for a specific device id (which
// doesn't this agent's device id)
if(dev_id_v != agent_v->gpu_index)
{
--expected_v; // is not expected
@@ -1257,7 +1335,17 @@ tool_init(rocprofiler_client_finalize_t fini_func, void* tool_data)
}
}
ROCPROFILER_CALL(rocprofiler_start_context(get_client_ctx()), "start context failed");
if(tool::get_config().collection_periods.empty())
{
ROCPROFILER_CHECK(rocprofiler_start_context(get_client_ctx()));
}
else
{
auto _prom = std::promise<void>{};
auto _fut = _prom.get_future();
std::thread{collection_period_cntrl, std::move(_prom), get_client_ctx()}.detach();
_fut.wait_for(std::chrono::seconds{1}); // wait for a max of 1 second
}
tool_metadata->process_id = getpid();
rocprofiler_get_timestamp(&(tool_metadata->process_start_ns));