forked from OSchip/llvm-project
[OpenMP] Consolidate error handling and debug messages in Libomptarget
Summary: This patch consolidates the error handling and messaging routines to a single file omptargetmessage. The goal is to simplify the error handling interface prior to adding more error handling support Reviewers: jdoerfert grokos ABataev AndreyChurbanov ronlieb JonChesterfield ye-luo tianshilei1992 Subscribers: danielkiss guansong jvesely kerbowa nhaehnle openmp-commits sstefan1 yaxunl
This commit is contained in:
parent
99f3b231cb
commit
ae95ceeb8f
openmp/libomptarget
include
plugins
src
|
@ -0,0 +1,136 @@
|
|||
//===------- Debug.h - Target independent OpenMP target RTL -- C++ --------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Routines used to provide debug messages and information from libomptarget
|
||||
// and plugin RTLs to the user.
|
||||
//
|
||||
// Each plugin RTL and libomptarget define TARGET_NAME and DEBUG_PREFIX for use
|
||||
// when sending messages to the user. These indicate which RTL sent the message
|
||||
//
|
||||
// Debug and information messages are controlled by the environment variables
|
||||
// LIBOMPTARGET_DEBUG and LIBOMPTARGET_INFO which is set upon initialization
|
||||
// of libomptarget or the plugin RTL.
|
||||
//
|
||||
// To printf a pointer in hex with a fixed width of 16 digits and a leading 0x,
|
||||
// use printf("ptr=" DPxMOD "...\n", DPxPTR(ptr));
|
||||
//
|
||||
// DPxMOD expands to:
|
||||
// "0x%0*" PRIxPTR
|
||||
// where PRIxPTR expands to an appropriate modifier for the type uintptr_t on a
|
||||
// specific platform, e.g. "lu" if uintptr_t is typedef'd as unsigned long:
|
||||
// "0x%0*lu"
|
||||
//
|
||||
// Ultimately, the whole statement expands to:
|
||||
// printf("ptr=0x%0*lu...\n", // the 0* modifier expects an extra argument
|
||||
// // specifying the width of the output
|
||||
// (int)(2*sizeof(uintptr_t)), // the extra argument specifying the width
|
||||
// // 8 digits for 32bit systems
|
||||
// // 16 digits for 64bit
|
||||
// (uintptr_t) ptr);
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#ifndef _OMPTARGET_DEBUG_H
|
||||
#define _OMPTARGET_DEBUG_H
|
||||
|
||||
static inline int getInfoLevel() {
|
||||
static int InfoLevel = -1;
|
||||
if (InfoLevel >= 0)
|
||||
return InfoLevel;
|
||||
|
||||
if (char *EnvStr = getenv("LIBOMPTARGET_INFO"))
|
||||
InfoLevel = std::stoi(EnvStr);
|
||||
|
||||
return InfoLevel;
|
||||
}
|
||||
|
||||
static inline int getDebugLevel() {
|
||||
static int DebugLevel = -1;
|
||||
if (DebugLevel >= 0)
|
||||
return DebugLevel;
|
||||
|
||||
if (char *EnvStr = getenv("LIBOMPTARGET_DEBUG"))
|
||||
DebugLevel = std::stoi(EnvStr);
|
||||
|
||||
return DebugLevel;
|
||||
}
|
||||
|
||||
#ifndef __STDC_FORMAT_MACROS
|
||||
#define __STDC_FORMAT_MACROS
|
||||
#endif
|
||||
#include <inttypes.h>
|
||||
#undef __STDC_FORMAT_MACROS
|
||||
|
||||
#define DPxMOD "0x%0*" PRIxPTR
|
||||
#define DPxPTR(ptr) ((int)(2 * sizeof(uintptr_t))), ((uintptr_t)(ptr))
|
||||
#define GETNAME2(name) #name
|
||||
#define GETNAME(name) GETNAME2(name)
|
||||
|
||||
// Messaging interface
|
||||
#define MESSAGE0(_str) \
|
||||
do { \
|
||||
fprintf(stderr, GETNAME(TARGET_NAME) " message: %s\n", _str); \
|
||||
} while (0)
|
||||
|
||||
#define MESSAGE(_str, ...) \
|
||||
do { \
|
||||
fprintf(stderr, GETNAME(TARGET_NAME) " message: " _str "\n", __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define FATAL_MESSAGE0(_num, _str) \
|
||||
do { \
|
||||
fprintf(stderr, GETNAME(TARGET_NAME) " fatal error %d: %s\n", _num, _str); \
|
||||
abort(); \
|
||||
} while (0)
|
||||
|
||||
#define FATAL_MESSAGE(_num, _str, ...) \
|
||||
do { \
|
||||
fprintf(stderr, GETNAME(TARGET_NAME) " fatal error %d:" _str "\n", _num, \
|
||||
__VA_ARGS__); \
|
||||
abort(); \
|
||||
} while (0)
|
||||
|
||||
#define FAILURE_MESSAGE(...) \
|
||||
do { \
|
||||
fprintf(stderr, GETNAME(TARGET_NAME) " error: "); \
|
||||
fprintf(stderr, __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
// Debugging messages
|
||||
#ifdef OMPTARGET_DEBUG
|
||||
#include <stdio.h>
|
||||
|
||||
#define DEBUGP(prefix, ...) \
|
||||
{ \
|
||||
fprintf(stderr, "%s --> ", prefix); \
|
||||
fprintf(stderr, __VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define DP(...) \
|
||||
do { \
|
||||
if (getDebugLevel() > 0) { \
|
||||
DEBUGP(DEBUG_PREFIX, __VA_ARGS__); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
#define REPORT(...) \
|
||||
do { \
|
||||
if (getDebugLevel() > 0) { \
|
||||
DP(__VA_ARGS__); \
|
||||
} else { \
|
||||
FAILURE_MESSAGE(__VA_ARGS__); \
|
||||
} \
|
||||
} while (false)
|
||||
#else
|
||||
#define DEBUGP(prefix, ...) \
|
||||
{}
|
||||
#define DP(...) \
|
||||
{}
|
||||
#define REPORT(...) FAILURE_MESSAGE(__VA_ARGS__);
|
||||
#endif // OMPTARGET_DEBUG
|
||||
|
||||
#endif // _OMPTARGET_DEBUG_H
|
|
@ -261,45 +261,6 @@ void __kmpc_push_target_tripcount(int64_t device_id, uint64_t loop_tripcount);
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef __STDC_FORMAT_MACROS
|
||||
#define __STDC_FORMAT_MACROS
|
||||
#endif
|
||||
|
||||
#include <inttypes.h>
|
||||
#define DPxMOD "0x%0*" PRIxPTR
|
||||
#define DPxPTR(ptr) ((int)(2*sizeof(uintptr_t))), ((uintptr_t) (ptr))
|
||||
|
||||
/*
|
||||
* To printf a pointer in hex with a fixed width of 16 digits and a leading 0x,
|
||||
* use printf("ptr=" DPxMOD "...\n", DPxPTR(ptr));
|
||||
*
|
||||
* DPxMOD expands to:
|
||||
* "0x%0*" PRIxPTR
|
||||
* where PRIxPTR expands to an appropriate modifier for the type uintptr_t on a
|
||||
* specific platform, e.g. "lu" if uintptr_t is typedef'd as unsigned long:
|
||||
* "0x%0*lu"
|
||||
*
|
||||
* Ultimately, the whole statement expands to:
|
||||
* printf("ptr=0x%0*lu...\n", // the 0* modifier expects an extra argument
|
||||
* // specifying the width of the output
|
||||
* (int)(2*sizeof(uintptr_t)), // the extra argument specifying the width
|
||||
* // 8 digits for 32bit systems
|
||||
* // 16 digits for 64bit
|
||||
* (uintptr_t) ptr);
|
||||
*/
|
||||
|
||||
#ifdef OMPTARGET_DEBUG
|
||||
#include <stdio.h>
|
||||
#define DEBUGP(prefix, ...) \
|
||||
{ \
|
||||
fprintf(stderr, "%s --> ", prefix); \
|
||||
fprintf(stderr, __VA_ARGS__); \
|
||||
}
|
||||
#else
|
||||
#define DEBUGP(prefix, ...) \
|
||||
{}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
#else
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
|
||||
#include "internal.h"
|
||||
|
||||
#include "Debug.h"
|
||||
#include "omptargetplugin.h"
|
||||
|
||||
// Get static gpu grid values from clang target-specific constants managed
|
||||
|
@ -101,28 +102,13 @@ static constexpr unsigned AMDGPUGpuGridValues[] = {
|
|||
#ifndef TARGET_NAME
|
||||
#define TARGET_NAME AMDHSA
|
||||
#endif
|
||||
#define DEBUG_PREFIX "Target " GETNAME(TARGET_NAME) " RTL"
|
||||
|
||||
int print_kernel_trace;
|
||||
|
||||
// Size of the target call stack struture
|
||||
uint32_t TgtStackItemSize = 0;
|
||||
|
||||
#ifdef OMPTARGET_DEBUG
|
||||
static int DebugLevel = 0;
|
||||
|
||||
#define GETNAME2(name) #name
|
||||
#define GETNAME(name) GETNAME2(name)
|
||||
#define DP(...) \
|
||||
do { \
|
||||
if (DebugLevel > 0) { \
|
||||
DEBUGP("Target " GETNAME(TARGET_NAME) " RTL", __VA_ARGS__); \
|
||||
} \
|
||||
} while (false)
|
||||
#else // OMPTARGET_DEBUG
|
||||
#define DP(...) \
|
||||
{}
|
||||
#endif // OMPTARGET_DEBUG
|
||||
|
||||
#undef check // Drop definition from internal.h
|
||||
#ifdef OMPTARGET_DEBUG
|
||||
#define check(msg, status) \
|
||||
|
@ -476,11 +462,6 @@ public:
|
|||
}
|
||||
|
||||
RTLDeviceInfoTy() {
|
||||
#ifdef OMPTARGET_DEBUG
|
||||
if (char *envStr = getenv("LIBOMPTARGET_DEBUG"))
|
||||
DebugLevel = std::stoi(envStr);
|
||||
#endif // OMPTARGET_DEBUG
|
||||
|
||||
// LIBOMPTARGET_KERNEL_TRACE provides a kernel launch trace to stderr
|
||||
// anytime. You do not need a debug library build.
|
||||
// 0 => no tracing
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if !(defined(_OMPTARGET_H_) && defined(DP))
|
||||
#error Include elf_common.c in the plugin source AFTER omptarget.h has been\
|
||||
included and macro DP(...) has been defined.
|
||||
#if !(defined(_OMPTARGET_DEBUG_H))
|
||||
#error Include elf_common.c in the plugin source AFTER Debug.h has\
|
||||
been included.
|
||||
#endif
|
||||
|
||||
#include <elf.h>
|
||||
|
|
|
@ -19,35 +19,23 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Debug.h"
|
||||
#include "omptargetplugin.h"
|
||||
|
||||
#ifndef TARGET_NAME
|
||||
#define TARGET_NAME CUDA
|
||||
#endif
|
||||
|
||||
#ifdef OMPTARGET_DEBUG
|
||||
static int DebugLevel = 0;
|
||||
|
||||
#define GETNAME2(name) #name
|
||||
#define GETNAME(name) GETNAME2(name)
|
||||
#define DP(...) \
|
||||
do { \
|
||||
if (DebugLevel > 0) { \
|
||||
DEBUGP("Target " GETNAME(TARGET_NAME) " RTL", __VA_ARGS__); \
|
||||
} \
|
||||
} while (false)
|
||||
#define DEBUG_PREFIX "Target " GETNAME(TARGET_NAME) " RTL"
|
||||
|
||||
// Utility for retrieving and printing CUDA error string.
|
||||
#define CUDA_ERR_STRING(err) \
|
||||
do { \
|
||||
if (DebugLevel > 0) { \
|
||||
const char *errStr; \
|
||||
cuGetErrorString(err, &errStr); \
|
||||
DEBUGP("Target " GETNAME(TARGET_NAME) " RTL", "CUDA error is: %s\n", errStr); \
|
||||
} \
|
||||
#ifdef OMPTARGET_DEBUG
|
||||
#define CUDA_ERR_STRING(err) \
|
||||
do { \
|
||||
if (getDebugLevel() > 0) { \
|
||||
const char *errStr; \
|
||||
cuGetErrorString(err, &errStr); \
|
||||
DP("CUDA error is: %s\n", errStr); \
|
||||
} \
|
||||
} while (false)
|
||||
#else // OMPTARGET_DEBUG
|
||||
#define DP(...) {}
|
||||
#define CUDA_ERR_STRING(err) {}
|
||||
#endif // OMPTARGET_DEBUG
|
||||
|
||||
|
@ -338,10 +326,6 @@ public:
|
|||
DeviceRTLTy()
|
||||
: NumberOfDevices(0), EnvNumTeams(-1), EnvTeamLimit(-1),
|
||||
RequiresFlags(OMP_REQ_UNDEFINED) {
|
||||
#ifdef OMPTARGET_DEBUG
|
||||
if (const char *EnvStr = getenv("LIBOMPTARGET_DEBUG"))
|
||||
DebugLevel = std::stoi(EnvStr);
|
||||
#endif // OMPTARGET_DEBUG
|
||||
|
||||
DP("Start initializing CUDA\n");
|
||||
|
||||
|
|
|
@ -22,31 +22,18 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Debug.h"
|
||||
#include "omptargetplugin.h"
|
||||
|
||||
#ifndef TARGET_NAME
|
||||
#define TARGET_NAME Generic ELF - 64bit
|
||||
#endif
|
||||
#define DEBUG_PREFIX "TARGET " GETNAME(TARGET_NAME) " RTL"
|
||||
|
||||
#ifndef TARGET_ELF_ID
|
||||
#define TARGET_ELF_ID 0
|
||||
#endif
|
||||
|
||||
#ifdef OMPTARGET_DEBUG
|
||||
static int DebugLevel = 0;
|
||||
|
||||
#define GETNAME2(name) #name
|
||||
#define GETNAME(name) GETNAME2(name)
|
||||
#define DP(...) \
|
||||
do { \
|
||||
if (DebugLevel > 0) { \
|
||||
DEBUGP("Target " GETNAME(TARGET_NAME) " RTL", __VA_ARGS__); \
|
||||
} \
|
||||
} while (false)
|
||||
#else // OMPTARGET_DEBUG
|
||||
#define DP(...) {}
|
||||
#endif // OMPTARGET_DEBUG
|
||||
|
||||
#include "../../common/elf_common.c"
|
||||
|
||||
#define NUMBER_OF_DEVICES 4
|
||||
|
@ -107,11 +94,6 @@ public:
|
|||
}
|
||||
|
||||
RTLDeviceInfoTy(int32_t num_devices) {
|
||||
#ifdef OMPTARGET_DEBUG
|
||||
if (char *envStr = getenv("LIBOMPTARGET_DEBUG")) {
|
||||
DebugLevel = std::stoi(envStr);
|
||||
}
|
||||
#endif // OMPTARGET_DEBUG
|
||||
|
||||
FuncGblEntries.resize(num_devices);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "Debug.h"
|
||||
#include "omptargetplugin.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
@ -29,21 +30,9 @@
|
|||
#define TARGET_ELF_ID 0
|
||||
#endif
|
||||
|
||||
#ifdef OMPTARGET_DEBUG
|
||||
static int DebugLevel = 0;
|
||||
#define TARGET_NAME VE
|
||||
|
||||
#define GETNAME2(name) #name
|
||||
#define GETNAME(name) GETNAME2(name)
|
||||
#define DP(...) \
|
||||
do { \
|
||||
if (DebugLevel > 0) { \
|
||||
DEBUGP("Target " GETNAME(TARGET_NAME) " RTL", __VA_ARGS__); \
|
||||
} \
|
||||
} while (false)
|
||||
#else // OMPTARGET_DEBUG
|
||||
#define DP(...) \
|
||||
{}
|
||||
#endif // OMPTARGET_DEBUG
|
||||
#define DEBUG_PREFIX "Target " GETNAME(TARGET_NAME) " RTL"
|
||||
|
||||
#include "../../common/elf_common.c"
|
||||
|
||||
|
@ -111,11 +100,6 @@ public:
|
|||
}
|
||||
|
||||
RTLDeviceInfoTy() {
|
||||
#ifdef OMPTARGET_DEBUG
|
||||
if (char *envStr = getenv("LIBOMPTARGET_DEBUG")) {
|
||||
DebugLevel = std::stoi(envStr);
|
||||
}
|
||||
#endif // OMPTARGET_DEBUG
|
||||
|
||||
struct ve_nodeinfo node_info;
|
||||
ve_node_info(&node_info);
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <omptarget.h>
|
||||
|
||||
#include "device.h"
|
||||
#include "private.h"
|
||||
#include "rtl.h"
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <omptarget.h>
|
||||
|
||||
#include "device.h"
|
||||
#include "private.h"
|
||||
#include "rtl.h"
|
||||
|
@ -62,7 +60,7 @@ static void HandleTargetOutcome(bool success) {
|
|||
break;
|
||||
case tgt_mandatory:
|
||||
if (!success) {
|
||||
if (InfoLevel > 0)
|
||||
if (getInfoLevel() > 0)
|
||||
MESSAGE0("LIBOMPTARGET_INFO is not supported yet");
|
||||
FATAL_MESSAGE0(1, "failure of target construct while offloading is mandatory");
|
||||
}
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <omptarget.h>
|
||||
|
||||
#include "device.h"
|
||||
#include "private.h"
|
||||
#include "rtl.h"
|
||||
|
@ -20,11 +18,6 @@
|
|||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
#ifdef OMPTARGET_DEBUG
|
||||
int DebugLevel = 0;
|
||||
#endif // OMPTARGET_DEBUG
|
||||
int InfoLevel = 0;
|
||||
|
||||
/* All begin addresses for partially mapped structs must be 8-aligned in order
|
||||
* to ensure proper alignment of members. E.g.
|
||||
*
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#define _OMPTARGET_PRIVATE_H
|
||||
|
||||
#include <omptarget.h>
|
||||
#include <Debug.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
@ -79,39 +80,6 @@ typedef int (*TargetDataFuncPtrTy)(DeviceTy &, int32_t, void **, void **,
|
|||
int64_t *, int64_t *, void **,
|
||||
__tgt_async_info *);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// implementation for messages
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define MESSAGE0(_str) \
|
||||
do { \
|
||||
fprintf(stderr, "Libomptarget message: %s\n", _str); \
|
||||
} while (0)
|
||||
|
||||
#define MESSAGE(_str, ...) \
|
||||
do { \
|
||||
fprintf(stderr, "Libomptarget message: " _str "\n", __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define FATAL_MESSAGE0(_num, _str) \
|
||||
do { \
|
||||
fprintf(stderr, "Libomptarget fatal error %d: %s\n", _num, _str); \
|
||||
abort(); \
|
||||
} while (0)
|
||||
|
||||
#define FATAL_MESSAGE(_num, _str, ...) \
|
||||
do { \
|
||||
fprintf(stderr, "Libomptarget fatal error %d:" _str "\n", _num, \
|
||||
__VA_ARGS__); \
|
||||
abort(); \
|
||||
} while (0)
|
||||
|
||||
#define FAILURE_MESSAGE(...) \
|
||||
do { \
|
||||
fprintf(stderr, "Libomptarget error: "); \
|
||||
fprintf(stderr, __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
// Implemented in libomp, they are called from within __tgt_* functions.
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -125,32 +93,7 @@ int __kmpc_get_target_offload(void) __attribute__((weak));
|
|||
}
|
||||
#endif
|
||||
|
||||
extern int InfoLevel;
|
||||
#ifdef OMPTARGET_DEBUG
|
||||
extern int DebugLevel;
|
||||
|
||||
#define DP(...) \
|
||||
do { \
|
||||
if (DebugLevel > 0) { \
|
||||
DEBUGP("Libomptarget", __VA_ARGS__); \
|
||||
} \
|
||||
} while (false)
|
||||
#else // OMPTARGET_DEBUG
|
||||
#define DP(...) {}
|
||||
#endif // OMPTARGET_DEBUG
|
||||
|
||||
// Report debug messages that result in offload failure always
|
||||
#ifdef OMPTARGET_DEBUG
|
||||
#define REPORT(...) \
|
||||
do { \
|
||||
if (DebugLevel > 0) { \
|
||||
DP(__VA_ARGS__); \
|
||||
} else { \
|
||||
FAILURE_MESSAGE(__VA_ARGS__); \
|
||||
} \
|
||||
} while (false)
|
||||
#else
|
||||
#define REPORT(...) FAILURE_MESSAGE(__VA_ARGS__);
|
||||
#endif
|
||||
#define TARGET_NAME Libomptarget
|
||||
#define DEBUG_PREFIX GETNAME(TARGET_NAME)
|
||||
|
||||
#endif
|
||||
|
|
|
@ -61,16 +61,6 @@ __attribute__((destructor(101))) void deinit() {
|
|||
}
|
||||
|
||||
void RTLsTy::LoadRTLs() {
|
||||
|
||||
if (char *envStr = getenv("LIBOMPTARGET_INFO")) {
|
||||
InfoLevel = std::stoi(envStr);
|
||||
}
|
||||
#ifdef OMPTARGET_DEBUG
|
||||
if (char *envStr = getenv("LIBOMPTARGET_DEBUG")) {
|
||||
DebugLevel = std::stoi(envStr);
|
||||
}
|
||||
#endif // OMPTARGET_DEBUG
|
||||
|
||||
// Parse environment variable OMP_TARGET_OFFLOAD (if set)
|
||||
TargetOffloadPolicy = (kmp_target_offload_kind_t) __kmpc_get_target_offload();
|
||||
if (TargetOffloadPolicy == tgt_disabled) {
|
||||
|
|
Loading…
Reference in New Issue