rocprofv3: PC Sampling Support (#14)
* Adding tool pc sampling support
Fixing merge issue
tool support on SDKupdates
link amd-comgr
Sanitizer failure fix
fix format
Addressing review comments
misc fix
Adding dispatch id to the CSV output
AddingCHANGELOG
[ROCProfV3][PC Sampling] Initial ROCProfV3 PC sampling tests for JSON and CSV formats (#17)
ROCProfV3 initial tests for JSON and CSV output.
Simple kernels that simplify the verification of samples to instruction decoding
has been introduced.
removing option to enable pc sampling explicitly
Adding documentation
no pc-sampling option in tests anymore
Addressing review comments
Updating docs
an option for choosing whether all units must be sampled
try ignoring PC sampling tests (#36)
* run pc-sampling tests on MI2xx runners
* use v_fmac_f32 instead of s_nop 0 in tests
* fixing docs
[ROCm/rocprofiler-sdk commit: 50b185b9ac]
This commit is contained in:
committed by
GitHub
parent
5ec8560fab
commit
9cfbfb5060
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "counter_info.hpp"
|
||||
#include "generator.hpp"
|
||||
#include "pc_sample_transform.hpp"
|
||||
#include "statistics.hpp"
|
||||
#include "tmp_file_buffer.hpp"
|
||||
|
||||
@@ -159,5 +160,8 @@ using memory_allocation_buffered_output_t =
|
||||
using counter_records_buffered_output_t =
|
||||
::rocprofiler::tool::buffered_output<rocprofiler::tool::serialized_counter_record_t,
|
||||
domain_type::COUNTER_VALUES>;
|
||||
using pc_sampling_host_trap_buffered_output_t =
|
||||
buffered_output<rocprofiler::tool::rocprofiler_tool_pc_sampling_host_trap_record_t,
|
||||
domain_type::PC_SAMPLING_HOST_TRAP>;
|
||||
} // namespace tool
|
||||
} // namespace rocprofiler
|
||||
|
||||
@@ -99,17 +99,18 @@ struct csv_encoder
|
||||
}
|
||||
};
|
||||
|
||||
using api_csv_encoder = csv_encoder<7>;
|
||||
using agent_info_csv_encoder = csv_encoder<53>;
|
||||
using kernel_trace_csv_encoder = csv_encoder<18>;
|
||||
using counter_collection_csv_encoder = csv_encoder<18>;
|
||||
using memory_copy_csv_encoder = csv_encoder<7>;
|
||||
using memory_allocation_csv_encoder = csv_encoder<8>;
|
||||
using marker_csv_encoder = csv_encoder<7>;
|
||||
using list_basic_metrics_csv_encoder = csv_encoder<5>;
|
||||
using list_derived_metrics_csv_encoder = csv_encoder<5>;
|
||||
using scratch_memory_encoder = csv_encoder<8>;
|
||||
using stats_csv_encoder = csv_encoder<8>;
|
||||
using api_csv_encoder = csv_encoder<7>;
|
||||
using agent_info_csv_encoder = csv_encoder<53>;
|
||||
using kernel_trace_csv_encoder = csv_encoder<18>;
|
||||
using counter_collection_csv_encoder = csv_encoder<18>;
|
||||
using memory_copy_csv_encoder = csv_encoder<7>;
|
||||
using memory_allocation_csv_encoder = csv_encoder<8>;
|
||||
using marker_csv_encoder = csv_encoder<7>;
|
||||
using list_basic_metrics_csv_encoder = csv_encoder<5>;
|
||||
using list_derived_metrics_csv_encoder = csv_encoder<5>;
|
||||
using scratch_memory_encoder = csv_encoder<8>;
|
||||
using stats_csv_encoder = csv_encoder<8>;
|
||||
using pc_sampling_host_trap_csv_encoder = csv_encoder<6>;
|
||||
} // namespace csv
|
||||
} // namespace tool
|
||||
} // namespace rocprofiler
|
||||
|
||||
Executable → Regular
+4
@@ -57,6 +57,10 @@ DEFINE_BUFFER_TYPE_NAME(MEMORY_ALLOCATION,
|
||||
"memory_allocation",
|
||||
"memory_allocation_stats")
|
||||
DEFINE_BUFFER_TYPE_NAME(COUNTER_VALUES, "COUNTER_VALUES", "counter_values", "no_filename")
|
||||
DEFINE_BUFFER_TYPE_NAME(PC_SAMPLING_HOST_TRAP,
|
||||
"PC_SAMPLING_HOST_TRAP",
|
||||
"pc_sampling_host_trap",
|
||||
"pc_sampling_host_trap_stats")
|
||||
|
||||
#undef DEFINE_BUFFER_TYPE_NAME
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ enum class domain_type
|
||||
RCCL,
|
||||
MEMORY_ALLOCATION,
|
||||
COUNTER_VALUES,
|
||||
PC_SAMPLING_HOST_TRAP,
|
||||
LAST,
|
||||
};
|
||||
|
||||
|
||||
Executable → Regular
+59
@@ -717,6 +717,65 @@ generate_csv(const output_config& cfg,
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
generate_csv(const output_config& cfg,
|
||||
const metadata& tool_metadata,
|
||||
const generator<rocprofiler_tool_pc_sampling_host_trap_record_t>& data,
|
||||
const stats_entry_t& stats)
|
||||
{
|
||||
if(data.empty()) return;
|
||||
|
||||
if(cfg.stats && stats)
|
||||
write_stats(get_stats_output_file(cfg, domain_type::PC_SAMPLING_HOST_TRAP), stats.entries);
|
||||
|
||||
auto ofs = tool::csv_output_file{cfg,
|
||||
domain_type::PC_SAMPLING_HOST_TRAP,
|
||||
tool::csv::pc_sampling_host_trap_csv_encoder{},
|
||||
{"Sample_Timestamp",
|
||||
"Exec_Mask",
|
||||
"Dispatch_Id",
|
||||
"Instruction",
|
||||
"Instruction_Comment",
|
||||
"Correlation_Id"}};
|
||||
for(auto ditr : data)
|
||||
{
|
||||
for(const auto& record : data.get(ditr))
|
||||
{
|
||||
if(record.inst_index == -1)
|
||||
{
|
||||
auto row_ss = std::stringstream{};
|
||||
std::string inst_comment =
|
||||
"Unrecognized code object id, physical virtual address of PC:" +
|
||||
std::to_string(record.pc_sample_record.pc.code_object_offset);
|
||||
rocprofiler::tool::csv::pc_sampling_host_trap_csv_encoder::write_row(
|
||||
row_ss,
|
||||
record.pc_sample_record.timestamp,
|
||||
record.pc_sample_record.exec_mask,
|
||||
record.pc_sample_record.dispatch_id,
|
||||
"",
|
||||
inst_comment,
|
||||
record.pc_sample_record.correlation_id.internal);
|
||||
|
||||
ofs << row_ss.str();
|
||||
}
|
||||
else
|
||||
{
|
||||
auto row_ss = std::stringstream{};
|
||||
rocprofiler::tool::csv::pc_sampling_host_trap_csv_encoder::write_row(
|
||||
row_ss,
|
||||
record.pc_sample_record.timestamp,
|
||||
record.pc_sample_record.exec_mask,
|
||||
record.pc_sample_record.dispatch_id,
|
||||
tool_metadata.get_instruction(record.inst_index),
|
||||
tool_metadata.get_comment(record.inst_index),
|
||||
record.pc_sample_record.correlation_id.internal);
|
||||
|
||||
ofs << row_ss.str();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
generate_csv(const output_config& cfg,
|
||||
const metadata& /*tool_metadata*/,
|
||||
|
||||
@@ -92,6 +92,11 @@ generate_csv(const output_config&
|
||||
const metadata& tool_metadata,
|
||||
const generator<rocprofiler_buffer_tracing_memory_allocation_record_t>& data,
|
||||
const stats_entry_t& stats);
|
||||
void
|
||||
generate_csv(const output_config& cfg,
|
||||
const metadata& tool_metadata,
|
||||
const generator<rocprofiler_tool_pc_sampling_host_trap_record_t>& data,
|
||||
const stats_entry_t& stats);
|
||||
|
||||
void
|
||||
generate_csv(const output_config& cfg,
|
||||
|
||||
@@ -124,7 +124,13 @@ write_json(json_output& json_ar,
|
||||
json_ar.startNode();
|
||||
json_ar(cereal::make_nvp("callback_records", callback_name_info));
|
||||
json_ar(cereal::make_nvp("buffer_records", buffer_name_info));
|
||||
json_ar(
|
||||
cereal::make_nvp("pc_sample_instructions", tool_metadata.get_pc_sample_instructions()));
|
||||
json_ar(cereal::make_nvp("pc_sample_comments", tool_metadata.get_pc_sample_comments()));
|
||||
json_ar(cereal::make_nvp("marker_api", marker_msg_data));
|
||||
json_ar(
|
||||
cereal::make_nvp("pc_sample_instructions", tool_metadata.get_pc_sample_instructions()));
|
||||
json_ar(cereal::make_nvp("pc_sample_comments", tool_metadata.get_pc_sample_comments()));
|
||||
|
||||
{
|
||||
auto _extern_corr_id_strings = std::map<size_t, std::string>{};
|
||||
@@ -178,7 +184,8 @@ write_json(json_output& json_ar,
|
||||
generator<rocprofiler_buffer_tracing_marker_api_record_t> marker_api_gen,
|
||||
generator<rocprofiler_buffer_tracing_scratch_memory_record_t> scratch_memory_gen,
|
||||
generator<rocprofiler_buffer_tracing_rccl_api_record_t> rccl_api_gen,
|
||||
generator<rocprofiler_buffer_tracing_memory_allocation_record_t> memory_allocation_gen)
|
||||
generator<rocprofiler_buffer_tracing_memory_allocation_record_t> memory_allocation_gen,
|
||||
generator<rocprofiler_tool_pc_sampling_host_trap_record_t> pc_sampling_gen)
|
||||
|
||||
{
|
||||
// summary
|
||||
@@ -219,6 +226,7 @@ write_json(json_output& json_ar,
|
||||
json_ar(cereal::make_nvp("memory_copy", memory_copy_gen));
|
||||
json_ar(cereal::make_nvp("memory_allocation", memory_allocation_gen));
|
||||
json_ar(cereal::make_nvp("scratch_memory", scratch_memory_gen));
|
||||
json_ar(cereal::make_nvp("pc_sample_host_trap", pc_sampling_gen));
|
||||
json_ar.finishNode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@ write_json(json_output& json
|
||||
generator<rocprofiler_buffer_tracing_marker_api_record_t> marker_api_gen,
|
||||
generator<rocprofiler_buffer_tracing_scratch_memory_record_t> scratch_memory_gen,
|
||||
generator<rocprofiler_buffer_tracing_rccl_api_record_t> rccl_api_gen,
|
||||
generator<rocprofiler_buffer_tracing_memory_allocation_record_t> memory_allocation_gen);
|
||||
generator<rocprofiler_buffer_tracing_memory_allocation_record_t> memory_allocation_gen,
|
||||
generator<rocprofiler_tool_pc_sampling_host_trap_record_t> pc_sampling_gen);
|
||||
} // namespace tool
|
||||
} // namespace rocprofiler
|
||||
|
||||
@@ -411,5 +411,13 @@ generate_stats(const output_config& cfg,
|
||||
|
||||
if(cfg.stats_summary) generate_stats(cfg, _os, "SUMMARY", data_v, _indent);
|
||||
}
|
||||
|
||||
stats_entry_t
|
||||
generate_stats(const output_config& /* cfg*/,
|
||||
const metadata& /*tool_metadata*/,
|
||||
const generator<rocprofiler_tool_pc_sampling_host_trap_record_t>& /*data*/)
|
||||
{
|
||||
return stats_entry_t{};
|
||||
}
|
||||
} // namespace tool
|
||||
} // namespace rocprofiler
|
||||
|
||||
@@ -75,6 +75,10 @@ generate_stats(const output_config& cfg,
|
||||
const metadata& tool_metadata,
|
||||
const generator<rocprofiler_buffer_tracing_memory_allocation_record_t>& data);
|
||||
|
||||
stats_entry_t
|
||||
generate_stats(const output_config& cfg,
|
||||
const metadata& tool_metadata,
|
||||
const generator<rocprofiler_tool_pc_sampling_host_trap_record_t>& data);
|
||||
void
|
||||
generate_stats(const output_config& cfg,
|
||||
const metadata& tool_metadata,
|
||||
|
||||
@@ -47,6 +47,20 @@ dimensions_info_callback(rocprofiler_counter_id_t /*id*/,
|
||||
dimensions_info->emplace_back(dim_info[j]);
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
rocprofiler_status_t
|
||||
query_pc_sampling_configuration(const rocprofiler_pc_sampling_configuration_t* configs,
|
||||
long unsigned int num_config,
|
||||
void* user_data)
|
||||
{
|
||||
auto* avail_configs =
|
||||
static_cast<std::vector<rocprofiler_pc_sampling_configuration_t>*>(user_data);
|
||||
for(size_t i = 0; i < num_config; i++)
|
||||
{
|
||||
avail_configs->emplace_back(configs[i]);
|
||||
}
|
||||
return ROCPROFILER_STATUS_SUCCESS;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
kernel_symbol_info::kernel_symbol_info()
|
||||
@@ -78,7 +92,14 @@ metadata::metadata(inprocess)
|
||||
_gpu_agents.reserve(agents.size());
|
||||
for(auto& itr : agents)
|
||||
{
|
||||
if(itr.type == ROCPROFILER_AGENT_TYPE_GPU) _gpu_agents.emplace_back(&itr);
|
||||
if(itr.type == ROCPROFILER_AGENT_TYPE_GPU)
|
||||
{
|
||||
_gpu_agents.emplace_back(&itr);
|
||||
auto pc_configs = std::vector<rocprofiler_pc_sampling_configuration_t>{};
|
||||
rocprofiler_query_pc_sampling_agent_configurations(
|
||||
itr.id, query_pc_sampling_configuration, &pc_configs);
|
||||
agent_pc_sample_config_info.emplace(itr.id, pc_configs);
|
||||
}
|
||||
}
|
||||
|
||||
// make sure they are sorted by node id
|
||||
@@ -112,6 +133,7 @@ void metadata::init(inprocess)
|
||||
void* user_data) {
|
||||
auto* data_v = static_cast<agent_counter_info_map_t*>(user_data);
|
||||
data_v->emplace(id, counter_info_vec_t{});
|
||||
|
||||
for(size_t i = 0; i < num_counters; ++i)
|
||||
{
|
||||
auto _info = rocprofiler_counter_info_v0_t{};
|
||||
@@ -260,6 +282,17 @@ metadata::get_gpu_agents() const
|
||||
return _data;
|
||||
}
|
||||
|
||||
pc_sample_config_vec_t
|
||||
metadata::get_pc_sample_config_info(rocprofiler_agent_id_t _val) const
|
||||
{
|
||||
auto _ret = pc_sample_config_vec_t{};
|
||||
auto pc_sample_config = agent_pc_sample_config_info.at(_val);
|
||||
for(const auto& itr : pc_sample_config)
|
||||
_ret.emplace_back(itr);
|
||||
|
||||
return _ret;
|
||||
}
|
||||
|
||||
counter_info_vec_t
|
||||
metadata::get_counter_info() const
|
||||
{
|
||||
@@ -417,5 +450,62 @@ metadata::get_string_entry(size_t key) const
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int64_t
|
||||
metadata::get_instruction_index(rocprofiler_pc_t record)
|
||||
{
|
||||
inst_t ins;
|
||||
ins.code_object_id = record.code_object_id;
|
||||
ins.code_object_offset = record.code_object_offset;
|
||||
auto itr = indexes.find(ins);
|
||||
if(itr != indexes.end()) return itr->second;
|
||||
auto idx = instruction_decoder.size();
|
||||
auto pc_instruction = decode_instruction(record);
|
||||
instruction_decoder.emplace_back(pc_instruction->inst);
|
||||
instruction_comment.emplace_back(pc_instruction->comment);
|
||||
indexes.emplace(ins, idx);
|
||||
return idx;
|
||||
}
|
||||
|
||||
void
|
||||
metadata::add_decoder(rocprofiler_code_object_info_t* obj_data)
|
||||
{
|
||||
if(obj_data->storage_type == ROCPROFILER_CODE_OBJECT_STORAGE_TYPE_FILE)
|
||||
{
|
||||
decoder.wlock(
|
||||
[](auto& _decoder, rocprofiler_code_object_info_t* obj_data_v) {
|
||||
_decoder.addDecoder(obj_data_v->uri,
|
||||
obj_data_v->code_object_id,
|
||||
obj_data_v->load_delta,
|
||||
obj_data_v->load_size);
|
||||
},
|
||||
obj_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
decoder.wlock(
|
||||
[](auto& _decoder, rocprofiler_code_object_info_t* obj_data_v) {
|
||||
_decoder.addDecoder(
|
||||
// NOLINTBEGIN(performance-no-int-to-ptr)
|
||||
reinterpret_cast<const void*>(obj_data_v->memory_base),
|
||||
// NOLINTEND(performance-no-int-to-ptr)
|
||||
obj_data_v->memory_size,
|
||||
obj_data_v->code_object_id,
|
||||
obj_data_v->load_delta,
|
||||
obj_data_v->load_size);
|
||||
},
|
||||
obj_data);
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<instruction_t>
|
||||
metadata::decode_instruction(rocprofiler_pc_t pc)
|
||||
{
|
||||
return decoder.wlock(
|
||||
[](auto& _decoder, uint64_t id, uint64_t addr) { return _decoder.get(id, addr); },
|
||||
pc.code_object_id,
|
||||
pc.code_object_offset);
|
||||
}
|
||||
|
||||
} // namespace tool
|
||||
} // namespace rocprofiler
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "agent_info.hpp"
|
||||
#include "counter_info.hpp"
|
||||
#include "kernel_symbol_info.hpp"
|
||||
#include "pc_sample_transform.hpp"
|
||||
|
||||
#include "lib/common/container/small_vector.hpp"
|
||||
#include "lib/common/demangle.hpp"
|
||||
@@ -36,6 +37,7 @@
|
||||
#include <rocprofiler-sdk/callback_tracing.h>
|
||||
#include <rocprofiler-sdk/fwd.h>
|
||||
#include <rocprofiler-sdk/rocprofiler.h>
|
||||
#include <rocprofiler-sdk/cxx/codeobj/code_printing.hpp>
|
||||
#include <rocprofiler-sdk/cxx/hash.hpp>
|
||||
#include <rocprofiler-sdk/cxx/name_info.hpp>
|
||||
#include <rocprofiler-sdk/cxx/operators.hpp>
|
||||
@@ -71,7 +73,8 @@ using marker_message_ordered_map_t = std::map<uint64_t, std::string>;
|
||||
using string_entry_map_t = std::unordered_map<size_t, std::unique_ptr<std::string>>;
|
||||
using counter_dimension_vec_t = std::vector<rocprofiler_record_dimension_info_t>;
|
||||
using external_corr_id_set_t = std::unordered_set<uint64_t>;
|
||||
|
||||
using code_obj_decoder_t = rocprofiler::sdk::codeobj::disassembly::CodeobjAddressTranslate;
|
||||
using instruction_t = rocprofiler::sdk::codeobj::disassembly::Instruction;
|
||||
template <typename Tp>
|
||||
using synced_map = common::Synchronized<Tp, true>;
|
||||
|
||||
@@ -82,19 +85,21 @@ struct metadata
|
||||
struct inprocess
|
||||
{};
|
||||
|
||||
pid_t process_id = 0;
|
||||
uint64_t process_start_ns = 0;
|
||||
uint64_t process_end_ns = 0;
|
||||
agent_info_vec_t agents = {};
|
||||
agent_info_map_t agents_map = {};
|
||||
agent_counter_info_map_t agent_counter_info = {};
|
||||
sdk::buffer_name_info buffer_names = {};
|
||||
sdk::callback_name_info callback_names = {};
|
||||
synced_map<code_object_data_map_t> code_objects = {};
|
||||
synced_map<kernel_symbol_data_map_t> kernel_symbols = {};
|
||||
synced_map<marker_message_map_t> marker_messages = {};
|
||||
synced_map<string_entry_map_t> string_entries = {};
|
||||
synced_map<external_corr_id_set_t> external_corr_ids = {};
|
||||
pid_t process_id = 0;
|
||||
uint64_t process_start_ns = 0;
|
||||
uint64_t process_end_ns = 0;
|
||||
agent_info_vec_t agents = {};
|
||||
agent_info_map_t agents_map = {};
|
||||
agent_counter_info_map_t agent_counter_info = {};
|
||||
agent_pc_sample_config_info_map_t agent_pc_sample_config_info = {};
|
||||
|
||||
sdk::buffer_name_info buffer_names = {};
|
||||
sdk::callback_name_info callback_names = {};
|
||||
synced_map<code_object_data_map_t> code_objects = {};
|
||||
synced_map<kernel_symbol_data_map_t> kernel_symbols = {};
|
||||
synced_map<marker_message_map_t> marker_messages = {};
|
||||
synced_map<string_entry_map_t> string_entries = {};
|
||||
synced_map<external_corr_id_set_t> external_corr_ids = {};
|
||||
|
||||
metadata() = default;
|
||||
metadata(inprocess);
|
||||
@@ -119,6 +124,13 @@ struct metadata
|
||||
agent_info_ptr_vec_t get_gpu_agents() const;
|
||||
counter_info_vec_t get_counter_info() const;
|
||||
counter_dimension_vec_t get_counter_dimension_info() const;
|
||||
pc_sample_config_vec_t get_pc_sample_config_info(rocprofiler_agent_id_t _val) const;
|
||||
std::vector<std::string> get_pc_sample_instructions() const { return instruction_decoder; }
|
||||
std::vector<std::string> get_pc_sample_comments() const { return instruction_comment; }
|
||||
std::string_view get_instruction(int64_t index) const { return instruction_decoder.at(index); }
|
||||
std::string_view get_comment(int64_t index) const { return instruction_comment.at(index); }
|
||||
int64_t get_instruction_index(rocprofiler_pc_t record);
|
||||
void add_decoder(rocprofiler_code_object_info_t* obj_data_v);
|
||||
|
||||
template <typename Tp>
|
||||
Tp get_marker_messages(Tp&&);
|
||||
@@ -141,7 +153,13 @@ struct metadata
|
||||
const std::string* get_string_entry(size_t key) const;
|
||||
|
||||
private:
|
||||
bool inprocess_init = false;
|
||||
bool inprocess_init = false;
|
||||
std::unique_ptr<instruction_t> decode_instruction(rocprofiler_pc_t pc);
|
||||
synced_map<code_obj_decoder_t> decoder = {};
|
||||
// TODO: We may have to reserve the vector size based on map size
|
||||
std::vector<std::string> instruction_decoder = {};
|
||||
std::vector<std::string> instruction_comment = {};
|
||||
std::map<inst_t, size_t> indexes = {};
|
||||
};
|
||||
|
||||
template <typename Tp>
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2023 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <rocprofiler-sdk/fwd.h>
|
||||
#include <rocprofiler-sdk/cxx/codeobj/code_printing.hpp>
|
||||
#include <rocprofiler-sdk/cxx/serialization.hpp>
|
||||
|
||||
#include "lib/common/static_object.hpp"
|
||||
#include "lib/common/synchronized.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
using pc_sample_config_vec_t = std::vector<rocprofiler_pc_sampling_configuration_t>;
|
||||
using agent_pc_sample_config_info_map_t =
|
||||
std::unordered_map<rocprofiler_agent_id_t, pc_sample_config_vec_t>;
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace tool
|
||||
{
|
||||
struct inst_t
|
||||
{
|
||||
uint64_t code_object_id;
|
||||
uint64_t code_object_offset;
|
||||
|
||||
bool operator==(const inst_t& inst) const
|
||||
{
|
||||
return this->code_object_id == inst.code_object_id &&
|
||||
this->code_object_offset == inst.code_object_offset;
|
||||
}
|
||||
|
||||
bool operator<(const inst_t& b) const
|
||||
{
|
||||
if(this->code_object_id == b.code_object_id)
|
||||
return this->code_object_offset < b.code_object_offset;
|
||||
return this->code_object_id < b.code_object_id;
|
||||
};
|
||||
};
|
||||
|
||||
// TODO:: Check if we can template this structure
|
||||
struct rocprofiler_tool_pc_sampling_host_trap_record_t
|
||||
{
|
||||
rocprofiler_pc_sampling_record_host_trap_v0_t pc_sample_record;
|
||||
int64_t inst_index;
|
||||
|
||||
rocprofiler_tool_pc_sampling_host_trap_record_t(
|
||||
rocprofiler_pc_sampling_record_host_trap_v0_t record,
|
||||
int64_t index)
|
||||
: pc_sample_record(record)
|
||||
, inst_index(index)
|
||||
{}
|
||||
|
||||
template <typename ArchiveT>
|
||||
void save(ArchiveT& ar) const
|
||||
{
|
||||
ar(cereal::make_nvp("record", pc_sample_record));
|
||||
ar(cereal::make_nvp("inst_index", inst_index));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace tool
|
||||
} // namespace rocprofiler
|
||||
@@ -21,7 +21,9 @@ target_link_libraries(
|
||||
rocprofiler-sdk::rocprofiler-sdk-output-library
|
||||
rocprofiler-sdk::rocprofiler-sdk-cereal
|
||||
rocprofiler-sdk::rocprofiler-sdk-perfetto
|
||||
rocprofiler-sdk::rocprofiler-sdk-otf2)
|
||||
rocprofiler-sdk::rocprofiler-sdk-otf2
|
||||
rocprofiler-sdk::rocprofiler-sdk-dw
|
||||
rocprofiler-sdk::rocprofiler-sdk-amd-comgr)
|
||||
|
||||
set_target_properties(
|
||||
rocprofiler-sdk-tool
|
||||
|
||||
@@ -195,6 +195,22 @@ config::config()
|
||||
, counters{parse_counters(get_env("ROCPROF_COUNTERS", std::string{}))}
|
||||
{
|
||||
if(kernel_filter_include.empty()) kernel_filter_include = std::string{".*"};
|
||||
|
||||
std::unordered_map<std::string_view, rocprofiler_pc_sampling_unit_t> pc_sampling_unit_map = {
|
||||
{"none", ROCPROFILER_PC_SAMPLING_UNIT_NONE},
|
||||
{"instructions", ROCPROFILER_PC_SAMPLING_UNIT_INSTRUCTIONS},
|
||||
{"cycles", ROCPROFILER_PC_SAMPLING_UNIT_CYCLES},
|
||||
{"time", ROCPROFILER_PC_SAMPLING_UNIT_TIME}};
|
||||
|
||||
std::unordered_map<std::string_view, rocprofiler_pc_sampling_method_t> pc_sampling_method_map =
|
||||
{{"none", ROCPROFILER_PC_SAMPLING_METHOD_NONE},
|
||||
{"stochastic", ROCPROFILER_PC_SAMPLING_METHOD_STOCHASTIC},
|
||||
{"host_trap", ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP}};
|
||||
|
||||
pc_sampling_method_value = pc_sampling_method_map.at(pc_sampling_method);
|
||||
if(pc_sampling_method_value == ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP)
|
||||
pc_sampling_host_trap = true;
|
||||
pc_sampling_unit_value = pc_sampling_unit_map.at(pc_sampling_unit);
|
||||
}
|
||||
|
||||
std::string
|
||||
|
||||
@@ -75,29 +75,36 @@ struct config : output_config
|
||||
config& operator=(const config&) = default;
|
||||
config& operator=(config&&) noexcept = default;
|
||||
|
||||
bool demangle = get_env("ROCPROF_DEMANGLE_KERNELS", true);
|
||||
bool truncate = get_env("ROCPROF_TRUNCATE_KERNELS", false);
|
||||
bool kernel_trace = get_env("ROCPROF_KERNEL_TRACE", false);
|
||||
bool hsa_core_api_trace = get_env("ROCPROF_HSA_CORE_API_TRACE", false);
|
||||
bool hsa_amd_ext_api_trace = get_env("ROCPROF_HSA_AMD_EXT_API_TRACE", false);
|
||||
bool hsa_image_ext_api_trace = get_env("ROCPROF_HSA_IMAGE_EXT_API_TRACE", false);
|
||||
bool hsa_finalizer_ext_api_trace = get_env("ROCPROF_HSA_FINALIZER_EXT_API_TRACE", false);
|
||||
bool marker_api_trace = get_env("ROCPROF_MARKER_API_TRACE", false);
|
||||
bool memory_copy_trace = get_env("ROCPROF_MEMORY_COPY_TRACE", false);
|
||||
bool memory_allocation_trace = get_env("ROCPROF_MEMORY_ALLOCATION_TRACE", false);
|
||||
bool scratch_memory_trace = get_env("ROCPROF_SCRATCH_MEMORY_TRACE", false);
|
||||
bool counter_collection = get_env("ROCPROF_COUNTER_COLLECTION", false);
|
||||
bool hip_runtime_api_trace = get_env("ROCPROF_HIP_RUNTIME_API_TRACE", false);
|
||||
bool hip_compiler_api_trace = get_env("ROCPROF_HIP_COMPILER_API_TRACE", false);
|
||||
bool rccl_api_trace = get_env("ROCPROF_RCCL_API_TRACE", false);
|
||||
bool list_metrics = get_env("ROCPROF_LIST_METRICS", false);
|
||||
bool list_metrics_output_file = get_env("ROCPROF_OUTPUT_LIST_METRICS_FILE", false);
|
||||
bool demangle = get_env("ROCPROF_DEMANGLE_KERNELS", true);
|
||||
bool truncate = get_env("ROCPROF_TRUNCATE_KERNELS", false);
|
||||
bool kernel_trace = get_env("ROCPROF_KERNEL_TRACE", false);
|
||||
bool hsa_core_api_trace = get_env("ROCPROF_HSA_CORE_API_TRACE", false);
|
||||
bool hsa_amd_ext_api_trace = get_env("ROCPROF_HSA_AMD_EXT_API_TRACE", false);
|
||||
bool hsa_image_ext_api_trace = get_env("ROCPROF_HSA_IMAGE_EXT_API_TRACE", false);
|
||||
bool hsa_finalizer_ext_api_trace = get_env("ROCPROF_HSA_FINALIZER_EXT_API_TRACE", false);
|
||||
bool marker_api_trace = get_env("ROCPROF_MARKER_API_TRACE", false);
|
||||
bool memory_copy_trace = get_env("ROCPROF_MEMORY_COPY_TRACE", false);
|
||||
bool memory_allocation_trace = get_env("ROCPROF_MEMORY_ALLOCATION_TRACE", false);
|
||||
bool scratch_memory_trace = get_env("ROCPROF_SCRATCH_MEMORY_TRACE", false);
|
||||
bool counter_collection = get_env("ROCPROF_COUNTER_COLLECTION", false);
|
||||
bool hip_runtime_api_trace = get_env("ROCPROF_HIP_RUNTIME_API_TRACE", false);
|
||||
bool hip_compiler_api_trace = get_env("ROCPROF_HIP_COMPILER_API_TRACE", false);
|
||||
bool rccl_api_trace = get_env("ROCPROF_RCCL_API_TRACE", false);
|
||||
bool list_metrics = get_env("ROCPROF_LIST_METRICS", false);
|
||||
bool list_metrics_output_file = get_env("ROCPROF_OUTPUT_LIST_METRICS_FILE", false);
|
||||
bool pc_sampling_host_trap = false;
|
||||
size_t pc_sampling_interval = get_env("ROCPROF_PC_SAMPLING_INTERVAL", 1);
|
||||
rocprofiler_pc_sampling_method_t pc_sampling_method_value = ROCPROFILER_PC_SAMPLING_METHOD_NONE;
|
||||
rocprofiler_pc_sampling_unit_t pc_sampling_unit_value = ROCPROFILER_PC_SAMPLING_UNIT_NONE;
|
||||
|
||||
int mpi_size = get_mpi_size();
|
||||
int mpi_rank = get_mpi_rank();
|
||||
std::string stats_summary_unit = get_env("ROCPROF_STATS_SUMMARY_UNITS", "nsec");
|
||||
int mpi_size = get_mpi_size();
|
||||
int mpi_rank = get_mpi_rank();
|
||||
|
||||
std::string kernel_filter_include = get_env("ROCPROF_KERNEL_FILTER_INCLUDE_REGEX", ".*");
|
||||
std::string kernel_filter_exclude = get_env("ROCPROF_KERNEL_FILTER_EXCLUDE_REGEX", "");
|
||||
std::string pc_sampling_method = get_env("ROCPROF_PC_SAMPLING_METHOD", "none");
|
||||
std::string pc_sampling_unit = get_env("ROCPROF_PC_SAMPLING_UNIT", "none");
|
||||
std::string extra_counters_contents = get_env("ROCPROF_EXTRA_COUNTERS_CONTENTS", "");
|
||||
|
||||
std::unordered_set<uint32_t> kernel_filter_range = {};
|
||||
|
||||
Executable → Regular
+124
-4
@@ -157,17 +157,19 @@ struct buffer_ids
|
||||
rocprofiler_buffer_id_t counter_collection = {};
|
||||
rocprofiler_buffer_id_t scratch_memory = {};
|
||||
rocprofiler_buffer_id_t rccl_api_trace = {};
|
||||
rocprofiler_buffer_id_t pc_sampling_host_trap = {};
|
||||
|
||||
auto as_array() const
|
||||
{
|
||||
return std::array<rocprofiler_buffer_id_t, 8>{hsa_api_trace,
|
||||
return std::array<rocprofiler_buffer_id_t, 9>{hsa_api_trace,
|
||||
hip_api_trace,
|
||||
kernel_trace,
|
||||
memory_copy_trace,
|
||||
memory_allocation_trace,
|
||||
counter_collection,
|
||||
scratch_memory,
|
||||
rccl_api_trace};
|
||||
rccl_api_trace,
|
||||
pc_sampling_host_trap};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -547,6 +549,10 @@ code_object_tracing_callback(rocprofiler_callback_tracing_record_t record,
|
||||
auto* obj_data = static_cast<tool::rocprofiler_code_object_info_t*>(record.payload);
|
||||
|
||||
CHECK_NOTNULL(tool_metadata)->add_code_object(*obj_data);
|
||||
if(tool::get_config().pc_sampling_host_trap)
|
||||
{
|
||||
CHECK_NOTNULL(tool_metadata)->add_decoder(obj_data);
|
||||
}
|
||||
}
|
||||
else if(record.phase == ROCPROFILER_CALLBACK_PHASE_UNLOAD)
|
||||
{
|
||||
@@ -801,6 +807,58 @@ get_device_counting_service(rocprofiler_agent_id_t agent_id)
|
||||
return profile;
|
||||
}
|
||||
|
||||
int64_t
|
||||
get_instruction_index(rocprofiler_pc_t pc)
|
||||
{
|
||||
if(pc.code_object_id == ROCPROFILER_CODE_OBJECT_ID_NONE)
|
||||
return -1;
|
||||
else
|
||||
return CHECK_NOTNULL(tool_metadata)->get_instruction_index(pc);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void
|
||||
rocprofiler_pc_sampling_callback(rocprofiler_context_id_t /* context_id*/,
|
||||
rocprofiler_buffer_id_t /* buffer_id*/,
|
||||
rocprofiler_record_header_t** headers,
|
||||
size_t num_headers,
|
||||
void* /*data*/,
|
||||
uint64_t /* drop_count*/)
|
||||
{
|
||||
if(!headers) return;
|
||||
|
||||
for(size_t i = 0; i < num_headers; i++)
|
||||
{
|
||||
auto* cur_header = headers[i];
|
||||
|
||||
if(cur_header == nullptr)
|
||||
{
|
||||
throw std::runtime_error{
|
||||
"rocprofiler provided a null pointer to header. this should never happen"};
|
||||
}
|
||||
else if(cur_header->category == ROCPROFILER_BUFFER_CATEGORY_PC_SAMPLING)
|
||||
{
|
||||
if(cur_header->kind == ROCPROFILER_PC_SAMPLING_RECORD_HOST_TRAP_V0_SAMPLE)
|
||||
{
|
||||
auto* pc_sample = static_cast<rocprofiler_pc_sampling_record_host_trap_v0_t*>(
|
||||
cur_header->payload);
|
||||
|
||||
auto pc_sample_tool_record =
|
||||
rocprofiler::tool::rocprofiler_tool_pc_sampling_host_trap_record_t(
|
||||
*pc_sample, get_instruction_index(pc_sample->pc));
|
||||
|
||||
rocprofiler::tool::write_ring_buffer(pc_sample_tool_record,
|
||||
domain_type::PC_SAMPLING_HOST_TRAP);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ROCP_FATAL << "unexpected rocprofiler_record_header_t category + kind";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
dispatch_callback(rocprofiler_dispatch_counting_service_data_t dispatch_data,
|
||||
rocprofiler_profile_config_id_t* config,
|
||||
@@ -1018,6 +1076,26 @@ finalize_rocprofv3(std::string_view context)
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
if_pc_sample_config_match(rocprofiler_agent_id_t agent_id,
|
||||
rocprofiler_pc_sampling_method_t pc_sampling_method,
|
||||
rocprofiler_pc_sampling_unit_t pc_sampling_unit,
|
||||
uint64_t pc_sampling_interval)
|
||||
{
|
||||
auto pc_sampling_config = CHECK_NOTNULL(tool_metadata)->get_pc_sample_config_info(agent_id);
|
||||
if(!pc_sampling_config.empty())
|
||||
{
|
||||
for(auto config : pc_sampling_config)
|
||||
{
|
||||
if(config.method == pc_sampling_method && config.unit == pc_sampling_unit &&
|
||||
config.min_interval <= pc_sampling_interval &&
|
||||
config.max_interval >= pc_sampling_interval)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
tool_init(rocprofiler_client_finalize_t fini_func, void* tool_data)
|
||||
{
|
||||
@@ -1277,6 +1355,44 @@ tool_init(rocprofiler_client_finalize_t fini_func, void* tool_data)
|
||||
"Could not configure external correlation id request service");
|
||||
}
|
||||
|
||||
if(tool::get_config().pc_sampling_host_trap)
|
||||
{
|
||||
ROCPROFILER_CALL(rocprofiler_create_buffer(get_client_ctx(),
|
||||
buffer_size,
|
||||
buffer_watermark,
|
||||
ROCPROFILER_BUFFER_POLICY_LOSSLESS,
|
||||
rocprofiler_pc_sampling_callback,
|
||||
tool_data,
|
||||
&get_buffers().pc_sampling_host_trap),
|
||||
"buffer creation");
|
||||
bool config_match_found = false;
|
||||
auto agent_ptr_vec = get_gpu_agents();
|
||||
for(auto& itr : agent_ptr_vec)
|
||||
{
|
||||
auto method = static_cast<rocprofiler_pc_sampling_method_t>(
|
||||
tool::get_config().pc_sampling_method_value);
|
||||
auto unit = static_cast<rocprofiler_pc_sampling_unit_t>(
|
||||
tool::get_config().pc_sampling_unit_value);
|
||||
if(if_pc_sample_config_match(
|
||||
itr->id, method, unit, tool::get_config().pc_sampling_interval))
|
||||
{
|
||||
config_match_found = true;
|
||||
int flags = 0;
|
||||
ROCPROFILER_CALL(rocprofiler_configure_pc_sampling_service(
|
||||
get_client_ctx(),
|
||||
itr->id,
|
||||
method,
|
||||
unit,
|
||||
tool::get_config().pc_sampling_interval,
|
||||
get_buffers().pc_sampling_host_trap,
|
||||
flags),
|
||||
"configure PC sampling");
|
||||
}
|
||||
}
|
||||
if(!config_match_found)
|
||||
ROCP_ERROR << "Given PC sampling configuration is not supported on any of the agents";
|
||||
}
|
||||
|
||||
for(auto itr : get_buffers().as_array())
|
||||
{
|
||||
if(itr.handle > 0)
|
||||
@@ -1380,6 +1496,8 @@ tool_fini(void* /*tool_data*/)
|
||||
tool::memory_allocation_buffered_output_t{tool::get_config().memory_allocation_trace};
|
||||
auto counters_records_output =
|
||||
tool::counter_records_buffered_output_t{tool::get_config().counter_collection};
|
||||
auto pc_sampling_host_trap_output =
|
||||
tool::pc_sampling_host_trap_buffered_output_t{tool::get_config().pc_sampling_host_trap};
|
||||
|
||||
auto node_id_sort = [](const auto& lhs, const auto& rhs) { return lhs.node_id < rhs.node_id; };
|
||||
|
||||
@@ -1402,6 +1520,7 @@ tool_fini(void* /*tool_data*/)
|
||||
generate_output(rccl_output, contributions);
|
||||
generate_output(counters_output, contributions);
|
||||
generate_output(scratch_memory_output, contributions);
|
||||
generate_output(pc_sampling_host_trap_output, contributions);
|
||||
|
||||
if(tool::get_config().stats && tool::get_config().csv_output)
|
||||
{
|
||||
@@ -1426,7 +1545,8 @@ tool_fini(void* /*tool_data*/)
|
||||
marker_output.get_generator(),
|
||||
scratch_memory_output.get_generator(),
|
||||
rccl_output.get_generator(),
|
||||
memory_allocation_output.get_generator());
|
||||
memory_allocation_output.get_generator(),
|
||||
pc_sampling_host_trap_output.get_generator());
|
||||
json_ar.finish_process();
|
||||
|
||||
tool::close_json(json_ar);
|
||||
@@ -1489,6 +1609,7 @@ tool_fini(void* /*tool_data*/)
|
||||
destroy_output(scratch_memory_output);
|
||||
destroy_output(rccl_output);
|
||||
destroy_output(counters_records_output);
|
||||
destroy_output(pc_sampling_host_trap_output);
|
||||
|
||||
if(destructors)
|
||||
{
|
||||
@@ -1502,7 +1623,6 @@ tool_fini(void* /*tool_data*/)
|
||||
__gcov_dump();
|
||||
#endif
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::vector<rocprofiler_record_dimension_info_t>
|
||||
get_tool_counter_dimension_info()
|
||||
|
||||
Reference in New Issue
Block a user