Skip to content

Commit a66299d

Browse files
committed
add basic control_tool functionality
1 parent a14b4a1 commit a66299d

File tree

6 files changed

+69
-10
lines changed

6 files changed

+69
-10
lines changed

runtime/src/include/45/omp.h.var

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,16 @@
182182
extern void __KAI_KMPC_CONVENTION kmp_set_warnings_on(void);
183183
extern void __KAI_KMPC_CONVENTION kmp_set_warnings_off(void);
184184

185+
/* OpenMP 5.0 Tool Control */
186+
typedef enum omp_control_tool_result_t {
187+
omp_control_tool_notool = -2,
188+
omp_control_tool_nocallback = -1,
189+
omp_control_tool_success = 0,
190+
omp_control_tool_ignored = 1
191+
} omp_control_tool_result_t;
192+
193+
extern int __KAI_KMPC_CONVENTION omp_control_tool(int, int, void*);
194+
185195
# undef __KAI_KMPC_CONVENTION
186196

187197
/* Warning:

runtime/src/include/45/ompt.h.var

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
/*macro (ompt_callback_target_data_op ompt_callback_target_data_op_t, 9)*/ /* target data op*/ \
9292
/*macro (ompt_callback_target_submit, ompt_callback_target_submit_t, 10)*/ /* target submit*/ \
9393
\
94-
/*macro (ompt_callback_control_tool, ompt_callback_control_tool_t, 11)*/ /* control tool */ \
94+
macro (ompt_callback_control_tool, ompt_callback_control_tool_t, 11) /* control tool */ \
9595
\
9696
/*macro (ompt_callback_device_initialize, ompt_callback_device_initialize_t, 12)*/ /* device initialize */ \
9797
\
@@ -129,7 +129,7 @@
129129
\
130130
\
131131
/*--- Old Events --- */ \
132-
macro (ompt_event_control, ompt_control_callback_t, 29) /* support control calls */ \
132+
//macro (ompt_event_control, ompt_control_callback_t, 29) /* support control calls */ \
133133

134134

135135

@@ -368,10 +368,12 @@ typedef void (*ompt_callback_task_dependence_t) (
368368
ompt_data_t *sink_task_data
369369
);
370370

371-
/* program */
372-
typedef void (*ompt_control_callback_t) (
371+
/* control_tool */
372+
typedef int (*ompt_callback_control_tool_t) (
373373
uint64_t command, /* command of control call */
374-
uint64_t modifier /* modifier of control call */
374+
uint64_t modifier, /* modifier of control call */
375+
void *arg,
376+
const void *codeptr_ra
375377
);
376378

377379
typedef void (*ompt_callback_t)(void);

runtime/src/ompt-event-specific.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#define ompt_callback_thread_begin_implemented ompt_event_MAY_ALWAYS
4848
#define ompt_callback_thread_end_implemented ompt_event_MAY_ALWAYS
4949

50-
#define ompt_event_control_implemented ompt_event_MAY_ALWAYS
50+
#define ompt_callback_control_tool_implemented ompt_event_MAY_ALWAYS
5151

5252
#define ompt_callback_implicit_task_implemented ompt_event_MAY_ALWAYS
5353

runtime/src/ompt-general.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,25 @@ OMPT_API_ROUTINE int ompt_get_ompt_version()
485485
| control
486486
---------------------------------------------------------------------------*/
487487

488-
_OMP_EXTERN void ompt_control(uint64_t command, uint64_t modifier)
488+
_OMP_EXTERN int omp_control_tool(uint64_t command, uint64_t modifier, void *arg)
489489
{
490-
if (ompt_enabled && ompt_callbacks.ompt_callback(ompt_event_control)) {
491-
ompt_callbacks.ompt_callback(ompt_event_control)(command, modifier);
490+
if(ompt_enabled){
491+
if (ompt_callbacks.ompt_callback(ompt_callback_control_tool)) {
492+
return ompt_callbacks.ompt_callback(ompt_callback_control_tool)(
493+
command,
494+
modifier,
495+
arg,
496+
OMPT_GET_RETURN_ADDRESS(0));
497+
}
498+
else {
499+
//TODO: replace hardcoded number by enum entry
500+
return -1;
501+
}
502+
}
503+
else {
504+
//TODO: return value?
505+
//TODO: replace hardcoded number by enum entry
506+
return -2;
492507
}
493508
}
494509

runtime/test/ompt/callback.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,17 @@ on_ompt_callback_thread_end(
565565
//printf("%" PRIu64 ": ompt_event_thread_end: thread_type=%s=%d, thread_id=%" PRIu64 "\n", ompt_get_thread_data()->value, ompt_thread_type_t_values[thread_type], thread_type, thread_data->value);
566566
}
567567

568+
static int
569+
on_ompt_callback_control_tool(
570+
uint64_t command,
571+
uint64_t modifier,
572+
void *arg,
573+
const void *codeptr_ra)
574+
{
575+
printf("%" PRIu64 ": ompt_event_control_tool: command=%" PRIu64 ", modifier=%" PRIu64 ", arg=%p, codeptr_ra=%p\n", ompt_get_thread_data()->value, command, modifier, arg, codeptr_ra);
576+
return 0; //success
577+
}
578+
568579
#define register_callback_t(name, type) \
569580
do{ \
570581
type f_##name = &on_##name; \
@@ -591,7 +602,7 @@ int ompt_initialize(
591602
register_callback(ompt_callback_nest_lock);
592603
register_callback(ompt_callback_sync_region);
593604
register_callback_t(ompt_callback_sync_region_wait, ompt_callback_sync_region_t);
594-
// register_callback(ompt_event_control);
605+
register_callback(ompt_callback_control_tool);
595606
register_callback(ompt_callback_flush);
596607
register_callback(ompt_callback_cancel);
597608
register_callback(ompt_callback_idle);

runtime/test/ompt/misc/control_tool.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %libomp-compile-and-run | FileCheck %s
2+
// REQUIRES: ompt
3+
#include "callback.h"
4+
#include <omp.h>
5+
6+
int main()
7+
{
8+
#pragma omp parallel num_threads(1)
9+
{
10+
omp_control_tool(0, 0, NULL);
11+
}
12+
13+
// Check if libomp supports the callbacks for this test.
14+
// CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_control_tool'
15+
16+
// CHECK: 0: NULL_POINTER=[[NULL:.*$]]
17+
18+
// CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_control_tool: command=0, modifier=0, arg=(nil), codeptr_ra={{0x[0-f]*}}
19+
20+
return 0;
21+
}

0 commit comments

Comments
 (0)