From 4defc278259f34ce0817d46a96388353fe24090a Mon Sep 17 00:00:00 2001 From: Aurelio Vivas Date: Fri, 30 Jun 2023 12:12:59 -0500 Subject: [PATCH] Backend level argument for iprof (#93) * draft with bad practice in configure.ac * fix * fix * fix tally test * Fix narrowing conversion error * Fix distcheck * enable compact * testing g++-7 * checking g++ version * cleaning * Add removed g++ library * add btx_tally pluging and component * suggestions * suggestions * suggestions * Update xprof/tally.hpp Co-authored-by: Thomas Applencourt * suggestions * typos, cleaning * before formatting * formatting * cleaning * cleaning * suggestions * fix * fixed * Update btx_interval_model.yaml * set backend level via env variable * update * fix * update comment * --backend_level * suggestions * suggestions * update * update * update * Update spliting to a more readable format * suggestions * update * Update utils/babeltrace_thapi.in Co-authored-by: Brice Videau * Update utils/xprof_utils.hpp Co-authored-by: Brice Videau * Update xprof/tally.cpp Co-authored-by: Brice Videau * fix identation * implitic max value * add namespace * fix merge resolution * Update utils/xprof_utils.hpp * Update xprof/tally.cpp * add --backed-level option to command line help --------- Co-authored-by: Thomas Applencourt Co-authored-by: Brice Videau --- utils/babeltrace_thapi.in | 3 ++- utils/xprof_utils.cpp | 1 - utils/xprof_utils.hpp | 37 +++++++++++++++++-------------- xprof/btx_tally_params.yaml | 2 ++ xprof/tally.cpp | 44 ++++++++++++++++++++++++++++++++++--- xprof/tally.hpp | 2 ++ xprof/xprof.sh.erb.in | 2 ++ 7 files changed, 69 insertions(+), 22 deletions(-) diff --git a/utils/babeltrace_thapi.in b/utils/babeltrace_thapi.in index fb4bbe69..6d6e606d 100644 --- a/utils/babeltrace_thapi.in +++ b/utils/babeltrace_thapi.in @@ -24,7 +24,8 @@ $options_tally = { 'display_mode' => [String, 'human'], 'display_metadata' => [FalseClass, false], 'display_name_max_size' => [Integer, 80], - 'display_kernel_verbose' => [FalseClass, false] + 'display_kernel_verbose' => [FalseClass, false], + 'backend_level' => [String, ''], } def common_options(opts) diff --git a/utils/xprof_utils.cpp b/utils/xprof_utils.cpp index a0a6d63b..07f141fc 100644 --- a/utils/xprof_utils.cpp +++ b/utils/xprof_utils.cpp @@ -205,4 +205,3 @@ bt_message* create_traffic_message(const char *hostname, const process_id_t proc return message; } - diff --git a/utils/xprof_utils.hpp b/utils/xprof_utils.hpp index 9486759b..6e9e44a8 100644 --- a/utils/xprof_utils.hpp +++ b/utils/xprof_utils.hpp @@ -5,23 +5,26 @@ #include #include "babeltrace2/babeltrace.h" -enum backend_e{ BACKEND_UNKNOWN = 0, - BACKEND_ZE = 1, - BACKEND_OPENCL = 2, - BACKEND_CUDA = 3, - BACKEND_OMP_TARGET_OPERATIONS = 4, - BACKEND_OMP = 5, - BACKEND_HIP = 6 }; - -constexpr int backend_level[] = { 2, 2, 2, 2, 1, 0, 2 }; - -constexpr const char* backend_name[] = { "BACKEND_UNKNOWN", - "BACKEND_ZE", - "BACKEND_OPENCL", - "BACKEND_CUDA", - "BACKEND_OMP_TARGET_OPERATIONS", - "BACKEND_OMP", - "BACKEND_HIP" }; +enum backend_e { + BACKEND_UNKNOWN = 0, + BACKEND_ZE = 1, + BACKEND_OPENCL = 2, + BACKEND_CUDA = 3, + BACKEND_OMP_TARGET_OPERATIONS = 4, + BACKEND_OMP = 5, + BACKEND_HIP = 6, + BACKEND_MAX, +}; + +constexpr const char* backend_name[] = { + "BACKEND_UNKNOWN", + "BACKEND_ZE", + "BACKEND_OPENCL", + "BACKEND_CUDA", + "BACKEND_OMP_TARGET_OPERATIONS", + "BACKEND_OMP", + "BACKEND_HIP", +}; typedef enum backend_e backend_t; typedef unsigned backend_level_t; diff --git a/xprof/btx_tally_params.yaml b/xprof/btx_tally_params.yaml index f2e41a8f..6f748c17 100644 --- a/xprof/btx_tally_params.yaml +++ b/xprof/btx_tally_params.yaml @@ -12,3 +12,5 @@ :type: integer_unsigned - :name: display_kernel_verbose :type: bool + - :name: backend_level + :type: string \ No newline at end of file diff --git a/xprof/tally.cpp b/xprof/tally.cpp index 2669379f..252c050d 100644 --- a/xprof/tally.cpp +++ b/xprof/tally.cpp @@ -1,4 +1,8 @@ #include "tally.hpp" +#include +#include +#include +#include // std::stringstream, std::stringbuf //! User data collection structure. //! It is used to collect interval messages data, once data is collected, @@ -7,6 +11,8 @@ struct tally_dispatch_s { //! User params provided to the user component. btx_params_t *params; + std::arraybackend_level; + std::map> host_backend_name; std::map> traffic_backend_name; @@ -32,14 +38,46 @@ void print_metadata(std::vector metadata) { std::cout << value << std::endl; } +int get_backend_id(std::string name) { + for(int i = 0; i < BACKEND_MAX; ++i) + // backend_name is located in xprof_utils.cpp + if (std::string{backend_name[i]} == name) return i; + return -1; +} + void btx_initialize_usr_data(void *btx_handle, void **usr_data) { /* User allocates its own data structure */ - *usr_data = new tally_dispatch_t; + auto *data = new tally_dispatch_t; + *usr_data = data; + + /* Backend information must match enum backend_e in xprof_utils.hpp */ + data->backend_level = { + 2, // BACKEND_UNKNOWN + 2, // BACKEND_ZE + 2, // BACKEND_OPENCL + 2, // BACKEND_CUDA + 1, // BACKEND_OMP_TARGET_OPERATIONS + 0, // BACKEND_OMP + 2, // BACKEND_HIP + }; } void btx_read_params(void *btx_handle, void *usr_data, btx_params_t *usr_params) { tally_dispatch_t *data = (tally_dispatch_t *)usr_data; data->params = usr_params; + + // Consumes key:value pairs in the stringstream k1:v1,..,kn:vn + std::stringstream tokens{data->params->backend_level}; + std::string tmp; + while (std::getline(tokens, tmp, ',')) { + std::stringstream tmp_string{tmp}; + std::string k,v; + std::getline(tmp_string, k, ':'); + int id = get_backend_id(k); + assert((id > 0) && "Backend not found. Please check --backend-level format."); + std::getline(tmp_string, v); + data->backend_level[id] = std::stoi(v); + } } void btx_finalize_usr_data(void *btx_handle, void *usr_data) { @@ -127,7 +165,7 @@ static void host_usr_callback(void *btx_handle, void *usr_data, const char *host tally_dispatch_t *data = (tally_dispatch_t *)usr_data; TallyCoreTime a{dur, (uint64_t)err}; - const int level = backend_level[backend_id]; + const int level = data->backend_level[backend_id]; data->host_backend_name[level].insert(backend_name[backend_id]); data->host[level][hpt_function_name_t(hostname, vpid, vtid, name)] += a; } @@ -154,7 +192,7 @@ static void traffic_usr_callback(void *btx_handle, void *usr_data, const char *h tally_dispatch_t *data = (tally_dispatch_t *)usr_data; TallyCoreByte a{(uint64_t)size, false}; - const int level = backend_level[backend]; + const int level = data->backend_level[backend]; data->traffic_backend_name[level].insert(backend_name[backend]); data->traffic[level][hpt_function_name_t(hostname, vpid, vtid, name)] += a; } diff --git a/xprof/tally.hpp b/xprof/tally.hpp index d8b4db22..f9741da7 100644 --- a/xprof/tally.hpp +++ b/xprof/tally.hpp @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include "json.hpp" #include "my_demangle.h" diff --git a/xprof/xprof.sh.erb.in b/xprof/xprof.sh.erb.in index c950c6da..c926344b 100644 --- a/xprof/xprof.sh.erb.in +++ b/xprof/xprof.sh.erb.in @@ -100,6 +100,7 @@ display_help() { echo " -l, --timeline Dump the timeline. Will create a `out.pftrace` file that can be opened in perfetto (https://ui.perfetto.dev/#!/viewer)" echo " -j, --json Summary will be printed as json" echo " -m, --tracing-mode [minimal, default, full]" + echo " --backend-level Update tally default backend levels" echo " --asm Dump in your current directory low-level kernels information (asm, isa, visa, ...)" echo " --no-save Data will be processed on-the-fly" echo " --mangle Use mangled name" @@ -521,6 +522,7 @@ while (( "$#" )); do -l | --timeline) shift; timeline=true ;; -j | --json) shift; bt_tally_argv+=" --display_mode=json" ;; -m | --tracing-mode) shift; tracing_mode=$1; shift ;; + --backend-level) shift; bt_tally_argv+=" --backend_level=$1"; shift ;; --no-save) shift; procesing_mode="on-the-fly" ;; --traced-ranks) shift; traced_ranks=$1; shift ;; --asm) shift; asm=true ;;