Skip to content

Commit

Permalink
common: verbose: add a warn verbose mode to print warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
avmanerikar committed Dec 12, 2024
1 parent eabb074 commit 81277c9
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/common/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void log_manager_t::log(const char *msg, log_level_t log_level) const {
void log_manager_t::set_log_level(const std::string &vmode_str) const {
// The logging level is determined from the verbose mode
// with the following order of decreasing priority:
// [trace, debug, info, error, critical, off]
// [trace, debug, info, warn, error, critical, off]
spdlog::set_level(spdlog::level::off);

if (vmode_str == "-1" || vmode_str == "all") {
Expand All @@ -104,6 +104,8 @@ void log_manager_t::set_log_level(const std::string &vmode_str) const {
|| vmode_str.find("profile") != std::string::npos
|| vmode_str.find("dispatch") != std::string::npos) {
spdlog::set_level(spdlog::level::info);
} else if (vmode_str.find("warn") != std::string::npos) {
spdlog::set_level(spdlog::level::warn);
} else if (vmode_str.find("check") != std::string::npos) {
spdlog::set_level(spdlog::level::err);
} else if (vmode_str.find("error") != std::string::npos) {
Expand Down
4 changes: 2 additions & 2 deletions src/common/stack_checker.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2021-2023 Intel Corporation
* Copyright 2021-2024 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -204,7 +204,7 @@ struct stack_checker_t {
size_t soft_stack_limit_in_bytes
= get_soft_stack_limit() * get_page_size();
if (stack_consumption > soft_stack_limit_in_bytes) {
VERROR(common, stack_checker,
VWARN(common, stack_checker,
"'%s' consumed %lu bytes of "
"stack while the limit is %lu bytes",
context_.c_str(), stack_consumption,
Expand Down
7 changes: 5 additions & 2 deletions src/common/verbose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ uint32_t get_verbose(verbose_t::flag_kind verbosity_kind,
if (s == "profile_exec") k |= verbose_t::exec_profile;
// Enable profiling to external libraries
if (s == "profile_externals") k |= verbose_t::profile_externals;
if (s == "warn") k |= verbose_t::warn;
// we extract debug info debuginfo=XX. ignore if debuginfo is invalid.
if (s.rfind("debuginfo=", 0) == 0)
k |= verbose_t::make_debuginfo(
Expand Down Expand Up @@ -1816,10 +1817,12 @@ dnnl_status_t dnnl_set_verbose(int level) {
if (level < 0 || level > 2) return invalid_arguments;

uint32_t verbose_level = verbose_t::none;
if (level == 1) verbose_level = verbose_t::error | verbose_t::exec_profile;
if (level == 1)
verbose_level
= verbose_t::error | verbose_t::exec_profile | verbose_t::warn;
if (level == 2)
verbose_level = verbose_t::error | verbose_t::exec_profile
| verbose_t::create_profile;
| verbose_t::create_profile | verbose_t::warn;
// we put the lower byte of level as devinfo to preserve backward
// compatibility with historical VERBOSE={1,2}
if (level == 1 || level == 2) verbose_level |= (level << 24);
Expand Down
18 changes: 17 additions & 1 deletion src/common/verbose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,21 @@ struct const_expr_value {
do { \
if (dnnl::impl::get_verbose(verbose_t::error)) { \
VFORMAT(get_msec(), verbose_t::error, apitype, error, "", \
#component "," msg, ##__VA_ARGS__); \
#component "," msg ",%s:%d", ##__VA_ARGS__, __FILENAME__, \
__LINE__); \
} \
} while (0)

// Special syntactic sugar for warnings, plus flush of the output stream
// The difference between the warn and error verbose modes is that the
// verbose error messages are only reserved for printing when an exception is
// thrown or when a status check fails.
#define VWARN(apitype, component, msg, ...) \
do { \
if (dnnl::impl::get_verbose(verbose_t::warn)) { \
VFORMAT(get_msec(), verbose_t::warn, apitype, warn, "", \
#component "," msg ",%s:%d", ##__VA_ARGS__, __FILENAME__, \
__LINE__); \
} \
} while (0)

Expand Down Expand Up @@ -157,6 +171,7 @@ struct verbose_t {
exec_check = 1 << 6,
exec_profile = 1 << 7,
profile_externals = 1 << 8,
warn = 1 << 9,
// the upper 8 bits are reserved for devinfo levels
debuginfo = 1 << 24,
//
Expand Down Expand Up @@ -246,6 +261,7 @@ get_verbose_to_log_level_map() {
{verbose_t::exec_profile, log_manager_t::info},
{verbose_t::exec_check, log_manager_t::error},
{verbose_t::error, log_manager_t::critical},
{verbose_t::warn, log_manager_t::warn},
{verbose_t::none, log_manager_t::off},
};
return verbose_to_log_map;
Expand Down
3 changes: 2 additions & 1 deletion src/common/verbose_msg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

// log type strings
#define VERBOSE_error "error"
#define VERBOSE_warn "warning"
#define VERBOSE_create "create"
#define VERBOSE_create_nested "create_nested"
#define VERBOSE_exec "exec"
Expand Down Expand Up @@ -119,7 +120,7 @@
#define VERBOSE_IMPL_HEURISTIC_FAIL "heuristic fail: %s"
#define VERBOSE_1x1CONV_HEURISTIC_FAIL "heuristic fail for 1x1 convolution: %s"
#define VERBOSE_SCRATCHPAD_LIMIT "scratchpad memory limit exceeded"
#define VERBOSE_PRIMITIVE_CREATION_FAIL "failed to create nested primitive %s"
#define VERBOSE_PRIMITIVE_CREATION_FAIL "failed to create nested %s primitive"
#define VERBOSE_DESC_CREATION_FAIL "failed to create %s descriptor"
#define VERBOSE_SHAPE_RESTRICTION "failed shape restrictions"
#define VERBOSE_INCOMPATIBLE_GEMM_FMT "incompatible gemm format"
Expand Down
4 changes: 2 additions & 2 deletions src/cpu/jit_utils/jit_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2019-2023 Intel Corporation
* Copyright 2019-2024 Intel Corporation
* Copyright 2021 FUJITSU LIMITED
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -97,7 +97,7 @@ void register_jit_code_vtune(const void *code, size_t code_size,
}
#else
if (flags & DNNL_JIT_PROFILE_VTUNE)
VERROR(primitive, jit_profiling,
VWARN(primitive, jit_profiling,
"VTune Profiler integration is not supported");
#endif
#else
Expand Down
4 changes: 2 additions & 2 deletions src/cpu/jit_utils/linux_perf/linux_perf.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2019-2023 Intel Corporation
* Copyright 2019-2024 Intel Corporation
* Copyright 2021 FUJITSU LIMITED
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -195,7 +195,7 @@ class linux_perf_jitdump_t {
}
#else
if (use_tsc) {
VERROR(primitive, linux_perf,
VWARN(primitive, linux_perf,
"TSC timestamps is not supported. clock_gettime() is used "
"instead.");
}
Expand Down

0 comments on commit 81277c9

Please sign in to comment.