Skip to content

Commit

Permalink
Backend level argument for iprof (#93)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* 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 <[email protected]>

* Update utils/xprof_utils.hpp

Co-authored-by: Brice Videau <[email protected]>

* Update xprof/tally.cpp

Co-authored-by: Brice Videau <[email protected]>

* 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 <[email protected]>
Co-authored-by: Brice Videau <[email protected]>
  • Loading branch information
3 people authored Jun 30, 2023
1 parent 2e2edd0 commit 4defc27
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 22 deletions.
3 changes: 2 additions & 1 deletion utils/babeltrace_thapi.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion utils/xprof_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,3 @@ bt_message* create_traffic_message(const char *hostname, const process_id_t proc

return message;
}

37 changes: 20 additions & 17 deletions utils/xprof_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@
#include <string>
#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;
Expand Down
2 changes: 2 additions & 0 deletions xprof/btx_tally_params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
:type: integer_unsigned
- :name: display_kernel_verbose
:type: bool
- :name: backend_level
:type: string
44 changes: 41 additions & 3 deletions xprof/tally.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include "tally.hpp"
#include <string>
#include <array>
#include <cassert>
#include <sstream> // std::stringstream, std::stringbuf

//! User data collection structure.
//! It is used to collect interval messages data, once data is collected,
Expand All @@ -7,6 +11,8 @@ struct tally_dispatch_s {
//! User params provided to the user component.
btx_params_t *params;

std::array<int, BACKEND_MAX>backend_level;

std::map<backend_level_t, std::set<const char *>> host_backend_name;
std::map<backend_level_t, std::set<const char *>> traffic_backend_name;

Expand All @@ -32,14 +38,46 @@ void print_metadata(std::vector<std::string> 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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions xprof/tally.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <tuple>
#include <unordered_map>
#include <vector>
#include <string>
#include <array>

#include "json.hpp"
#include "my_demangle.h"
Expand Down
2 changes: 2 additions & 0 deletions xprof/xprof.sh.erb.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 <mode> [minimal, default, full]"
echo " --backend-level <name:value,...> 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"
Expand Down Expand Up @@ -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 ;;
Expand Down

0 comments on commit 4defc27

Please sign in to comment.