SWDEV-423947: Added ATT header option

Change-Id: I6e9ad213b578d752c865c9f9af4ee0b79d447e1b


[ROCm/rocprofiler commit: e0962d9d63]
This commit is contained in:
Giovanni LB
2023-10-07 16:34:19 -03:00
committed by Giovanni Baraldi
parent 5d443a4821
commit 769f6303d8
7 changed files with 96 additions and 55 deletions
@@ -171,7 +171,6 @@ static const kernel_descriptor_t* GetKernelCode(uint64_t kernel_object) {
static uint32_t arch_vgpr_count(const std::string_view& name,
const kernel_descriptor_t& kernel_code) {
std::string info_name(name.data(), name.size());
if (strcmp(name.data(), "gfx90a") == 0 || strncmp(name.data(), "gfx94", 5) == 0)
return (AMD_HSA_BITS_GET(kernel_code.compute_pgm_rsrc3,
AMD_COMPUTE_PGM_RSRC_THREE_ACCUM_OFFSET) +
@@ -1127,9 +1126,12 @@ void Queue::WriteInterceptor(const void* packets, uint64_t pkt_count, uint64_t u
dispatch_packet.completion_signal, session_id_snapshot, buffer_id, profile,
kernel_properties, (uint32_t)syscall(__NR_gettid), user_pkt_index);
uint64_t off = dispatch_packet.kernel_object +
GetKernelCode(dispatch_packet.kernel_object)->kernel_code_entry_byte_offset;
codeobj_record::make_capture(rocprofiler_record_id_t{record_id}, capture_mode, off);
uint64_t userdata = HSASupport_Singleton::GetInstance()
.GetHSAAgentInfo(queue_info.GetGPUAgent().handle)
.GetDeviceInfo()
.getName()
.find("gfx9") != std::string::npos;
codeobj_record::make_capture(rocprofiler_record_id_t{record_id}, capture_mode, userdata);
codeobj_record::start_capture(rocprofiler_record_id_t{record_id});
codeobj_record::stop_capture(rocprofiler_record_id_t{record_id});
@@ -44,6 +44,19 @@ typedef struct {
uint64_t queue_index;
} att_pending_signal_t;
union att_header_packet_t {
struct {
uint64_t reserved : 14;
uint64_t navi : 1;
uint64_t enable : 1;
uint64_t DSIMDM : 4;
uint64_t DCU : 5;
uint64_t DSA : 1;
uint64_t SEID : 6;
};
uint64_t raw;
};
namespace att {
class AttTracer {
+40 -18
View File
@@ -59,6 +59,14 @@
#include "utils/helper.h"
#include "trace_buffer.h"
#include "core/session/att/att.h"
struct PluginHeaderPacket
{
std::string plugin_path;
void* userdata;
};
#define SLEEP_CYCLE_LENGTH 100l
@@ -97,10 +105,10 @@ void warning(const std::string& msg) { std::cerr << msg << std::endl; }
class rocprofiler_plugin_t {
public:
rocprofiler_plugin_t(const std::string& plugin_path) {
plugin_handle_ = dlopen(plugin_path.c_str(), RTLD_LAZY);
rocprofiler_plugin_t(const PluginHeaderPacket& data) {
plugin_handle_ = dlopen(data.plugin_path.c_str(), RTLD_LAZY);
if (plugin_handle_ == nullptr) {
warning(std::string("Warning: dlopen for ") + plugin_path + " failed: " + dlerror());
warning(std::string("Warning: dlopen for ") + data.plugin_path + " failed: " + dlerror());
return;
}
@@ -117,8 +125,7 @@ class rocprofiler_plugin_t {
if (auto* initialize = reinterpret_cast<decltype(rocprofiler_plugin_initialize)*>(
dlsym(plugin_handle_, "rocprofiler_plugin_initialize"));
initialize != nullptr)
valid_ =
initialize(ROCPROFILER_VERSION_MAJOR, ROCPROFILER_VERSION_MINOR, &counter_names) == 0;
valid_ = initialize(ROCPROFILER_VERSION_MAJOR, ROCPROFILER_VERSION_MINOR, data.userdata) == 0;
}
~rocprofiler_plugin_t() {
@@ -253,7 +260,7 @@ std::vector<std::string> GetCounterNames() {
}
typedef std::tuple<std::vector<std::pair<rocprofiler_att_parameter_name_t, uint32_t>>,
std::vector<std::string>, std::vector<std::string>, std::vector<uint64_t>>
std::vector<std::string>, std::vector<std::string>, std::vector<uint64_t>, uint64_t>
att_parsed_input_t;
static int GetMpRank() {
@@ -269,7 +276,7 @@ att_parsed_input_t GetATTParams() {
std::vector<std::string> counters_names;
std::vector<uint64_t> dispatch_ids;
const char* path = getenv("COUNTERS_PATH");
if (!path) return {{}, {}, {}, {}};
if (!path) return {{}, {}, {}, {}, 0};
// List of parameters the user can set. Maxvalue is unused.
std::unordered_map<std::string, rocprofiler_att_parameter_name_t> ATT_PARAM_NAMES{};
@@ -304,9 +311,12 @@ att_parsed_input_t GetATTParams() {
std::ifstream trace_file(path);
if (!trace_file.is_open()) {
std::cout << "Unable to open att trace file." << std::endl;
return {{}, {}, {}, {}};
return {{}, {}, {}, {}, 0};
}
rocprofiler::att_header_packet_t header{.raw = 0};
header.enable = 1;
header.DSIMDM = default_params["SIMD_SELECT"];
int MPI_RANK = GetMpRank();
bool started_att_counters = false;
@@ -332,7 +342,10 @@ att_parsed_input_t GetATTParams() {
}
if (!started_att_counters) continue;
if (param_name == "KERNEL") {
if (param_name == "REMOVE_HEADER_PACKET") {
header.enable = 0;
continue;
} else if (param_name == "KERNEL") {
kernel_names.push_back(line);
continue;
} else if (param_name == "PERFCOUNTER") {
@@ -371,14 +384,19 @@ att_parsed_input_t GetATTParams() {
param_name.c_str(), line.c_str());
for (auto& name : ATT_PARAM_NAMES) printf("%s\n", name.first.c_str());
}
if (param_name.find("TARGET_CU") != std::string::npos)
header.DCU = param_value;
else if (param_name.find("SIMD_SELECT") != std::string::npos)
header.DSIMDM = param_value;
}
if (!started_att_counters) return {{}, {}, {}, {}};
if (!started_att_counters) return {{}, {}, {}, {}, 0};
for (auto& param : default_params)
parameters.push_back(std::make_pair(ATT_PARAM_NAMES[param.first], param.second));
return {parameters, kernel_names, counters_names, dispatch_ids};
return {parameters, kernel_names, counters_names, dispatch_ids, header.raw};
}
void finish() {
@@ -435,7 +453,7 @@ static void env_var_replace(const char* env_name) {
}
// load plugins
void plugins_load() {
void plugins_load(void* userdata) {
// Load output plugin
if (Dl_info dl_info; dladdr((void*)plugins_load, &dl_info) != 0) {
const char* plugin_name = getenv("ROCPROFILER_PLUGIN_LIB");
@@ -461,7 +479,11 @@ void plugins_load() {
<< std::string(getenv("ROCPROFILER_COUNTERS")) << '\n';
}
if (!plugin.emplace(fs::path(dl_info.dli_fname).replace_filename(plugin_name)).is_valid()) {
PluginHeaderPacket header{
.plugin_path = fs::path(dl_info.dli_fname).replace_filename(plugin_name),
.userdata = userdata
};
if (!plugin.emplace(header).is_valid()) {
plugin.reset();
}
}
@@ -683,10 +705,6 @@ ROCPROFILER_EXPORT bool OnLoad(void* table, uint64_t runtime_version, uint64_t f
}
}
// load the plugins
plugins_load();
std::vector<rocprofiler_tracer_activity_domain_t> apis_requested;
if (getenv("ROCPROFILER_HIP_API_TRACE")) apis_requested.emplace_back(ACTIVITY_DOMAIN_HIP_API);
@@ -703,7 +721,11 @@ ROCPROFILER_EXPORT bool OnLoad(void* table, uint64_t runtime_version, uint64_t f
std::vector<std::string> kernel_names;
std::vector<std::string> att_counters_names;
std::vector<uint64_t> dispatch_ids;
std::tie(params, kernel_names, att_counters_names, dispatch_ids) = GetATTParams();
uint64_t attheader;
std::tie(params, kernel_names, att_counters_names, dispatch_ids, attheader) = GetATTParams();
// load the plugins
plugins_load(params.size() ? (void*)attheader : (void*)&counter_names);
for (auto& kv_pair : params)
parameters.emplace_back(rocprofiler_att_parameter_t{kv_pair.first, kv_pair.second});