Skip to content

Commit f30f5ce

Browse files
authored
More omp support (#347)
* first pass * remove deadcode * missing file... * passing test * shorter name * new name * fix test * removed unused input
1 parent dcae3f3 commit f30f5ce

14 files changed

+239
-86
lines changed

omp/Makefile.am

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,17 @@ OMP_LIB_GEN = \
6464

6565
EXTRA_DIST += \
6666
$(OMP_LIB_GEN) \
67-
$(srcdir)/ompt_meta_parameters.yaml
67+
$(srcdir)/ompt_meta_parameters.yaml \
68+
btx_ompmatching_model.yaml
6869

6970
omp_babeltrace_model.yaml: $(srcdir)/gen_babeltrace_omp_model.rb $(OMP_LIB_GEN) $(OMP_MODEL)
7071
SRC_DIR=$(srcdir) $(RUBY) $< > $@
7172

7273
btx_omp_model.yaml: $(top_srcdir)/utils/babeltrace_to_metababel_model.rb omp_babeltrace_model.yaml
7374
SRC_DIR=$(srcdir) $(RUBY) $^ > $@
7475

75-
$(BTX_OMP_GENERATED) &: $(top_srcdir)/xprof/btx_interval_model.yaml btx_omp_model.yaml
76-
$(METABABEL) -u btx_omp_model.yaml -d $(top_srcdir)/xprof/btx_interval_model.yaml -t FILTER -o btx_filter_omp -p ompinterval -c interval -i ompt.h.include
76+
$(BTX_OMP_GENERATED) &: $(top_srcdir)/xprof/btx_interval_model.yaml btx_omp_model.yaml btx_ompmatching_model.yaml
77+
$(METABABEL) -u btx_omp_model.yaml -d $(top_srcdir)/xprof/btx_interval_model.yaml -t FILTER -o btx_filter_omp -p ompinterval -c interval --matching $(srcdir)/btx_ompmatching_model.yaml -i ompt.h.include
7778

7879
CLEANFILES += \
7980
omp_babeltrace_model.yaml \
@@ -196,9 +197,7 @@ data_DATA = \
196197
# Tests
197198

198199
TRACE_COMMON = \
199-
tests/data_op.thapi_text_pretty \
200200
tests/target.thapi_text_pretty \
201-
tests/submit.thapi_text_pretty \
202201
tests/data_op_emi.thapi_text_pretty \
203202
tests/target_emi.thapi_text_pretty \
204203
tests/submit_emi.thapi_text_pretty

omp/btx_ompinterval_callbacks.cpp

Lines changed: 151 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
#include "magic_enum.hpp"
22
#include "ompt.h.include"
33
#include "xprof_utils.hpp"
4+
#include <algorithm>
5+
#include <iostream>
46
#include <metababel/metababel.h>
5-
#include <optional>
7+
#include <sstream>
68
#include <string>
79
#include <unordered_map>
810

911
using hpt_function_name_omp_t = std::tuple<hostname_t, process_id_t, thread_id_t, std::string>;
1012

1113
struct data_s {
1214
std::unordered_map<hpt_function_name_omp_t, uint64_t> host_start;
15+
std::unordered_map<std::tuple<std::string, std::string>, std::string> cached_build_name;
1316
};
1417
typedef struct data_s data_t;
1518

@@ -19,7 +22,7 @@ static void btx_finalize_component(void *usr_data) { delete static_cast<data_t *
1922

2023
// Get the start of the "ompt_scope" or return empty optional
2124
static std::optional<int64_t> set_or_get_start(void *usr_data, hpt_function_name_omp_t key,
22-
ompt_scope_endpoint_t endpoint, int64_t ts) {
25+
ompt_scope_endpoint_t endpoint, int64_t ts) {
2326
auto state = static_cast<data_t *>(usr_data);
2427
switch (endpoint) {
2528
case ompt_scope_begin:
@@ -34,96 +37,181 @@ static std::optional<int64_t> set_or_get_start(void *usr_data, hpt_function_name
3437
}
3538
}
3639

37-
static void host_op_callback(void *btx_handle, void *usr_data, int64_t ts, const char *hostname,
38-
int64_t vpid, uint64_t vtid, ompt_scope_endpoint_t endpoint,
39-
std::string const &op_name) {
40+
// Split on `delimiter`, return unique tokens in sorted order.
41+
static auto split(const std::string &str, char delimiter, size_t offset = 0) {
42+
std::vector<std::string> tokens;
43+
std::stringstream ss(str);
44+
ss.seekg(offset);
45+
std::string token;
46+
while (std::getline(ss, token, delimiter)) {
47+
if (!token.empty())
48+
tokens.push_back(token);
49+
}
50+
return tokens;
51+
}
52+
53+
// Join a vector of strings with `delimiter` in between.
54+
static std::string join(const std::vector<std::string> &v, const std::string &delimiter) {
55+
std::stringstream ss;
56+
bool first = true;
57+
for (const auto &s : v) {
58+
if (!first)
59+
ss << delimiter;
60+
first = false;
61+
ss << s;
62+
}
63+
return ss.str();
64+
}
65+
66+
inline std::string build_name(void *usr_data, const char *event_class_name, void *) {
67+
// Just strip and return
68+
return strip_event_class_name(event_class_name);
69+
}
70+
71+
// Remove element in `kind` who are in the `event_class_name`
72+
template <typename E, typename = std::enable_if_t<std::is_enum_v<E>>>
73+
static std::string build_name(void *usr_data, const char *event_class_name, E kind) {
74+
// ompt_callback_target_emi, ompt_target_enter_data -> ompt_callback_target_emi:enter_data
75+
// ompt_callback_target_emi, ompt_target -> ompt_callback_target_emi:target
76+
auto state = static_cast<data_t *>(usr_data);
77+
78+
// 1) Base name
79+
std::string base = strip_event_class_name(event_class_name);
80+
auto kindName = std::string{magic_enum::enum_name(kind)};
81+
82+
// 2) Cache
83+
const auto key = std::make_tuple(base, kindName);
84+
auto it = state->cached_build_name.find(key);
85+
if (it != state->cached_build_name.end()) {
86+
return it->second;
87+
}
88+
89+
// 3) Tokenize
90+
auto kindTokens = split(kindName, '_', strlen("ompt_"));
91+
auto baseTokens = split(base, '_', strlen("ompt_"));
92+
93+
// 4) set_difference
94+
std::vector<std::string> diffTokens;
95+
std::set_difference(kindTokens.begin(), kindTokens.end(), baseTokens.begin(), baseTokens.end(),
96+
std::back_inserter(diffTokens));
97+
98+
// 5) glue it back together
99+
std::string kindNameProcessed;
100+
if (diffTokens.empty()) {
101+
kindNameProcessed = join(kindTokens, "_");
102+
} else {
103+
kindNameProcessed = join(diffTokens, "_");
104+
}
105+
106+
// 6) Update Cache and Return
107+
it = state->cached_build_name.insert(it, {key, base + ":" + kindNameProcessed});
108+
return it->second;
109+
}
110+
111+
template <typename EnumType = void *>
112+
static void host_op_callback(void *btx_handle, void *usr_data, int64_t ts,
113+
const char *event_class_name, const char *hostname, int64_t vpid,
114+
uint64_t vtid, ompt_scope_endpoint_t endpoint,
115+
EnumType kind = EnumType()) {
116+
117+
std::string op_name = build_name(usr_data, event_class_name, kind);
118+
40119
if (auto start_ts = set_or_get_start(usr_data, {hostname, vpid, vtid, op_name}, endpoint, ts)) {
41120
const bool err = false;
42121
btx_push_message_lttng_host(btx_handle, hostname, vpid, vtid, start_ts.value(), BACKEND_OMP,
43122
op_name.c_str(), (ts - start_ts.value()), err);
44123
}
45124
}
46125

47-
static void host_and_traffic_op_callback(void *btx_handle, void *usr_data, int64_t ts,
48-
const char *hostname, int64_t vpid, uint64_t vtid,
49-
ompt_scope_endpoint_t endpoint, size_t bytes,
50-
std::string const &op_name) {
126+
static void traffic_op_callback(void *btx_handle, void *usr_data, int64_t ts,
127+
const char *event_class_name, const char *hostname, int64_t vpid,
128+
uint64_t vtid, ompt_scope_endpoint_t endpoint, size_t bytes,
129+
ompt_target_data_op_t kind) {
130+
131+
std::string op_name = build_name(usr_data, event_class_name, kind);
132+
51133
if (auto start_ts = set_or_get_start(usr_data, {hostname, vpid, vtid, op_name}, endpoint, ts)) {
52-
const bool err = false;
53-
btx_push_message_lttng_host(btx_handle, hostname, vpid, vtid, start_ts.value(), BACKEND_OMP,
54-
op_name.c_str(), (ts - start_ts.value()), err);
55134
btx_push_message_lttng_traffic(btx_handle, hostname, vpid, vtid, start_ts.value(), BACKEND_OMP,
56135
op_name.c_str(), bytes, "");
57136
}
58137
}
59138

60-
static void ompt_callback_target_callback(void *btx_handle, void *usr_data, int64_t ts,
61-
const char *hostname, int64_t vpid, uint64_t vtid,
62-
ompt_target_t kind, ompt_scope_endpoint_t endpoint,
63-
int device_num, ompt_data_t *task_data,
64-
ompt_id_t target_id, void *codeptr_ra) {
65-
std::string op_name(magic_enum::enum_name(kind));
66-
host_op_callback(btx_handle, usr_data, ts, hostname, vpid, vtid, endpoint, op_name);
139+
// _
140+
// / _. | | |_ _. _ | _
141+
// \_ (_| | | |_) (_| (_ |< _>
142+
//
143+
144+
// Host: We support function with 'ompt_sync_region_t'.
145+
// We specialize with:
146+
// - ompt_sync_region_t
147+
// - ompt_target_t
148+
// - ompt_target_data_op_t
149+
static void btx_host_sync_region_callback(void *btx_handle, void *usr_data, int64_t ts,
150+
const char *event_class_name, const char *hostname,
151+
int64_t vpid, uint64_t vtid, ompt_sync_region_t kind,
152+
ompt_scope_endpoint_t endpoint) {
153+
154+
host_op_callback(btx_handle, usr_data, ts, event_class_name, hostname, vpid, vtid, endpoint,
155+
kind);
67156
}
68157

69-
static void ompt_callback_target_emi_callback(void *btx_handle, void *usr_data, int64_t ts,
70-
const char *hostname, int64_t vpid, uint64_t vtid,
71-
ompt_target_t kind, ompt_scope_endpoint_t endpoint,
72-
int device_num, ompt_data_t *task_data,
73-
ompt_data_t *target_task_data,
74-
ompt_data_t *target_data, void *codeptr_ra) {
75-
std::string op_name(magic_enum::enum_name(kind));
76-
host_op_callback(btx_handle, usr_data, ts, hostname, vpid, vtid, endpoint, op_name);
77-
}
158+
static void btx_host_target_callback(void *btx_handle, void *usr_data, int64_t ts,
159+
const char *event_class_name, const char *hostname,
160+
int64_t vpid, uint64_t vtid, ompt_target_t kind,
161+
ompt_scope_endpoint_t endpoint) {
78162

79-
static void ompt_callback_target_data_op_callback(
80-
void *btx_handle, void *usr_data, int64_t ts, const char *hostname, int64_t vpid, uint64_t vtid,
81-
ompt_id_t target_id, ompt_id_t host_op_id, ompt_target_data_op_t optype, void *src_addr,
82-
int src_device_num, void *dest_addr, int dest_device_num, size_t bytes, void *codeptr_ra) {
83-
std::string op_name(magic_enum::enum_name(optype));
84-
host_and_traffic_op_callback(btx_handle, usr_data, ts, hostname, vpid, vtid, ompt_scope_beginend,
85-
bytes, op_name);
163+
host_op_callback(btx_handle, usr_data, ts, event_class_name, hostname, vpid, vtid, endpoint,
164+
kind);
86165
}
87166

88-
static void ompt_callback_target_data_op_emi_callback(
89-
void *btx_handle, void *usr_data, int64_t ts, const char *hostname, int64_t vpid, uint64_t vtid,
90-
ompt_scope_endpoint_t endpoint, ompt_data_t *target_task_data, ompt_data_t *target_data,
91-
ompt_id_t *host_op_id, ompt_target_data_op_t optype, void *src_addr, int src_device_num,
92-
void *dest_addr, int dest_device_num, size_t bytes, void *codeptr_ra) {
93-
std::string op_name(magic_enum::enum_name(optype));
94-
host_and_traffic_op_callback(btx_handle, usr_data, ts, hostname, vpid, vtid, endpoint, bytes,
95-
op_name);
167+
static void btx_host_target_data_callback(void *btx_handle, void *usr_data, int64_t ts,
168+
const char *event_class_name, const char *hostname,
169+
int64_t vpid, uint64_t vtid,
170+
ompt_scope_endpoint_t endpoint,
171+
ompt_target_data_op_t optype) {
172+
173+
host_op_callback(btx_handle, usr_data, ts, event_class_name, hostname, vpid, vtid, endpoint,
174+
optype);
96175
}
97176

98-
static void ompt_callback_target_submit_callback(void *btx_handle, void *usr_data, int64_t ts,
99-
const char *hostname, int64_t vpid, uint64_t vtid,
100-
ompt_id_t target_id, ompt_id_t host_op_id,
101-
unsigned int requested_num_teams) {
102-
// Nothing we can do with them, but add a callback to they are removed from the trace
177+
static void btx_host_callback(void *btx_handle, void *usr_data, int64_t ts,
178+
const char *event_class_name, const char *hostname, int64_t vpid,
179+
uint64_t vtid, ompt_scope_endpoint_t endpoint) {
180+
181+
host_op_callback(btx_handle, usr_data, ts, event_class_name, hostname, vpid, vtid, endpoint);
103182
}
104183

105-
static void ompt_callback_target_submit_emi_callback(void *btx_handle, void *usr_data, int64_t ts,
106-
const char *hostname, int64_t vpid,
107-
uint64_t vtid, ompt_scope_endpoint_t endpoint,
108-
ompt_data_t *target_data,
109-
ompt_id_t *host_op_id,
110-
unsigned int requested_num_teams) {
111-
host_op_callback(btx_handle, usr_data, ts, hostname, vpid, vtid, endpoint,
112-
"ompt_target_submit_emi");
184+
// Traffic
185+
186+
static void btx_traffic_target_data_callback(void *btx_handle, void *usr_data, int64_t ts,
187+
const char *event_class_name, const char *hostname,
188+
int64_t vpid, uint64_t vtid,
189+
ompt_scope_endpoint_t endpoint,
190+
ompt_target_data_op_t optype, size_t bytes) {
191+
192+
traffic_op_callback(btx_handle, usr_data, ts, event_class_name, hostname, vpid, vtid, endpoint,
193+
bytes, optype);
113194
}
114195

196+
// _ _
197+
// |_) _ _ o _ _|_ _ ._ / _. | | |_ _. _ | _
198+
// | \ (/_ (_| | _> |_ (/_ | \_ (_| | | |_) (_| (_ |< _>
199+
// _|
200+
115201
#define REGISTER_ASSOCIATED_CALLBACK(base_name) \
116-
btx_register_callbacks_lttng_ust_ompt_##base_name(btx_handle, &base_name##_callback);
202+
btx_register_callbacks_##base_name(btx_handle, &base_name##_callback);
117203

118204
void btx_register_usr_callbacks(void *btx_handle) {
205+
119206
btx_register_callbacks_initialize_component(btx_handle, &btx_initialize_component);
120207
btx_register_callbacks_finalize_component(btx_handle, &btx_finalize_component);
121-
REGISTER_ASSOCIATED_CALLBACK(ompt_callback_target);
122-
REGISTER_ASSOCIATED_CALLBACK(ompt_callback_target_emi);
123-
REGISTER_ASSOCIATED_CALLBACK(ompt_callback_target_data_op);
124-
REGISTER_ASSOCIATED_CALLBACK(ompt_callback_target_data_op_emi);
125-
REGISTER_ASSOCIATED_CALLBACK(ompt_callback_target_submit);
126-
REGISTER_ASSOCIATED_CALLBACK(ompt_callback_target_submit_emi);
208+
209+
REGISTER_ASSOCIATED_CALLBACK(btx_host_sync_region);
210+
REGISTER_ASSOCIATED_CALLBACK(btx_host_target);
211+
REGISTER_ASSOCIATED_CALLBACK(btx_host_target_data);
212+
REGISTER_ASSOCIATED_CALLBACK(btx_host);
213+
214+
REGISTER_ASSOCIATED_CALLBACK(btx_traffic_target_data);
127215
}
128216

129217
#undef REGISTER_ASSOCIATED_CALLBACK

omp/btx_ompmatching_model.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
:environment:
2+
:entries:
3+
- :name: ^hostname$
4+
:type: string
5+
:stream_classes:
6+
- :default_clock_class: {}
7+
:event_common_context_field_class:
8+
:type: structure
9+
:members:
10+
- :name: ^vpid$
11+
:field_class:
12+
:type: integer_signed
13+
- :name: ^vtid$
14+
:field_class:
15+
:type: integer_unsigned
16+
:event_classes:
17+
- :set_id: btx_host_sync_region
18+
:payload_field_class:
19+
:type: structure
20+
:members:
21+
- :name: ^kind$
22+
:field_class:
23+
:cast_type: ^ompt_sync_region_t$
24+
- :name: ^endpoint$
25+
:field_class:
26+
:cast_type: ^ompt_scope_endpoint_t$
27+
- :set_id: btx_host_target
28+
:payload_field_class:
29+
:type: structure
30+
:members:
31+
- :name: ^kind$
32+
:field_class:
33+
:cast_type: ^ompt_target_t$
34+
- :name: ^endpoint$
35+
:field_class:
36+
:cast_type: ^ompt_scope_endpoint_t$
37+
- :set_id: btx_host_target_data
38+
:payload_field_class:
39+
:type: structure
40+
:members:
41+
- :name: ^endpoint$
42+
:field_class:
43+
:cast_type: ^ompt_scope_endpoint_t$
44+
- :name: ^optype$
45+
:field_class:
46+
:cast_type: ^ompt_target_data_op_t$
47+
- :set_id: btx_host
48+
:domain: all - ( btx_host_sync_region + btx_host_target + btx_host_target_data)
49+
:payload_field_class:
50+
:type: structure
51+
:members:
52+
- :name: ^endpoint$
53+
:field_class:
54+
:cast_type: ^ompt_scope_endpoint_t$
55+
- :set_id: btx_traffic_target_data
56+
:payload_field_class:
57+
:type: structure
58+
:members:
59+
- :name: ^endpoint$
60+
:field_class:
61+
:cast_type: ^ompt_scope_endpoint_t$
62+
- :name: ^optype$
63+
:field_class:
64+
:cast_type: ^ompt_target_data_op_t$
65+
- :name: ^bytes$

omp/tests/data_op.bt_text_pretty

Lines changed: 0 additions & 2 deletions
This file was deleted.

omp/tests/data_op.thapi_text_pretty

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
lttng:host: { hostname = "testhost", vpid = 1, vtid = 1, ts = 1704110400000000000, backend = 5 }, { name = "ompt_target_data_alloc", dur = 1, err = false }
2-
lttng:traffic: { hostname = "testhost", vpid = 1, vtid = 1, ts = 1704110400000000000, backend = 5 }, { name = "ompt_target_data_alloc", size = 4, metadata = "" }
3-
lttng:host: { hostname = "testhost", vpid = 1, vtid = 1, ts = 1704110400000000002, backend = 5 }, { name = "ompt_target_data_delete", dur = 1, err = false }
4-
lttng:traffic: { hostname = "testhost", vpid = 1, vtid = 1, ts = 1704110400000000002, backend = 5 }, { name = "ompt_target_data_delete", size = 4, metadata = "" }
5-
lttng:host: { hostname = "testhost", vpid = 1, vtid = 1, ts = 1704110400000000004, backend = 5 }, { name = "ompt_target_data_associate", dur = 1, err = false }
6-
lttng:traffic: { hostname = "testhost", vpid = 1, vtid = 1, ts = 1704110400000000004, backend = 5 }, { name = "ompt_target_data_associate", size = 4, metadata = "" }
1+
lttng:host: { hostname = "testhost", vpid = 1, vtid = 1, ts = 1704110400000000000, backend = 5 }, { name = "ompt_callback_target_data_op_emi:alloc", dur = 1, err = false }
2+
lttng:traffic: { hostname = "testhost", vpid = 1, vtid = 1, ts = 1704110400000000000, backend = 5 }, { name = "ompt_callback_target_data_op_emi:alloc", size = 4, metadata = "" }
3+
lttng:host: { hostname = "testhost", vpid = 1, vtid = 1, ts = 1704110400000000002, backend = 5 }, { name = "ompt_callback_target_data_op_emi:delete", dur = 1, err = false }
4+
lttng:traffic: { hostname = "testhost", vpid = 1, vtid = 1, ts = 1704110400000000002, backend = 5 }, { name = "ompt_callback_target_data_op_emi:delete", size = 4, metadata = "" }
5+
lttng:host: { hostname = "testhost", vpid = 1, vtid = 1, ts = 1704110400000000004, backend = 5 }, { name = "ompt_callback_target_data_op_emi:associate", dur = 1, err = false }
6+
lttng:traffic: { hostname = "testhost", vpid = 1, vtid = 1, ts = 1704110400000000004, backend = 5 }, { name = "ompt_callback_target_data_op_emi:associate", size = 4, metadata = "" }

omp/tests/submit.bt_text_pretty

Whitespace-only changes.

omp/tests/submit.thapi_text_pretty

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
lttng:host: { hostname = "testhost", vpid = 1, vtid = 1, ts = 1704110400000000000, backend = 5 }, { name = "ompt_target_submit_emi", dur = 1, err = false }
1+
lttng:host: { hostname = "testhost", vpid = 1, vtid = 1, ts = 1704110400000000000, backend = 5 }, { name = "ompt_callback_target_submit_emi", dur = 1, err = false }

omp/tests/target.bt_text_pretty

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
lttng:host: { hostname = "testhost", vpid = 1, vtid = 1, ts = 1704110400000000000, backend = 5 }, { name = "ompt_target", dur = 1, err = false }
1+
lttng:host: { hostname = "testhost", vpid = 1, vtid = 1, ts = 1704110400000000000, backend = 5 }, { name = "ompt_callback_target:target", dur = 1, err = false }

0 commit comments

Comments
 (0)