Add support for kernel name filtering to rocprofv2

rocprofv2 does not support the "kernel:" attribute in
input files. This commit adds support for this attribute
for cli/csv output. This is requested by Alibaba/Omniperf
to have compatible execution with both v1/v2 (JSON and CTF
are not supported here and not needed).

Filtering can also be enabled by the flag ROCPROFILER_KERNEL_FILTER.

Change-Id: I376382d9e5b10a8356df8d175b1a56396b5b51d3


[ROCm/rocprofiler commit: b32eb2bda9]
Dieser Commit ist enthalten in:
Benjamin Welton
2024-08-08 01:14:38 +00:00
committet von Benjamin Welton
Ursprung a34d5dbc16
Commit c45fbe91ff
4 geänderte Dateien mit 78 neuen und 1 gelöschten Zeilen
+8
Datei anzeigen
@@ -295,6 +295,14 @@ export LD_PRELOAD=$LD_PRELOAD:$ROCM_DIR/lib/rocprofiler/librocprofiler_tool.so
if [ -n "$PMC_LINES" ] && [ ! -n "$ATT_ARGV" ]; then
COUNTER=1
for i in ${!PMC_LINES[@]}; do
if [[ ${PMC_LINES[$i]} =~ "kernel:" ]]; then
echo ${PMC_LINES[$i]}
export ROCPROFILER_KERNEL_FILTER="${PMC_LINES[$i]}"
fi
done
for i in ${!PMC_LINES[@]}; do
export ROCPROFILER_COUNTERS="${PMC_LINES[$i]}"
if [[ ! ${PMC_LINES[$i]} =~ "pmc" ]]; then
+27 -1
Datei anzeigen
@@ -32,6 +32,7 @@
#include <cstdint>
#include <fstream>
#include <iostream>
#include <map>
#include <memory>
#include <optional>
#include <ostream>
@@ -136,7 +137,10 @@ class file_plugin_t {
}
public:
file_plugin_t() { valid_ = true; }
file_plugin_t() {
valid_ = true;
kernel_filters_ = GetKernelFilters();
}
std::mutex writing_lock;
@@ -208,6 +212,22 @@ class file_plugin_t {
void FlushProfilerRecord(const rocprofiler_record_profiler_t* profiler_record,
rocprofiler_session_id_t session_id, rocprofiler_buffer_id_t buffer_id) {
auto check_filter_cache = [&](const char * k_name) {
auto str = std::string{k_name};
auto f = kernel_filter_cache_.find(k_name);
if (f == kernel_filter_cache_.end()) {
bool found_match = false;
for (const auto& filter : kernel_filters_) {
if (str.find(filter) != std::string::npos) {
found_match = true;
break;
}
}
f = kernel_filter_cache_.emplace(str, found_match).first;
}
return f->second;
};
std::lock_guard<std::mutex> lock(writing_lock);
size_t name_length = 0;
output_file_t* output_file{nullptr};
@@ -220,6 +240,10 @@ class file_plugin_t {
if (name_length > 1) {
CHECK_ROCPROFILER(rocprofiler_query_kernel_info(ROCPROFILER_KERNEL_NAME,
profiler_record->kernel_id, &kernel_name_c));
if (kernel_name_c != nullptr && !kernel_filters_.empty() && !check_filter_cache(kernel_name_c)) {
free(const_cast<char*>(kernel_name_c));
return;
}
}
*output_file << "Dispatch_ID(" << std::to_string(profiler_record->header.id.handle) << "), "
<< "GPU_ID(" << std::to_string(profiler_record->gpu_id.handle) << "), "
@@ -340,6 +364,8 @@ class file_plugin_t {
private:
bool valid_{false};
std::set<std::string> kernel_filters_;
std::map<std::string, bool> kernel_filter_cache_;
std::atomic<bool> tracer_header_written_{false};
std::atomic<bool> profiler_header_written_{false};
@@ -32,6 +32,7 @@
#include <cstdint>
#include <fstream>
#include <iostream>
#include <map>
#include <memory>
#include <optional>
#include <ostream>
@@ -176,6 +177,7 @@ class file_plugin_t {
file_plugin_t(void* data) {
if (data) counter_names_ = GetCounterNames();
kernel_filters_ = GetKernelFilters();
const char* str = getenv("ROCPROFILER_INDIVIDUAL_XCC_MODE");
if (str != NULL) is_individual_xcc_mode = (atol(str) > 0);
@@ -328,6 +330,23 @@ class file_plugin_t {
void FlushProfilerRecord(const rocprofiler_record_profiler_t* profiler_record,
rocprofiler_session_id_t session_id, rocprofiler_buffer_id_t buffer_id) {
auto check_filter_cache = [&](const char * k_name) {
auto str = std::string{k_name};
auto f = kernel_filter_cache_.find(k_name);
if (f == kernel_filter_cache_.end()) {
bool found_match = false;
for (const auto& filter : kernel_filters_) {
if (str.find(filter) != std::string::npos) {
found_match = true;
break;
}
}
f = kernel_filter_cache_.emplace(str, found_match).first;
}
return f->second;
};
std::lock_guard<std::mutex> lock(writing_lock);
std::stringstream ss;
WriteHeader(output_type_t::COUNTER, ACTIVITY_DOMAIN_NUMBER);
@@ -342,6 +361,10 @@ class file_plugin_t {
if (name_length > 1) {
CHECK_ROCPROFILER(rocprofiler_query_kernel_info(ROCPROFILER_KERNEL_NAME,
profiler_record->kernel_id, &kernel_name_c));
if (kernel_name_c != nullptr && !kernel_filters_.empty() && !check_filter_cache(kernel_name_c)) {
free(const_cast<char*>(kernel_name_c));
return;
}
}
if (!counter_header_written_) {
@@ -465,6 +488,8 @@ class file_plugin_t {
bool counter_header_written_ = false;
bool is_individual_xcc_mode=false;
std::vector<std::string> counter_names_;
std::set<std::string> kernel_filters_;
std::map<std::string, bool> kernel_filter_cache_;
std::atomic<bool> roctx_header_written_{false}, hsa_api_header_written_{false},
hip_api_header_written_{false}, hip_activity_header_written_{false},
+18
Datei anzeigen
@@ -32,6 +32,8 @@
#include <cstdint>
#include <cstdlib>
#include <string>
#include <set>
#include <sstream>
#include "src/utils/helper.h"
@@ -51,4 +53,20 @@ namespace {
[[maybe_unused]] uint64_t GetMachineID() { return gethostid(); }
[[maybe_unused]] std::set<std::string> GetKernelFilters() {
std::set<std::string> ret;
if (const char* line_c_str = getenv("ROCPROFILER_KERNEL_FILTER")) {
std::stringstream ss(std::string{line_c_str});
std::string filter_name;
while(std::getline(ss, filter_name, ' '))
{
if (filter_name.find("kernel:") != std::string::npos) {
continue;
}
ret.insert(filter_name);
}
}
return ret;
}
} // namespace