ROCpd support [Part 2] (#109)
* Rocpd part 2, caching * Fix shadowed variables * backward compatibility * Fixed designated initializers * Fix timemory include * Remove benchmark & Fix build issues for rhel * Add missing bracket * Fix shadowing and pedantic * Fix pedantic pt2 * Fix duplicated SDK calls * Add decay in get_size_impl * Rename sample cache to trace cache * Add cache storage supported types * Resolving track naming in sampling module * fix sampling of flushing thread * fix sampling of flushing thread 2 * throw exception upon store while buffer storage is not running * Prevent fork crashing * Fix rebase issue * Applied suggestions from code review * Change flushing thread to use PTL * Fix agent creation order * Fix stream id ci throw * Remove force setup of rocprofiler-sdk * Code cleanup * Change initialization for agent * Add missing namespace * Fix the mismatch within the tool_agent->device_id * Switch from using handle to use agent type index * Fix pmc info comparator in metadata registry --------- Co-authored-by: Aleksandar <aleksandar.djordjevic@amd.com> Co-authored-by: Milan Radosavljevic <milan.radosavljevic@amd.com> Co-authored-by: Marjan Antic <marantic@amd.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
351d598869
Коммит
1f86010ca2
+493
-56
@@ -20,24 +20,31 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include "library/rocprofiler-sdk.hpp"
|
||||
#include "core/rocprofiler-sdk.hpp"
|
||||
#include "api.hpp"
|
||||
#include "common/synchronized.hpp"
|
||||
#include "core/common.hpp"
|
||||
#include "core/config.hpp"
|
||||
#include "core/containers/stable_vector.hpp"
|
||||
#include "core/debug.hpp"
|
||||
#include "core/gpu.hpp"
|
||||
#include "core/perfetto.hpp"
|
||||
#include "core/rocprofiler-sdk.hpp"
|
||||
#include "core/rocpd/json.hpp"
|
||||
#include "core/state.hpp"
|
||||
#include "core/trace_cache/buffer_storage.hpp"
|
||||
#include "core/trace_cache/cache_manager.hpp"
|
||||
#include "core/trace_cache/metadata_registry.hpp"
|
||||
#include "core/trace_cache/sample_type.hpp"
|
||||
#include "library/amd_smi.hpp"
|
||||
#include "library/components/category_region.hpp"
|
||||
#include "library/rocprofiler-sdk.hpp"
|
||||
#include "library/rocprofiler-sdk/counters.hpp"
|
||||
#include "library/rocprofiler-sdk/fwd.hpp"
|
||||
#include "library/rocprofiler-sdk/rccl.hpp"
|
||||
#include "library/thread_info.hpp"
|
||||
#include "library/tracing.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <timemory/components/timing/wall_clock.hpp>
|
||||
#include <timemory/hash/types.hpp>
|
||||
#include <timemory/unwind/processed_entry.hpp>
|
||||
@@ -247,7 +254,7 @@ create_agent_profile(rocprofiler_agent_id_t agent_id,
|
||||
ROCPROFSYS_ABORT_F(
|
||||
"Unable to find all counters for agent %i (gpu-%li, %s) in %s. Found: %s\n",
|
||||
tool_agent_v->agent->node_id, tool_agent_v->device_id,
|
||||
tool_agent_v->agent->name, requested_counters.c_str(),
|
||||
tool_agent_v->agent->name.c_str(), requested_counters.c_str(),
|
||||
found_counters.c_str());
|
||||
}
|
||||
|
||||
@@ -270,6 +277,12 @@ get_kernel_symbol_info(uint64_t _kernel_id)
|
||||
return tool_data->get_kernel_symbol_info(_kernel_id);
|
||||
}
|
||||
|
||||
const rocprofiler_callback_tracing_code_object_load_data_t*
|
||||
get_code_object_info(uint64_t _code_object_id)
|
||||
{
|
||||
return tool_data->get_code_object_info(_code_object_id);
|
||||
}
|
||||
|
||||
// Implementation of rocprofiler_callback_tracing_operation_args_cb_t
|
||||
int
|
||||
save_args(rocprofiler_callback_tracing_kind_t /*kind*/, int32_t /*operation*/,
|
||||
@@ -283,6 +296,22 @@ save_args(rocprofiler_callback_tracing_kind_t /*kind*/, int32_t /*operation*/,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Additional implementation of rocprofiler_callback_tracing_operation_args_cb_t
|
||||
// for iterating through arguments in a callback for rocpd_arg table in database
|
||||
int
|
||||
iterate_args_callback(rocprofiler_callback_tracing_kind_t /*kind*/, int32_t /*operation*/,
|
||||
uint32_t arg_number, const void* const /*arg_value_addr*/,
|
||||
int32_t /*arg_indirection_count*/, const char* arg_type,
|
||||
const char* arg_name, const char* arg_value_str,
|
||||
int32_t /*arg_dereference_count*/, void* data)
|
||||
{
|
||||
auto* _data = static_cast<function_args_t*>(data);
|
||||
if(arg_type && arg_name && arg_value_str)
|
||||
_data->emplace_back(
|
||||
argument_info{ arg_number, demangle(arg_type), arg_name, arg_value_str });
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto&
|
||||
get_marker_pushed_ranges()
|
||||
{
|
||||
@@ -299,6 +328,294 @@ get_marker_started_ranges()
|
||||
return _v;
|
||||
}
|
||||
|
||||
template <typename Tp, typename... Args>
|
||||
Tp*
|
||||
as_pointer(Args&&... _args)
|
||||
{
|
||||
return new Tp{ std::forward<Args>(_args)... };
|
||||
}
|
||||
|
||||
template <typename... Tp>
|
||||
void
|
||||
consume_args(Tp&&...)
|
||||
{}
|
||||
|
||||
auto
|
||||
get_backtrace(std::optional<std::vector<tim::unwind::processed_entry>>& _bt_data)
|
||||
{
|
||||
auto backtrace = ::rocpd::json::create();
|
||||
if(_bt_data && !_bt_data->empty())
|
||||
{
|
||||
const std::string _unk = "??";
|
||||
size_t _bt_cnt = 0;
|
||||
for(const auto& itr : *_bt_data)
|
||||
{
|
||||
auto _linfo = itr.lineinfo.get();
|
||||
const auto* _func = (itr.name.empty()) ? &_unk : &itr.name;
|
||||
const auto* _loc = (_linfo && !_linfo.location.empty())
|
||||
? &_linfo.location
|
||||
: ((itr.location.empty()) ? &_unk : &itr.location);
|
||||
auto _line =
|
||||
(_linfo && _linfo.line > 0)
|
||||
? join("", _linfo.line)
|
||||
: ((itr.lineno == 0) ? std::string{ "?" } : join("", itr.lineno));
|
||||
auto _entry = join("", demangle(*_func), " @ ",
|
||||
join(':', ::basename(_loc->c_str()), _line));
|
||||
backtrace->set(join("", "frame#", _bt_cnt++), _entry);
|
||||
}
|
||||
}
|
||||
return backtrace;
|
||||
}
|
||||
|
||||
template <typename CorrelationIdType>
|
||||
uint64_t
|
||||
get_parent_stack_id([[maybe_unused]] const CorrelationIdType& correlation_id)
|
||||
{
|
||||
#if(ROCPROFILER_VERSION >= 700)
|
||||
if constexpr(std::is_same_v<rocprofiler_correlation_id_t, CorrelationIdType>)
|
||||
{
|
||||
return correlation_id.ancestor;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
auto
|
||||
get_extdata(const rocprofiler_callback_tracing_record_t& record)
|
||||
{
|
||||
constexpr auto message_key = "message";
|
||||
auto args = callback_arg_array_t{};
|
||||
auto extdata = ::rocpd::json::create();
|
||||
|
||||
rocprofiler_iterate_callback_tracing_kind_operation_args(record, save_args, 2, &args);
|
||||
|
||||
for(auto [key, val] : args)
|
||||
{
|
||||
if(key == message_key)
|
||||
{
|
||||
extdata->set(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
return extdata;
|
||||
}
|
||||
|
||||
struct scope_destructor
|
||||
{
|
||||
/// \fn scope_destructor(FuncT&& _fini, InitT&& _init)
|
||||
/// \tparam FuncT "std::function<void()> or void (*)()"
|
||||
/// \tparam InitT "std::function<void()> or void (*)()"
|
||||
/// \param _fini Function to execute when object is destroyed
|
||||
/// \param _init Function to execute when object is created (optional)
|
||||
///
|
||||
/// \brief Provides a utility to perform an operation when exiting a scope.
|
||||
template <typename FuncT, typename InitT = void (*)()>
|
||||
scope_destructor(FuncT&& _fini, InitT&& _init = []() {});
|
||||
|
||||
~scope_destructor() { m_functor(); }
|
||||
|
||||
// delete copy operations
|
||||
scope_destructor(const scope_destructor&) = delete;
|
||||
scope_destructor& operator=(const scope_destructor&) = delete;
|
||||
|
||||
// allow move operations
|
||||
scope_destructor(scope_destructor&& rhs) noexcept;
|
||||
scope_destructor& operator=(scope_destructor&& rhs) noexcept;
|
||||
|
||||
private:
|
||||
std::function<void()> m_functor = []() {};
|
||||
};
|
||||
|
||||
template <typename FuncT, typename InitT>
|
||||
scope_destructor::scope_destructor(FuncT&& _fini, InitT&& _init)
|
||||
: m_functor{ std::forward<FuncT>(_fini) }
|
||||
{
|
||||
_init();
|
||||
}
|
||||
|
||||
inline scope_destructor::scope_destructor(scope_destructor&& rhs) noexcept
|
||||
: m_functor{ std::move(rhs.m_functor) }
|
||||
{
|
||||
rhs.m_functor = []() {};
|
||||
}
|
||||
|
||||
inline scope_destructor&
|
||||
scope_destructor::operator=(scope_destructor&& rhs) noexcept
|
||||
{
|
||||
if(this != &rhs)
|
||||
{
|
||||
m_functor = std::move(rhs.m_functor);
|
||||
rhs.m_functor = []() {};
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
using kernel_rename_stack_t = std::stack<uint64_t>;
|
||||
|
||||
thread_local auto thread_dispatch_rename = as_pointer<kernel_rename_stack_t>();
|
||||
thread_local auto thread_dispatch_rename_dtor = scope_destructor{ []() {
|
||||
delete thread_dispatch_rename;
|
||||
thread_dispatch_rename = nullptr;
|
||||
} };
|
||||
|
||||
template <typename Category>
|
||||
void
|
||||
cache_category()
|
||||
{
|
||||
trace_cache::get_metadata_registry().add_string(trait::name<Category>::value);
|
||||
}
|
||||
|
||||
void
|
||||
cache_add_thread_info(uint64_t tid)
|
||||
{
|
||||
trace_cache::get_metadata_registry().add_thread_info(
|
||||
{ getppid(), getpid(), tid, 0, 0, "{}" });
|
||||
}
|
||||
|
||||
void
|
||||
cache_add_track(const char* track_name, uint64_t tid)
|
||||
{
|
||||
trace_cache::get_metadata_registry().add_track({ track_name, tid, "{}" });
|
||||
}
|
||||
|
||||
size_t
|
||||
get_mem_copy_dst_address(
|
||||
[[maybe_unused]] const rocprofiler_buffer_tracing_memory_copy_record_t& record)
|
||||
{
|
||||
#if(ROCPROFILER_VERSION >= 700)
|
||||
return record.dst_address.value;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t
|
||||
get_mem_copy_src_address(
|
||||
[[maybe_unused]] const rocprofiler_buffer_tracing_memory_copy_record_t& record)
|
||||
{
|
||||
#if(ROCPROFILER_VERSION >= 700)
|
||||
return record.src_address.value;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if(ROCPROFILER_VERSION >= 600)
|
||||
size_t
|
||||
get_mem_alloc_address(
|
||||
[[maybe_unused]] const rocprofiler_buffer_tracing_memory_allocation_record_t& record)
|
||||
{
|
||||
# if(ROCPROFILER_VERSION >= 700)
|
||||
return record.address.value;
|
||||
# else
|
||||
return static_cast<size_t>(record.address.handle);
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// clang-format off
|
||||
void
|
||||
cache_region(const rocprofiler_callback_tracing_record_t* record,
|
||||
const rocprofiler_timestamp_t start_timestamp,
|
||||
const rocprofiler_timestamp_t end_timestamp, const std::string& call_stack,
|
||||
const std::string& args_str, const std::string& category)
|
||||
|
||||
{
|
||||
trace_cache::get_buffer_storage().store(
|
||||
trace_cache::entry_type::region,
|
||||
record->thread_id,
|
||||
static_cast<int32_t>(record->kind),
|
||||
static_cast<int32_t>(record->operation),
|
||||
record->correlation_id.internal,
|
||||
get_parent_stack_id(record->correlation_id),
|
||||
start_timestamp,
|
||||
end_timestamp,
|
||||
call_stack.c_str(),
|
||||
args_str.c_str(),
|
||||
category.c_str());
|
||||
}
|
||||
|
||||
void
|
||||
cache_kernel_dispatch(rocprofiler_buffer_tracing_kernel_dispatch_record_t* record)
|
||||
{
|
||||
auto stream_handle = get_stream_id(record).handle;
|
||||
auto queue_handle = record->dispatch_info.queue_id.handle;
|
||||
|
||||
trace_cache::get_metadata_registry().add_queue(queue_handle);
|
||||
trace_cache::get_metadata_registry().add_stream(stream_handle);
|
||||
|
||||
trace_cache::get_buffer_storage().store(
|
||||
trace_cache::entry_type::kernel_dispatch,
|
||||
record->start_timestamp,
|
||||
record->end_timestamp,
|
||||
record->thread_id,
|
||||
record->dispatch_info.agent_id.handle,
|
||||
record->dispatch_info.kernel_id,
|
||||
record->dispatch_info.dispatch_id,
|
||||
record->dispatch_info.queue_id.handle,
|
||||
record->correlation_id.internal,
|
||||
get_parent_stack_id(record->correlation_id),
|
||||
record->dispatch_info.private_segment_size,
|
||||
record->dispatch_info.group_segment_size,
|
||||
record->dispatch_info.workgroup_size.x,
|
||||
record->dispatch_info.workgroup_size.y,
|
||||
record->dispatch_info.workgroup_size.z,
|
||||
record->dispatch_info.grid_size.x,
|
||||
record->dispatch_info.grid_size.y,
|
||||
record->dispatch_info.grid_size.z,
|
||||
stream_handle);
|
||||
}
|
||||
|
||||
void
|
||||
cache_memory_copy(rocprofiler_buffer_tracing_memory_copy_record_t* record)
|
||||
{
|
||||
auto stream_handle = get_stream_id(record).handle;
|
||||
|
||||
trace_cache::get_buffer_storage().store(
|
||||
trace_cache::entry_type::memory_copy,
|
||||
record->start_timestamp,
|
||||
record->end_timestamp,
|
||||
record->thread_id,
|
||||
record->dst_agent_id.handle,
|
||||
record->src_agent_id.handle,
|
||||
static_cast<int32_t>(record->kind),
|
||||
static_cast<int32_t>(record->operation),
|
||||
record->bytes,
|
||||
record->correlation_id.internal,
|
||||
get_parent_stack_id(record->correlation_id),
|
||||
get_mem_copy_dst_address(*record),
|
||||
get_mem_copy_src_address(*record),
|
||||
stream_handle);
|
||||
}
|
||||
|
||||
#if (ROCPROFILER_VERSION >= 600)
|
||||
void
|
||||
cache_memory_allocation(rocprofiler_buffer_tracing_memory_allocation_record_t* record)
|
||||
{
|
||||
auto stream_handle = get_stream_id(record).handle;
|
||||
|
||||
trace_cache::get_metadata_registry().add_stream(stream_handle);
|
||||
trace_cache::get_buffer_storage().store(
|
||||
trace_cache::entry_type::memory_alloc,
|
||||
record->start_timestamp,
|
||||
record->end_timestamp,
|
||||
record->thread_id,
|
||||
record->agent_id.handle,
|
||||
static_cast<int32_t>(record->kind),
|
||||
static_cast<int32_t>(record->operation),
|
||||
record->allocation_size,
|
||||
record->correlation_id.internal,
|
||||
get_parent_stack_id(record->correlation_id),
|
||||
get_mem_alloc_address(*record),
|
||||
stream_handle);
|
||||
}
|
||||
#endif
|
||||
// clang-format on
|
||||
template <typename CategoryT>
|
||||
void
|
||||
tool_tracing_callback_start(CategoryT, rocprofiler_callback_tracing_record_t record,
|
||||
@@ -391,7 +708,8 @@ tool_tracing_callback_stop(
|
||||
{
|
||||
ROCPROFSYS_CONDITIONAL_ABORT_F(
|
||||
get_marker_started_ranges().empty(),
|
||||
"roctxRangeStop does not have corresponding roctxRangeStart on "
|
||||
"roctxRangeStop does not have corresponding roctxRangeStart "
|
||||
"on "
|
||||
"this thread");
|
||||
|
||||
auto _hash = get_marker_started_ranges().back().first;
|
||||
@@ -473,8 +791,9 @@ tool_tracing_callback_stop(
|
||||
join(':', ::basename(_loc->c_str()), _line));
|
||||
if(_bt_cnt < 10)
|
||||
{
|
||||
// Prepend zero for better ordering in UI. Only one zero
|
||||
// is ever necessary since stack depth is limited to 16.
|
||||
// Prepend zero for better ordering in UI. Only one
|
||||
// zero is ever necessary since stack depth is limited
|
||||
// to 16.
|
||||
tracing::add_perfetto_annotation(
|
||||
ctx, join("", "frame#0", _bt_cnt++), _entry);
|
||||
}
|
||||
@@ -493,6 +812,33 @@ tool_tracing_callback_stop(
|
||||
tracing::add_perfetto_annotation(ctx, "end_ns", _end_ts);
|
||||
});
|
||||
}
|
||||
|
||||
// Insert callback trace into database
|
||||
auto args = function_args_t{};
|
||||
|
||||
rocprofiler_iterate_callback_tracing_kind_operation_args(
|
||||
record, iterate_args_callback, 2, &args);
|
||||
|
||||
auto call_stack = get_backtrace(_bt_data);
|
||||
uint64_t _beg_ts = user_data->value;
|
||||
uint64_t _end_ts = ts;
|
||||
|
||||
{
|
||||
cache_category<CategoryT>();
|
||||
cache_add_thread_info(record.thread_id);
|
||||
std::string args_str;
|
||||
|
||||
std::for_each(args.begin(), args.end(), [&args_str](const argument_info& arg) {
|
||||
const auto* delimiter = ";;";
|
||||
std::stringstream ss;
|
||||
ss << arg.arg_number << delimiter << arg.arg_type << delimiter << arg.arg_name
|
||||
<< delimiter << arg.arg_value << delimiter;
|
||||
args_str.append(ss.str());
|
||||
});
|
||||
|
||||
cache_region(&record, _beg_ts, _end_ts, call_stack->to_string(), args_str,
|
||||
trait::name<CategoryT>::value);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -535,6 +881,7 @@ tool_code_object_callback(rocprofiler_callback_tracing_record_t record,
|
||||
_data.emplace_back(
|
||||
code_object_callback_record_t{ ts, record, data_v });
|
||||
});
|
||||
trace_cache::get_metadata_registry().add_code_object(data_v);
|
||||
}
|
||||
else if(record.operation ==
|
||||
ROCPROFILER_CODE_OBJECT_DEVICE_KERNEL_SYMBOL_REGISTER)
|
||||
@@ -545,6 +892,7 @@ tool_code_object_callback(rocprofiler_callback_tracing_record_t record,
|
||||
_data.emplace_back(
|
||||
new kernel_symbol_callback_record_t{ ts, record, data_v });
|
||||
});
|
||||
trace_cache::get_metadata_registry().add_kernel_symbol(data_v);
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -635,7 +983,6 @@ tool_tracing_callback(rocprofiler_callback_tracing_record_t record,
|
||||
case ROCPROFILER_CALLBACK_TRACING_MEMORY_COPY:
|
||||
#if(ROCPROFILER_VERSION >= 600)
|
||||
case ROCPROFILER_CALLBACK_TRACING_OMPT:
|
||||
case ROCPROFILER_CALLBACK_TRACING_MEMORY_ALLOCATION:
|
||||
case ROCPROFILER_CALLBACK_TRACING_RUNTIME_INITIALIZATION:
|
||||
#endif
|
||||
#if(ROCPROFILER_VERSION >= 700)
|
||||
@@ -646,6 +993,12 @@ tool_tracing_callback(rocprofiler_callback_tracing_record_t record,
|
||||
record.kind);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
ROCPROFSYS_CI_ABORT(true, "Unhandled callback record: \n\t%s\n",
|
||||
info.str().c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(record.phase == ROCPROFILER_CALLBACK_PHASE_EXIT)
|
||||
@@ -657,8 +1010,11 @@ tool_tracing_callback(rocprofiler_callback_tracing_record_t record,
|
||||
constexpr bool bt_with_signal_frame = true;
|
||||
|
||||
auto _bt_data = std::optional<backtrace_entry_vec_t>{};
|
||||
auto use_perfetto =
|
||||
(config::get_use_perfetto() && config::get_perfetto_annotations());
|
||||
auto use_rocpd = config::get_use_rocpd();
|
||||
|
||||
if(config::get_use_perfetto() && config::get_perfetto_annotations() &&
|
||||
if((use_perfetto || use_rocpd) &&
|
||||
tool_data->backtrace_operations.at(record.kind).count(record.operation) > 0)
|
||||
{
|
||||
auto _backtrace = tim::get_unw_stack<bt_stack_depth, bt_ignore_depth,
|
||||
@@ -735,7 +1091,6 @@ tool_tracing_callback(rocprofiler_callback_tracing_record_t record,
|
||||
case ROCPROFILER_CALLBACK_TRACING_MEMORY_COPY:
|
||||
#if(ROCPROFILER_VERSION >= 600)
|
||||
case ROCPROFILER_CALLBACK_TRACING_OMPT:
|
||||
case ROCPROFILER_CALLBACK_TRACING_MEMORY_ALLOCATION:
|
||||
case ROCPROFILER_CALLBACK_TRACING_RUNTIME_INITIALIZATION:
|
||||
#endif
|
||||
#if(ROCPROFILER_VERSION >= 700)
|
||||
@@ -746,27 +1101,41 @@ tool_tracing_callback(rocprofiler_callback_tracing_record_t record,
|
||||
record.kind);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
ROCPROFSYS_CI_ABORT(true, "Unhandled callback record\n\t%s\n",
|
||||
info.str().c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(record.phase == ROCPROFILER_CALLBACK_PHASE_NONE)
|
||||
{
|
||||
if(record.kind == ROCPROFILER_CALLBACK_TRACING_KERNEL_DISPATCH &&
|
||||
record.operation == ROCPROFILER_KERNEL_DISPATCH_COMPLETE)
|
||||
switch(record.kind)
|
||||
{
|
||||
auto* _data =
|
||||
static_cast<rocprofiler_callback_tracing_kernel_dispatch_data_t*>(
|
||||
record.payload);
|
||||
case ROCPROFILER_CALLBACK_TRACING_KERNEL_DISPATCH:
|
||||
{
|
||||
if(record.operation == ROCPROFILER_KERNEL_DISPATCH_COMPLETE)
|
||||
{
|
||||
auto* _data =
|
||||
static_cast<rocprofiler_callback_tracing_kernel_dispatch_data_t*>(
|
||||
record.payload);
|
||||
|
||||
// save for post-processing
|
||||
get_kernel_dispatch_timestamps().emplace(
|
||||
_data->dispatch_info.dispatch_id,
|
||||
timing_interval{ _data->start_timestamp, _data->end_timestamp });
|
||||
}
|
||||
else
|
||||
{
|
||||
ROCPROFSYS_WARNING_F(
|
||||
1, "tool_tracing_callback: unhandled PHASE_NONE callback record\n\t%s\n",
|
||||
info.str().c_str());
|
||||
// save for post-processing
|
||||
get_kernel_dispatch_timestamps().emplace(
|
||||
_data->dispatch_info.dispatch_id,
|
||||
timing_interval{ _data->start_timestamp, _data->end_timestamp });
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
ROCPROFSYS_WARNING_F(1,
|
||||
"tool_tracing_callback: unhandled PHASE_NONE "
|
||||
"callback record\n\t%s\n",
|
||||
info.str().c_str());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -820,10 +1189,20 @@ tool_tracing_buffered(rocprofiler_context_id_t /*context*/,
|
||||
uint64_t _stream_id = get_stream_id(record).handle;
|
||||
if(_stream_id == 0)
|
||||
{
|
||||
// kernel is not associated with a HIP stream
|
||||
// kernel_dispatch is not associated with a HIP stream
|
||||
_group_by_queue = true;
|
||||
}
|
||||
|
||||
{
|
||||
cache_category<category::rocm_kernel_dispatch>();
|
||||
cache_add_thread_info(record->thread_id);
|
||||
cache_add_track(JOIN("", "GPU Kernel Dispatch [", _agent->device_id,
|
||||
"] Queue ", _queue_id.handle)
|
||||
.c_str(),
|
||||
record->thread_id);
|
||||
cache_kernel_dispatch(record);
|
||||
}
|
||||
|
||||
if(get_use_timemory())
|
||||
{
|
||||
const auto& _tinfo = thread_info::get(record->thread_id, SystemTID);
|
||||
@@ -937,6 +1316,20 @@ tool_tracing_buffered(rocprofiler_context_id_t /*context*/,
|
||||
_group_by_queue = true;
|
||||
}
|
||||
|
||||
{
|
||||
size_t thread_idx = record->thread_id;
|
||||
std::string track_name;
|
||||
|
||||
track_name =
|
||||
JOIN("", "GPU Memory Copy to Agent [",
|
||||
_dst_agent->logical_node_id, "] Thread ", thread_idx);
|
||||
|
||||
cache_category<category::rocm_memory_copy>();
|
||||
cache_add_track(track_name.c_str(), record->thread_id);
|
||||
|
||||
cache_memory_copy(record);
|
||||
}
|
||||
|
||||
if(get_use_timemory())
|
||||
{
|
||||
const auto& _tinfo = thread_info::get(record->thread_id, SystemTID);
|
||||
@@ -1005,6 +1398,26 @@ tool_tracing_buffered(rocprofiler_context_id_t /*context*/,
|
||||
}
|
||||
}
|
||||
}
|
||||
#if(ROCPROFILER_VERSION >= 600)
|
||||
else if(header->kind == ROCPROFILER_BUFFER_TRACING_MEMORY_ALLOCATION)
|
||||
{
|
||||
auto* record =
|
||||
static_cast<rocprofiler_buffer_tracing_memory_allocation_record_t*>(
|
||||
header->payload);
|
||||
|
||||
{
|
||||
cache_category<category::rocm_memory_allocate>();
|
||||
cache_add_thread_info(record->thread_id);
|
||||
cache_memory_allocation(record);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else if(header->kind == ROCPROFILER_BUFFER_TRACING_HSA_CORE_API ||
|
||||
header->kind == ROCPROFILER_BUFFER_TRACING_HSA_AMD_EXT_API)
|
||||
{
|
||||
// Not handling those buffered events
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
ROCPROFSYS_THROW(
|
||||
@@ -1098,10 +1511,10 @@ counter_record_callback(rocprofiler_dispatch_counting_service_data_t dispatch_da
|
||||
ROCPROFSYS_CONDITIONAL_ABORT_F(
|
||||
!_agent, "unable to find tool agent for agent (id=%zu)\n",
|
||||
_agent_id.handle);
|
||||
ROCPROFSYS_CONDITIONAL_ABORT_F(
|
||||
!_info,
|
||||
"unable to find counter info for counter (id=%zu) on agent (id=%zu)\n",
|
||||
itr.first.handle, _agent_id.handle);
|
||||
ROCPROFSYS_CONDITIONAL_ABORT_F(!_info,
|
||||
"unable to find counter info for counter "
|
||||
"(id=%zu) on agent (id=%zu)\n",
|
||||
itr.first.handle, _agent_id.handle);
|
||||
|
||||
auto _dev_id = static_cast<uint32_t>(_agent->device_id);
|
||||
|
||||
@@ -1159,7 +1572,6 @@ void
|
||||
flush()
|
||||
{
|
||||
if(!tool_data) return;
|
||||
|
||||
for(auto itr : tool_data->get_buffers())
|
||||
{
|
||||
if(itr.handle > 0)
|
||||
@@ -1268,6 +1680,24 @@ tool_init(rocprofiler_client_finalize_t fini_func, void* user_data)
|
||||
_data->primary_ctx, ROCPROFILER_CALLBACK_TRACING_CODE_OBJECT, nullptr, 0,
|
||||
tool_code_object_callback, _data));
|
||||
|
||||
auto external_corr_id_request_kinds =
|
||||
std::array<rocprofiler_external_correlation_id_request_kind_t, 3>{
|
||||
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_KERNEL_DISPATCH,
|
||||
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_MEMORY_COPY,
|
||||
#if(ROCPROFILER_VERSION >= 600)
|
||||
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_MEMORY_ALLOCATION
|
||||
#endif
|
||||
};
|
||||
|
||||
// Insert the default stream and queue info to ensure that the default entry is
|
||||
{
|
||||
trace_cache::get_metadata_registry().add_stream(0);
|
||||
trace_cache::get_metadata_registry().add_queue(0);
|
||||
}
|
||||
// ROCPROFILER_CALL(rocprofiler_configure_callback_tracing_service(
|
||||
// _data->primary_ctx, ROCPROFILER_CALLBACK_TRACING_CODE_OBJECT, nullptr, 0,
|
||||
// tool_code_object_callback, _data));
|
||||
|
||||
for(auto itr : {
|
||||
ROCPROFILER_CALLBACK_TRACING_HSA_CORE_API,
|
||||
ROCPROFILER_CALLBACK_TRACING_HSA_AMD_EXT_API,
|
||||
@@ -1296,17 +1726,8 @@ tool_init(rocprofiler_client_finalize_t fini_func, void* user_data)
|
||||
}
|
||||
}
|
||||
|
||||
constexpr auto buffer_size = 8192;
|
||||
constexpr auto watermark = 7936;
|
||||
|
||||
// Configure external correlation id request service for kernel dispatch
|
||||
// and memory copy.
|
||||
|
||||
auto external_corr_id_request_kinds =
|
||||
std::array<rocprofiler_external_correlation_id_request_kind_t, 2>{
|
||||
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_KERNEL_DISPATCH,
|
||||
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_MEMORY_COPY
|
||||
};
|
||||
constexpr auto buffer_size = 16 * 4096;
|
||||
constexpr auto watermark = 15 * 4096;
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_configure_external_correlation_id_request_service(
|
||||
_data->primary_ctx, external_corr_id_request_kinds.data(),
|
||||
@@ -1334,7 +1755,8 @@ tool_init(rocprofiler_client_finalize_t fini_func, void* user_data)
|
||||
_data->primary_ctx, ROCPROFILER_BUFFER_TRACING_KERNEL_DISPATCH, nullptr, 0,
|
||||
_data->kernel_dispatch_buffer));
|
||||
}
|
||||
|
||||
// ROCPROFILER_BUFFER_TRACING_HSA_CORE_API, ///< @see
|
||||
// ::rocprofiler_hsa_core_api_id_t ROCPROFILER_BUFFER_TRACING_HSA_AMD_EXT_API,
|
||||
if(_buffered_domain.count(ROCPROFILER_BUFFER_TRACING_MEMORY_COPY) > 0)
|
||||
{
|
||||
ROCPROFILER_CALL(rocprofiler_create_buffer(
|
||||
@@ -1347,19 +1769,39 @@ tool_init(rocprofiler_client_finalize_t fini_func, void* user_data)
|
||||
_data->memory_copy_buffer));
|
||||
}
|
||||
|
||||
#if(ROCPROFILER_VERSION >= 600)
|
||||
if(_buffered_domain.count(ROCPROFILER_BUFFER_TRACING_MEMORY_ALLOCATION) > 0)
|
||||
{
|
||||
ROCPROFILER_CALL(rocprofiler_create_buffer(
|
||||
_data->primary_ctx, buffer_size, watermark,
|
||||
ROCPROFILER_BUFFER_POLICY_LOSSLESS, tool_tracing_buffered, tool_data,
|
||||
&_data->memory_alloc_buffer));
|
||||
if(_data->memory_alloc_buffer.handle == 0UL)
|
||||
{
|
||||
ROCPROFSYS_CI_ABORT(true, "Failed to create memory allocation buffer\n");
|
||||
}
|
||||
auto _ops =
|
||||
rocprofiler_sdk::get_operations(ROCPROFILER_BUFFER_TRACING_MEMORY_ALLOCATION);
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_configure_buffer_tracing_service(
|
||||
_data->primary_ctx, ROCPROFILER_BUFFER_TRACING_MEMORY_ALLOCATION, nullptr, 0,
|
||||
_data->memory_alloc_buffer));
|
||||
}
|
||||
#endif
|
||||
|
||||
if(!_counter_events.empty())
|
||||
{
|
||||
for(const auto& itr : _data->gpu_agents)
|
||||
{
|
||||
const auto& _agent_id = rocprofiler_agent_id_t{ itr.agent->handle };
|
||||
_data->agent_events.emplace(
|
||||
itr.agent->id,
|
||||
create_agent_profile(itr.agent->id, _counter_events, _data));
|
||||
_agent_id, create_agent_profile(_agent_id, _counter_events, _data));
|
||||
}
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_create_context(&_data->counter_ctx));
|
||||
|
||||
auto _operations = std::array<rocprofiler_tracing_operation_t, 1>{
|
||||
ROCPROFILER_KERNEL_DISPATCH_COMPLETE
|
||||
ROCPROFILER_KERNEL_DISPATCH_COMPLETE,
|
||||
};
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_configure_callback_tracing_service(
|
||||
@@ -1393,8 +1835,9 @@ tool_init(rocprofiler_client_finalize_t fini_func, void* user_data)
|
||||
}
|
||||
}
|
||||
|
||||
// throwaway context for handling the profiler control API. If primary_ctx were used,
|
||||
// we would get profiler pause callback but never get profiler resume callback
|
||||
// throwaway context for handling the profiler control API. If primary_ctx were
|
||||
// used, we would get profiler pause callback but never get profiler resume
|
||||
// callback
|
||||
{
|
||||
auto _local_ctx = rocprofiler_context_id_t{ 0 };
|
||||
ROCPROFILER_CALL(rocprofiler_create_context(&_local_ctx));
|
||||
@@ -1405,8 +1848,8 @@ tool_init(rocprofiler_client_finalize_t fini_func, void* user_data)
|
||||
|
||||
if(!is_valid(_data->primary_ctx))
|
||||
{
|
||||
// notify rocprofiler that initialization failed and all the contexts, buffers,
|
||||
// etc. created should be ignored
|
||||
// notify rocprofiler that initialization failed and all the contexts,
|
||||
// buffers, etc. created should be ignored
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1454,13 +1897,7 @@ tool_fini(void* callback_data)
|
||||
|
||||
void
|
||||
setup()
|
||||
{
|
||||
if(int status = 0;
|
||||
rocprofiler_is_initialized(&status) == ROCPROFILER_STATUS_SUCCESS && status == 0)
|
||||
{
|
||||
ROCPROFILER_CALL(rocprofiler_force_configure(&rocprofiler_configure));
|
||||
}
|
||||
}
|
||||
{}
|
||||
|
||||
void
|
||||
shutdown()
|
||||
|
||||
Ссылка в новой задаче
Block a user