18static void utest_region_name(
void);
19static void utest_disabled_is_noop(
void);
20static void utest_single_region(
void);
21static void utest_nested_regions(
void);
22static void utest_deeply_nested_regions(
void);
23static void utest_sibling_nested_regions(
void);
24static void utest_reregister_destroys_old_handles(
void);
25static void utest_start_only_no_stop_cb(
void);
30 utest_disabled_is_noop();
31 utest_single_region();
32 utest_nested_regions();
33 utest_deeply_nested_regions();
34 utest_sibling_nested_regions();
35 utest_reregister_destroys_old_handles();
36 utest_start_only_no_stop_cb();
70static void * utest_create_cb(
int id,
void *
user_data) {
78static void utest_start_cb(
79 int id,
void * handle,
int depth,
void *
user_data) {
88static void utest_stop_cb(
89 int id,
void * handle,
int depth,
void *
user_data) {
95 utest_record_call(ctx,
STOP_TAG +
id);
98static void utest_destroy_cb(
99 int id,
void * handle,
void *
user_data) {
107static void utest_region_name(
void) {
111 ref_region_names[YAC_INSTR_DIST_GRID_PAIR_NEW] =
112 "distributed grid pair generation";
113 ref_region_names[YAC_INSTR_DIST_GRID_PAIR_DECOMP] =
114 "distributed grid pair decomposition";
115 ref_region_names[YAC_INSTR_DIST_GRID_PAIR_REDIST] =
116 "distributed grid pair redistribution";
117 ref_region_names[YAC_INSTR_DIST_GRID_PAIR_POINT_SEARCH] =
118 "distributed grid pair point search";
119 ref_region_names[YAC_INSTR_DIST_GRID_PAIR_POINT_SEARCH_GC] =
120 "distributed grid pair point search (great circle edges)";
121 ref_region_names[YAC_INSTR_DIST_GRID_PAIR_NNN_SEARCH] =
122 "distributed grid pair n-nearest-neighbour search";
123 ref_region_names[YAC_INSTR_DIST_GRID_PAIR_BND_CIRCLE_SEARCH] =
124 "distributed grid pair bounding circle search";
125 ref_region_names[YAC_INSTR_DIST_GRID_PAIR_DNN_SEARCH] =
126 "distributed grid pair distance-nearest-neighbour search";
127 ref_region_names[YAC_INSTR_DIST_GRID_PAIR_CELL_SEARCH] =
128 "distributed grid pair cell search";
129 ref_region_names[YAC_INSTR_DIST_GRID_PAIR_AUX_GRID] =
130 "distributed grid pair auxiliary grid generation";
131 ref_region_names[YAC_INSTR_DIST_GRID_PAIR_RELOCATE_POINTS] =
132 "distributed grid pair point pair relocation";
133 ref_region_names[YAC_INSTR_DIST_GRID_GLOBAL_TO_LOCAL] =
134 "distributed grid global to local id conversion";
135 ref_region_names[YAC_INSTR_GEN_PROC_SPHERE_PART] =
136 "process sphere part generation";
137 ref_region_names[YAC_INSTR_COMPUTE_TGT_FIELD] =
138 "target field computation (SpMV)";
139 ref_region_names[YAC_INSTR_COMPUTE_TGT_FIELD_DIRECT] =
140 "target field computation (direct copy)";
141 ref_region_names[YAC_INSTR_INTERP_SEARCH] =
142 "interpolation search (method stack)";
143 ref_region_names[YAC_INSTR_INTERP_SEARCH_AVG] =
144 "interpolation search (average)";
145 ref_region_names[YAC_INSTR_INTERP_SEARCH_NCC] =
146 "interpolation search (nearest corner cells)";
147 ref_region_names[YAC_INSTR_INTERP_SEARCH_NNN] =
148 "interpolation search (n-nearest-neighbour)";
149 ref_region_names[YAC_INSTR_INTERP_SEARCH_1NN] =
150 "interpolation search (nearest-neighbour)";
151 ref_region_names[YAC_INSTR_INTERP_SEARCH_ZERO] =
152 "interpolation search (zero)";
153 ref_region_names[YAC_INSTR_INTERP_SEARCH_DNN] =
154 "interpolation search (distance-nearest-neighbour)";
155 ref_region_names[YAC_INSTR_INTERP_SEARCH_CONSERV_1ST] =
156 "interpolation search (1st order conservative)";
157 ref_region_names[YAC_INSTR_INTERP_SEARCH_CONSERV_2ND] =
158 "interpolation search (2nd order conservative)";
159 ref_region_names[YAC_INSTR_INTERP_SEARCH_FIXED] =
160 "interpolation search (fixed value)";
161 ref_region_names[YAC_INSTR_INTERP_SEARCH_FILE] =
162 "interpolation search (user file)";
163 ref_region_names[YAC_INSTR_INTERP_SEARCH_CHECK] =
164 "interpolation search (check)";
165 ref_region_names[YAC_INSTR_INTERP_SEARCH_HCSBB] =
166 "interpolation search (Bernstein Bezier)";
167 ref_region_names[YAC_INSTR_INTERP_SEARCH_CREEP] =
168 "interpolation search (creep)";
169 ref_region_names[YAC_INSTR_INTERP_SEARCH_CALLBACK] =
170 "interpolation search (user callback)";
171 ref_region_names[YAC_INSTR_INTERP_SEARCH_SPMAP] =
172 "interpolation search (source to target map)";
177 PUT_ERR_F(
"yac_instrument_region_name: unexpected NULL for region %zu\n", i);
178 if (!ref_region_names[i] || strcmp(
name, ref_region_names[i]))
180 "yac_instrument_region_name: "
181 "unexpected name for region %zu (%s vs %s)\n",
183 ref_region_names[
i]?ref_region_names[
i]:
"(null)");
187static void utest_disabled_is_noop(
void) {
199static void utest_single_region(
void) {
206 utest_create_cb, utest_start_cb, utest_stop_cb, utest_destroy_cb, &ctx);
214 PUT_ERR(
"single region: create_cb must be called exactly once\n");
215 if (ctx.
start_calls[YAC_INSTR_COMPUTE_TGT_FIELD] != 1)
216 PUT_ERR(
"single region: start_cb must be called exactly once\n");
217 if (ctx.
stop_calls[YAC_INSTR_COMPUTE_TGT_FIELD] != 1)
218 PUT_ERR(
"single region: stop_cb must be called exactly once\n");
220 PUT_ERR(
"single region: start depth must be 0\n");
222 PUT_ERR(
"single region: stop depth must be 0\n");
225 PUT_ERR(
"single region: start_cb must receive the created handle\n");
228 PUT_ERR(
"single region: stop_cb must receive the created handle\n");
237 PUT_ERR(
"single region: create_cb must not be called again\n");
238 if (ctx.
start_calls[YAC_INSTR_COMPUTE_TGT_FIELD] != 2)
239 PUT_ERR(
"single region: start_cb must be called again\n");
240 if (ctx.
stop_calls[YAC_INSTR_COMPUTE_TGT_FIELD] != 2)
241 PUT_ERR(
"single region: stop_cb must be called again\n");
250 PUT_ERR(
"single region: destroy_cb must be called exactly once\n");
253 PUT_ERR(
"single region: destroy_cb must receive the created handle\n");
256 if (ctx.
create_calls[YAC_INSTR_COMPUTE_TGT_FIELD_DIRECT] != 0 ||
258 PUT_ERR(
"single region: untouched region must not be created/destroyed\n");
262static void utest_nested_regions(
void) {
269 utest_create_cb, utest_start_cb, utest_stop_cb, utest_destroy_cb, &ctx);
279 PUT_ERR(
"nested regions: outer region must start at depth 0\n");
281 PUT_ERR(
"nested regions: inner region must start at depth 1\n");
283 PUT_ERR(
"nested regions: inner region must stop at depth 1\n");
285 PUT_ERR(
"nested regions: outer region must stop at depth 0\n");
290 PUT_ERR(
"nested regions: outer region has the wrong handle\n");
293 PUT_ERR(
"nested regions: inner region has the wrong handle\n");
298 int const expected_order[] = {
301 CREATE_TAG + YAC_INSTR_COMPUTE_TGT_FIELD_DIRECT,
302 START_TAG + YAC_INSTR_COMPUTE_TGT_FIELD_DIRECT,
303 STOP_TAG + YAC_INSTR_COMPUTE_TGT_FIELD_DIRECT,
304 STOP_TAG + YAC_INSTR_COMPUTE_TGT_FIELD};
305 int const n_expected =
306 (int)(
sizeof(expected_order) /
sizeof(expected_order[0]));
309 PUT_ERR(
"nested regions: unexpected number of callback invocations\n");
311 for (
int i = 0;
i < n_expected; ++
i)
313 PUT_ERR(
"nested regions: callbacks fired in the wrong order\n");
319static void utest_deeply_nested_regions(
void) {
326 utest_create_cb, utest_start_cb, utest_stop_cb, utest_destroy_cb, &ctx);
332 YAC_INSTR_DIST_GRID_PAIR_NEW, YAC_INSTR_DIST_GRID_PAIR_DECOMP,
333 YAC_INSTR_DIST_GRID_PAIR_REDIST, YAC_INSTR_GEN_PROC_SPHERE_PART};
338 for (
int i = 0;
i < 4; ++
i) {
341 "deeply nested regions: region %d must start at depth %d\n", i, i);
344 "deeply nested regions: region %d must stop at depth %d\n", i, i);
349 int expected_order[8];
350 for (
int i = 0;
i < 4; ++
i) {
354 int const n_start = 8;
355 int const n_expected = n_start + 4;
356 int full_expected[12];
357 memcpy(full_expected, expected_order,
sizeof(expected_order));
358 for (
int i = 0;
i < 4; ++
i)
359 full_expected[n_start + i] =
STOP_TAG +
id[3 - i];
363 "deeply nested regions: unexpected number of callback invocations\n");
365 for (
int i = 0;
i < n_expected; ++
i)
367 PUT_ERR(
"deeply nested regions: callbacks fired in the wrong order\n");
373static void utest_sibling_nested_regions(
void) {
380 utest_create_cb, utest_start_cb, utest_stop_cb, utest_destroy_cb, &ctx);
397 PUT_ERR(
"sibling nested regions: parent must stay at depth 0\n");
400 PUT_ERR(
"sibling nested regions: first sibling must run at depth 1\n");
403 PUT_ERR(
"sibling nested regions: second sibling must run at depth 1\n");
407 if (ctx.
start_calls[YAC_INSTR_COMPUTE_TGT_FIELD] != 1 ||
408 ctx.
stop_calls[YAC_INSTR_COMPUTE_TGT_FIELD] != 1)
409 PUT_ERR(
"sibling nested regions: parent must start/stop exactly once\n");
411 int const expected_order[] = {
414 CREATE_TAG + YAC_INSTR_COMPUTE_TGT_FIELD_DIRECT,
415 START_TAG + YAC_INSTR_COMPUTE_TGT_FIELD_DIRECT,
416 STOP_TAG + YAC_INSTR_COMPUTE_TGT_FIELD_DIRECT,
418 START_TAG + YAC_INSTR_GEN_PROC_SPHERE_PART,
419 STOP_TAG + YAC_INSTR_GEN_PROC_SPHERE_PART,
420 STOP_TAG + YAC_INSTR_COMPUTE_TGT_FIELD};
421 int const n_expected =
422 (int)(
sizeof(expected_order) /
sizeof(expected_order[0]));
426 "sibling nested regions: unexpected number of callback invocations\n");
428 for (
int i = 0;
i < n_expected; ++
i)
431 "sibling nested regions: callbacks fired in the wrong order\n");
437static void utest_reregister_destroys_old_handles(
void) {
444 utest_create_cb, utest_start_cb, utest_stop_cb, utest_destroy_cb, &ctx_old);
453 utest_create_cb, utest_start_cb, utest_stop_cb, utest_destroy_cb, &ctx_new);
457 "reregister: old registration's destroy_cb must be called once "
458 "for the resolved region\n");
460 PUT_ERR(
"reregister: new registration's destroy_cb must not be called\n");
467 if (ctx_new.
create_calls[YAC_INSTR_COMPUTE_TGT_FIELD] != 1)
469 "reregister: new registration must re-run create_cb for a region "
470 "already resolved under the old registration\n");
471 if (ctx_old.
create_calls[YAC_INSTR_COMPUTE_TGT_FIELD] != 1)
472 PUT_ERR(
"reregister: old registration's create_cb must not run again\n");
478 "reregister: clearing callbacks must destroy the new registration's "
482static void utest_start_only_no_stop_cb(
void) {
490 utest_create_cb, utest_start_cb, NULL, utest_destroy_cb, &ctx);
495 if (ctx.
start_calls[YAC_INSTR_COMPUTE_TGT_FIELD] != 1)
496 PUT_ERR(
"start-only: start_cb must still be called\n");
497 if (ctx.
stop_calls[YAC_INSTR_COMPUTE_TGT_FIELD] != 0)
498 PUT_ERR(
"start-only: stop_cb must never be called (it is NULL)\n");
506 if (ctx.
start_calls[YAC_INSTR_COMPUTE_TGT_FIELD] != 2)
507 PUT_ERR(
"start-only: start_cb must be called again\n");
509 PUT_ERR(
"start-only: region must be poppable and restartable at depth 0\n");
514 PUT_ERR(
"start-only: destroy_cb must still be called on clear\n");
void yac_instrument_set_callbacks(yac_instrument_create_cb create_cb, yac_instrument_start_cb start_cb, yac_instrument_stop_cb stop_cb, yac_instrument_destroy_cb destroy_cb, void *user_data)
void yac_instrument_clear_callbacks(void)
const char * yac_instrument_region_name(yac_instrument_region_id id)
#define YAC_INSTRUMENT_START(ID)
Enter an instrumented region.
#define YAC_INSTRUMENT_STOP(ID)
Exit an instrumented region entered with YAC_INSTRUMENT_START(ID).
void * last_stop_handle[YAC_INSTR_REGION_COUNT]
int stop_calls[YAC_INSTR_REGION_COUNT]
int destroy_calls[YAC_INSTR_REGION_COUNT]
void * last_start_handle[YAC_INSTR_REGION_COUNT]
int last_start_depth[YAC_INSTR_REGION_COUNT]
int last_stop_depth[YAC_INSTR_REGION_COUNT]
int create_calls[YAC_INSTR_REGION_COUNT]
int call_order[4 *YAC_INSTR_REGION_COUNT]
void * last_destroy_handle[YAC_INSTR_REGION_COUNT]
int start_calls[YAC_INSTR_REGION_COUNT]
static int dummy_handle_storage[YAC_INSTR_REGION_COUNT]
#define PUT_ERR_F(fmt,...)