Skip to content

Commit d31d8f8

Browse files
committed
common: verbose: add spdlog headers for logging
1 parent 1addd3a commit d31d8f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+16885
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ and OpenCL Driver](https://github.com/intel/compute-runtime)
432432
* [Doxyrest](https://github.com/vovkos/doxyrest)
433433
* [Intel Metrics Discovery Application Programming
434434
Interface](https://github.com/intel/metrics-discovery)
435+
* [spdlog](https://github.com/gabime/spdlog)
435436

436437
This third party software, even if included with the distribution of
437438
the Intel software, may be governed by separate license terms, including

THIRD-PARTY-PROGRAMS

+29
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,35 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
168168
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
169169
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
170170

171+
------------------------------------------------------------------------------
172+
5. spdlog (src/common/spdlog/)
173+
174+
The MIT License (MIT)
175+
Copyright (c) 2016 Gabi Melman.
176+
177+
Permission is hereby granted, free of charge, to any person obtaining a copy
178+
of this software and associated documentation files (the "Software"), to deal
179+
in the Software without restriction, including without limitation the rights
180+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
181+
copies of the Software, and to permit persons to whom the Software is
182+
furnished to do so, subject to the following conditions:
183+
184+
The above copyright notice and this permission notice shall be included in
185+
all copies or substantial portions of the Software.
186+
187+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
188+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
189+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
190+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
191+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
192+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
193+
THE SOFTWARE.
194+
195+
-- NOTE: Third party dependency used by this software --
196+
This software depends on the fmt lib (MIT License),
197+
and users must comply to its license:
198+
https://raw.githubusercontent.com/fmtlib/fmt/master/LICENSE
199+
171200
------------------------------------------------------------------------------
172201

173202
The following individuals and institutions are among the Contributors:

src/common/CMakeLists.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#===============================================================================
2-
# Copyright 2019-2023 Intel Corporation
2+
# Copyright 2019-2024 Intel Corporation
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -48,6 +48,13 @@ if(NOT DNNL_CPU_RUNTIME STREQUAL "THREADPOOL")
4848
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/stream_threadpool.cpp")
4949
endif()
5050

51+
if(NOT DNNL_EXPERIMENTAL_LOGGING)
52+
# avoid building and linking spdlog if logging support is not enabled
53+
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/spdlog/*")
54+
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/logging.cpp")
55+
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/logging.hpp")
56+
endif()
57+
5158
set(OBJ_LIB ${LIB_PACKAGE_NAME}_common)
5259
add_library(${OBJ_LIB} OBJECT ${SOURCES})
5360
set_property(GLOBAL APPEND PROPERTY DNNL_LIB_DEPS

src/common/spdlog/common-inl.h

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2+
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
3+
4+
#pragma once
5+
6+
#ifndef SPDLOG_HEADER_ONLY
7+
#include <common/spdlog/common.h>
8+
#endif
9+
10+
#include <algorithm>
11+
#include <iterator>
12+
13+
namespace spdlog {
14+
namespace level {
15+
16+
#if __cplusplus >= 201703L
17+
constexpr
18+
#endif
19+
static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES;
20+
21+
static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES;
22+
23+
SPDLOG_INLINE const string_view_t &to_string_view(
24+
spdlog::level::level_enum l) SPDLOG_NOEXCEPT {
25+
return level_string_views[l];
26+
}
27+
28+
SPDLOG_INLINE const char *to_short_c_str(
29+
spdlog::level::level_enum l) SPDLOG_NOEXCEPT {
30+
return short_level_names[l];
31+
}
32+
33+
SPDLOG_INLINE spdlog::level::level_enum from_str(
34+
const std::string &name) SPDLOG_NOEXCEPT {
35+
auto it = std::find(
36+
std::begin(level_string_views), std::end(level_string_views), name);
37+
if (it != std::end(level_string_views))
38+
return static_cast<level::level_enum>(
39+
std::distance(std::begin(level_string_views), it));
40+
41+
// check also for "warn" and "err" before giving up..
42+
if (name == "warn") { return level::warn; }
43+
if (name == "err") { return level::err; }
44+
return level::off;
45+
}
46+
} // namespace level
47+
48+
SPDLOG_INLINE spdlog_ex::spdlog_ex(std::string msg) : msg_(std::move(msg)) {}
49+
50+
SPDLOG_INLINE spdlog_ex::spdlog_ex(const std::string &msg, int last_errno) {
51+
#ifdef SPDLOG_USE_STD_FORMAT
52+
msg_ = std::system_error(
53+
std::error_code(last_errno, std::generic_category()), msg)
54+
.what();
55+
#else
56+
memory_buf_t outbuf;
57+
fmt::format_system_error(outbuf, last_errno, msg.c_str());
58+
msg_ = fmt::to_string(outbuf);
59+
#endif
60+
}
61+
62+
SPDLOG_INLINE const char *spdlog_ex::what() const SPDLOG_NOEXCEPT {
63+
return msg_.c_str();
64+
}
65+
66+
SPDLOG_INLINE void throw_spdlog_ex(const std::string &msg, int last_errno) {
67+
SPDLOG_THROW(spdlog_ex(msg, last_errno));
68+
}
69+
70+
SPDLOG_INLINE void throw_spdlog_ex(std::string msg) {
71+
SPDLOG_THROW(spdlog_ex(std::move(msg)));
72+
}
73+
74+
} // namespace spdlog

0 commit comments

Comments
 (0)