[OpenMP] Add runtime interface for OpenMP 5.1 error directive

The proposed new interface is for supporting `at(execution)` clause in the
error directive.

Differential Revision: https://reviews.llvm.org/D98448
This commit is contained in:
Hansang Bae 2021-03-11 11:24:29 -06:00
parent 64687f2cc3
commit a6f9cb6adc
8 changed files with 96 additions and 2 deletions

View File

@ -390,8 +390,9 @@ kmpc_set_disp_num_buffers 267
__kmpc_taskred_init 277
__kmpc_taskred_modifier_init 278
__kmpc_omp_target_task_alloc 279
__kmpc_error 281
__kmpc_masked 282
__kmpc_end_masked 283
__kmpc_end_masked 283
%endif
# User API entry points that have both lower- and upper- case versions for Fortran.

View File

@ -455,6 +455,8 @@ AffHWSubsetManyDies "KMP_HW_SUBSET ignored: too many Dies requested."
AffUseGlobCpuidL "%1$s: Affinity capable, using global cpuid leaf %2$d info"
AffNotCapableUseLocCpuidL "%1$s: Affinity not capable, using local cpuid leaf %2$d info"
AffNotUsingHwloc "%1$s: Affinity not capable, using hwloc."
UserDirectedError "%1$s: Encountered user-directed error: %2$s."
UserDirectedWarning "%1$s: Encountered user-directed warning: %2$s."
FailedToCreateTeam "Failed to create teams between lower bound (%1$d) and upper bound (%2$d)."
# --------------------------------------------------------------------------------------------------

View File

@ -1099,6 +1099,13 @@ typedef void (*ompt_callback_error_t) (
const void *codeptr_ra
);
typedef struct ompt_record_error_t {
ompt_severity_t severity;
const char *message;
size_t length;
const void *codeptr_ra;
} ompt_record_error_t;
typedef struct ompd_address_t {
ompd_seg_t segment;
ompd_addr_t address;

View File

@ -4087,6 +4087,13 @@ extern void __kmp_hidden_helper_main_thread_release();
#define KMP_GTID_TO_SHADOW_GTID(gtid) \
((gtid) % (__kmp_hidden_helper_threads_num - 1) + 2)
// Support for error directive
typedef enum kmp_severity_t {
severity_warning = 1,
severity_fatal = 2
} kmp_severity_t;
extern void __kmpc_error(ident_t *loc, int severity, const char *message);
#ifdef __cplusplus
}
#endif

View File

@ -4357,3 +4357,35 @@ int __kmpc_pause_resource(kmp_pause_status_t level) {
}
return __kmp_pause_resource(level);
}
void __kmpc_error(ident_t *loc, int severity, const char *message) {
if (!__kmp_init_serial)
__kmp_serial_initialize();
KMP_ASSERT(severity == severity_warning || severity == severity_fatal);
#if OMPT_SUPPORT
if (ompt_enabled.enabled && ompt_enabled.ompt_callback_error) {
ompt_callbacks.ompt_callback(ompt_callback_error)(
(ompt_severity_t)severity, message, KMP_STRLEN(message),
OMPT_GET_RETURN_ADDRESS(0));
}
#endif // OMPT_SUPPORT
char *src_loc;
if (loc && loc->psource) {
kmp_str_loc_t str_loc = __kmp_str_loc_init(loc->psource, false);
src_loc =
__kmp_str_format("%s:%s:%s", str_loc.file, str_loc.line, str_loc.col);
__kmp_str_loc_free(&str_loc);
} else {
src_loc = __kmp_str_format("unknown");
}
if (severity == severity_warning)
KMP_WARNING(UserDirectedWarning, src_loc, message);
else
KMP_FATAL(UserDirectedError, src_loc, message);
__kmp_str_free(&src_loc);
}

View File

@ -106,6 +106,6 @@
#define ompt_callback_dispatch_implemented ompt_event_UNIMPLEMENTED
#define ompt_callback_error_implemented ompt_event_UNIMPLEMENTED
#define ompt_callback_error_implemented ompt_event_MAY_ALWAYS_OPTIONAL
#endif

View File

@ -1124,6 +1124,15 @@ on_ompt_callback_control_tool(
return 0; //success
}
static void on_ompt_callback_error(ompt_severity_t severity,
const char *message, size_t length,
const void *codeptr_ra) {
printf("%" PRIu64 ": ompt_event_runtime_error: severity=%" PRIu32
", message=%s, length=%" PRIu64 ", codeptr_ra=%p\n",
ompt_get_thread_data()->value, severity, message, (uint64_t)length,
codeptr_ra);
}
int ompt_initialize(
ompt_function_lookup_t lookup,
int initial_device_num,
@ -1173,6 +1182,7 @@ int ompt_initialize(
register_ompt_callback(ompt_callback_task_dependence);
register_ompt_callback(ompt_callback_thread_begin);
register_ompt_callback(ompt_callback_thread_end);
register_ompt_callback(ompt_callback_error);
printf("0: NULL_POINTER=%p\n", (void*)NULL);
return 1; //success
}

View File

@ -0,0 +1,35 @@
// RUN: %libomp-compile-and-run 2>&1 | sort | FileCheck %s
// REQUIRES: ompt
#include <string.h>
#include <stdio.h>
#include "callback.h"
// TODO: use error directive when compiler suppors
typedef void ident_t;
extern void __kmpc_error(ident_t *, int, const char *);
int main() {
#pragma omp parallel num_threads(2)
{
if (omp_get_thread_num() == 0) {
const char *msg = "User message goes here";
printf("0: Message length=%" PRIu64 "\n", (uint64_t)strlen(msg));
__kmpc_error(NULL, ompt_warning, msg);
}
}
return 0;
}
// CHECK: {{^}}0: Message length=[[LENGTH:[0-9]+]]
// CHECK: {{^}}0: NULL_POINTER=[[NULL:.*$]]
// CHECK: {{^}}[[PRIMARY_ID:[0-9]+]]: ompt_event_implicit_task_begin
// CHECK: {{^}}[[PRIMARY_ID]]: ompt_event_runtime_error
// CHECK-SAME: severity=1
// CHECK-SAME: message=User message goes here
// CHECK-SAME: length=[[LENGTH]]
// CHECK-SAME: codeptr_ra={{0x[0-f]+}}
// Message from runtime
// CHECK: {{^}}OMP: Warning{{.*}}User message goes here