Making ATT work with Profilerv2

Change-Id: Ic9334aa80e40faaaf5c1a79ba37dbe52e8d31253
This commit is contained in:
gobhardw
2023-02-07 13:06:02 +05:30
committed by Ammar ELWazir
parent 6dda141e4b
commit 03c305dbd4
28 changed files with 3783 additions and 24 deletions
+57
View File
@@ -0,0 +1,57 @@
/* Copyright (c) 2022 Advanced Micro Devices, Inc.
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. */
#include "att.h"
#include <cassert>
namespace rocmtools {
namespace att {
AttTracer::AttTracer(rocprofiler_buffer_id_t buffer_id, rocprofiler_filter_id_t filter_id,
rocprofiler_session_id_t session_id)
: buffer_id_(buffer_id), filter_id_(filter_id), session_id_(session_id) {}
AttTracer::~AttTracer() {}
void AttTracer::AddPendingSignals(uint32_t writer_id, uint64_t kernel_object,
const hsa_signal_t& completion_signal,
rocprofiler_session_id_t session_id,
rocprofiler_buffer_id_t buffer_id,
hsa_ven_amd_aqlprofile_profile_t* profile,
rocprofiler_kernel_properties_t kernel_properties,
uint32_t thread_id, uint64_t queue_index) {
std::lock_guard<std::mutex> lock(sessions_pending_signals_lock_);
if (sessions_pending_signals_.find(writer_id) == sessions_pending_signals_.end())
sessions_pending_signals_.emplace(writer_id, std::vector<att_pending_signal_t>());
sessions_pending_signals_.at(writer_id).emplace_back(
att_pending_signal_t{kernel_object, completion_signal, session_id_, buffer_id, profile,
kernel_properties, thread_id, queue_index});
}
const std::vector<att_pending_signal_t>& AttTracer::GetPendingSignals(uint32_t writer_id) {
std::lock_guard<std::mutex> lock(sessions_pending_signals_lock_);
assert(sessions_pending_signals_.find(writer_id) != sessions_pending_signals_.end() &&
"writer_id is not found in the pending_signals");
return sessions_pending_signals_.at(writer_id);
}
} // namespace att
} // namespace rocmtools
+76
View File
@@ -0,0 +1,76 @@
/* Copyright (c) 2022 Advanced Micro Devices, Inc.
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. */
#ifndef SRC_CORE_SESSION_ATT_ATT_H_
#define SRC_CORE_SESSION_ATT_ATT_H_
#include <hsa/hsa_ven_amd_aqlprofile.h>
#include <map>
#include <mutex>
#include <string>
#include <vector>
#include "inc/rocprofiler.h"
namespace rocmtools {
typedef struct {
uint64_t kernel_descriptor;
hsa_signal_t signal;
rocprofiler_session_id_t session_id;
rocprofiler_buffer_id_t buffer_id;
hsa_ven_amd_aqlprofile_profile_t* profile;
rocprofiler_kernel_properties_t kernel_properties;
uint32_t thread_id;
uint64_t queue_index;
} att_pending_signal_t;
namespace att {
class AttTracer {
public:
AttTracer(rocprofiler_buffer_id_t buffer_id, rocprofiler_filter_id_t filter_id,
rocprofiler_session_id_t session_id);
~AttTracer();
void AddPendingSignals(uint32_t writer_id, uint64_t kernel_object,
const hsa_signal_t& completion_signal, rocprofiler_session_id_t session_id,
rocprofiler_buffer_id_t buffer_id, hsa_ven_amd_aqlprofile_profile_t* profile,
rocprofiler_kernel_properties_t kernel_properties, uint32_t thread_id,
uint64_t queue_index);
const std::vector<att_pending_signal_t>& GetPendingSignals(uint32_t writer_id);
private:
rocprofiler_buffer_id_t buffer_id_;
rocprofiler_filter_id_t filter_id_;
rocprofiler_session_id_t session_id_;
std::mutex sessions_pending_signals_lock_;
std::map<uint32_t, std::vector<att_pending_signal_t>> sessions_pending_signals_;
};
} // namespace att
} // namespace rocmtools
#endif // SRC_CORE_SESSION_ATT_ATT_H_
+38 -7
View File
@@ -35,12 +35,25 @@ Filter::Filter(rocprofiler_filter_id_t id, rocprofiler_filter_kind_t filter_kind
}
case ROCPROFILER_COUNTERS_COLLECTION: {
profiler_counter_names_.clear();
for (uint32_t j = 0; j < data_count; j++)
for (uint32_t j = 0; j < data_count; j++) {
profiler_counter_names_.emplace_back(filter_data.counters_names[j]);
}
break;
}
case ROCPROFILER_PC_SAMPLING_COLLECTION:
case ROCPROFILER_ATT_TRACE: {
case ROCPROFILER_PC_SAMPLING_COLLECTION:{
break;
}
case ROCPROFILER_ATT_TRACE_COLLECTION: {
att_parameters_.clear();
profiler_counter_names_.clear();
for (uint32_t j = 0; j < data_count; j++) {
if (filter_data.att_parameters[j].parameter_name != ROCPROFILER_ATT_PERFCOUNTER_NAME) {
att_parameters_.emplace_back(filter_data.att_parameters[j]);
} else {
profiler_counter_names_.emplace_back(filter_data.att_parameters[j].counter_name);
}
}
break;
}
case ROCPROFILER_SPM_COLLECTION: {
@@ -49,8 +62,9 @@ Filter::Filter(rocprofiler_filter_id_t id, rocprofiler_filter_kind_t filter_kind
}
case ROCPROFILER_API_TRACE: {
tracer_apis_.clear();
for (uint32_t j = 0; j < data_count; j++)
tracer_apis_.emplace_back(filter_data.trace_apis[j]);
for (uint32_t j = 0; j < data_count; j++){
tracer_apis_.emplace_back(filter_data.trace_apis[j]);
}
break;
}
default: {
@@ -73,7 +87,7 @@ rocprofiler_filter_kind_t Filter::GetKind() { return kind_; }
std::mutex counter_data_lock;
std::vector<std::string> Filter::GetCounterData() {
if (kind_ == ROCPROFILER_COUNTERS_COLLECTION) {
if (kind_ == ROCPROFILER_COUNTERS_COLLECTION || kind_ == ROCPROFILER_ATT_TRACE_COLLECTION) {
std::lock_guard<std::mutex> lock(counter_data_lock);
return profiler_counter_names_;
}
@@ -90,6 +104,16 @@ std::vector<rocprofiler_tracer_activity_domain_t> Filter::GetTraceData() {
"Error: ROCMtools filter specified is not supported for "
"profiler mode!\n");
}
std::vector<rocprofiler_att_parameter_t> Filter::GetAttParametersData() {
if (kind_ == ROCPROFILER_ATT_TRACE_COLLECTION) {
return att_parameters_;
}
fatal(
"Error: ROCMtools filter specified is not supported for "
"ATT tracing mode!\n");
}
rocprofiler_spm_parameter_t* Filter::GetSpmParameterData() {
if (kind_ == ROCPROFILER_SPM_COLLECTION) {
return spm_parameter_;
@@ -143,7 +167,8 @@ void Filter::SetProperty(rocprofiler_filter_property_t property) {
}
case ROCPROFILER_FILTER_KERNEL_NAMES: {
if (kind_ == ROCPROFILER_COUNTERS_COLLECTION ||
kind_ == ROCPROFILER_DISPATCH_TIMESTAMPS_COLLECTION) {
kind_ == ROCPROFILER_DISPATCH_TIMESTAMPS_COLLECTION ||
kind_ == ROCPROFILER_ATT_TRACE_COLLECTION) {
kernel_names_.clear();
for (uint32_t j = 0; j < property.data_count; j++)
kernel_names_.emplace_back(property.name_regex[j]);
@@ -166,23 +191,29 @@ std::variant<std::vector<std::string>, uint32_t*> Filter::GetProperty(
switch (kind) {
case ROCPROFILER_FILTER_GPU_NAME: {
property = agent_names_;
break;
}
case ROCPROFILER_FILTER_RANGE: {
property = static_cast<uint32_t*>(dispatch_range_);
break;
}
case ROCPROFILER_FILTER_KERNEL_NAMES: {
property = kernel_names_;
break;
}
case ROCPROFILER_FILTER_HSA_TRACER_API_FUNCTIONS: {
property = hsa_tracer_api_calls_;
break;
}
case ROCPROFILER_FILTER_HIP_TRACER_API_FUNCTIONS: {
property = hip_tracer_api_calls_;
break;
}
default:
fatal(
"Error: ROCMtools filter specified is not supported for the given "
"kind!");
break;
}
return property;
}
+2 -1
View File
@@ -47,7 +47,7 @@ class Filter {
std::vector<std::string> GetCounterData();
std::vector<rocprofiler_tracer_activity_domain_t> GetTraceData();
std::vector<rocprofiler_att_parameter_t> GetAttParametersData();
void SetCallback(rocprofiler_sync_callback_t& callback);
rocprofiler_sync_callback_t& GetCallback();
@@ -71,6 +71,7 @@ class Filter {
std::vector<std::string> profiler_counter_names_; // Counter Names to collect
std::vector<rocprofiler_tracer_activity_domain_t> tracer_apis_; // ROCTX/HIP/HSA API
rocprofiler_spm_parameter_t* spm_parameter_; // spm parameter
std::vector<rocprofiler_att_parameter_t> att_parameters_; // ATT Parameters
rocprofiler_sync_callback_t callback_;
};
+12
View File
@@ -54,6 +54,10 @@ Session::~Session() {
// delete tracer_;
// tracer_started_.exchange(false, std::memory_order_release);
// }
if (att_tracer_started_.load(std::memory_order_release)) {
delete att_tracer_;
att_tracer_started_.exchange(false, std::memory_order_release);
}
// {
// std::lock_guard<std::mutex> lock(filters_lock_);
// buffers_.clear();
@@ -99,6 +103,13 @@ void Session::Start() {
GetFilter(GetFilterIdWithKind(ROCPROFILER_COUNTERS_COLLECTION))->GetId(), session_id_);
profiler_started_.exchange(true, std::memory_order_release);
}
if (FindFilterWithKind(ROCPROFILER_ATT_TRACE_COLLECTION)) {
if (att_tracer_started_.load(std::memory_order_release)) delete att_tracer_;
att_tracer_ = new att::AttTracer(
GetFilter(GetFilterIdWithKind(ROCPROFILER_ATT_TRACE_COLLECTION))->GetBufferId(),
GetFilter(GetFilterIdWithKind(ROCPROFILER_ATT_TRACE_COLLECTION))->GetId(), session_id_);
att_tracer_started_.exchange(true, std::memory_order_release);
}
if (FindFilterWithKind(ROCPROFILER_SPM_COLLECTION)) {
if (spm_started_.load(std::memory_order_release)) delete spmcounter_;
@@ -176,6 +187,7 @@ rocprofiler_session_id_t Session::GetId() { return session_id_; }
bool Session::IsActive() { return is_active_; }
profiler::Profiler* Session::GetProfiler() { return profiler_; }
att::AttTracer* Session::GetAttTracer() { return att_tracer_; }
tracer::Tracer* Session::GetTracer() { return tracer_; }
spm::SpmCounters* Session::GetSpmCounter() { return spmcounter_; }
pc_sampler::PCSampler* Session::GetPCSampler() { return pc_sampler_; }
+4
View File
@@ -37,6 +37,7 @@
#include "src/core/session/filter.h"
#include "profiler/profiler.h"
#include "tracer/tracer.h"
#include "att/att.h"
#include "spm/spm.h"
#include "src/pcsampler/session/pc_sampler.h"
@@ -58,6 +59,7 @@ class Session {
profiler::Profiler* GetProfiler();
tracer::Tracer* GetTracer();
att::AttTracer* GetAttTracer();
spm::SpmCounters* GetSpmCounter();
pc_sampler::PCSampler* GetPCSampler();
@@ -104,6 +106,8 @@ class Session {
std::atomic<bool> profiler_started_{false};
std::atomic<bool> tracer_started_{false};
std::atomic<bool> att_tracer_started_{false};
att::AttTracer* att_tracer_;
std::atomic<bool> spm_started_{false};
profiler::Profiler* profiler_;