Skip to content

Commit 27edc37

Browse files
refactor: make spdlog optional
Signed-off-by: Artur Harasimiuk <artur.harasimiuk@intel.com> Source: b8e212d
1 parent 311b960 commit 27edc37

Some content is hidden

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

57 files changed

+93
-14992
lines changed

level_zero/CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,11 @@ if(BUILD_WITH_L0)
194194
endif()
195195

196196
include_directories(${COMPUTE_RUNTIME_DIR}/third_party/opencl_headers)
197-
if(UNIX)
198-
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/experimental/source/log_utility/linux/linux_logging.cpp PROPERTIES INCLUDE_DIRECTORIES ${COMPUTE_RUNTIME_DIR}/third_party/spdlog_headers)
197+
if(UNIX AND DEFINED NEO_SPDLOG_DIR)
198+
set_source_files_properties(
199+
${CMAKE_CURRENT_SOURCE_DIR}/experimental/source/log_utility/linux/linux_logging.cpp
200+
PROPERTIES INCLUDE_DIRECTORIES ${NEO_SPDLOG_DIR}
201+
)
199202
endif()
200203

201204
if(CUSTOM_L0_INCLUDE_PATH)
@@ -360,6 +363,12 @@ if(BUILD_WITH_L0)
360363
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/source "${NEO_BUILD_DIR}/${LIB_NAME}tools/source")
361364
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/sysman/source "${NEO_BUILD_DIR}/${LIB_NAME}sysman/source")
362365

366+
if(DEFINED NEO_SPDLOG_DIR)
367+
target_include_directories(${LIB_NAME} PRIVATE "experimental/source/log_utility")
368+
else()
369+
target_include_directories(${LIB_NAME} PRIVATE "experimental/source/log_utility_stub")
370+
endif()
371+
363372
if(${MOCKABLE})
364373
get_property(COMPUTE_RUNTIME_DEFINITIONS
365374
TARGET ${NEO_SHARED_MOCKABLE_LIB_NAME}

level_zero/core/source/cmdlist/cmdlist_imp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
#include "level_zero/core/source/device/device_imp.h"
2727
#include "level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h"
2828
#include "level_zero/core/source/helpers/properties_parser.h"
29-
#include "level_zero/experimental/source/log_utility/log_manager.h"
3029
#include "level_zero/tools/source/metrics/metric.h"
3130

3231
#include "igfxfmid.h"
32+
#include "log_manager.h"
3333

3434
#include <algorithm>
3535

level_zero/core/source/driver/driver.cpp

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,14 @@
1717
#include "level_zero/core/source/device/device.h"
1818
#include "level_zero/core/source/driver/driver_handle_imp.h"
1919
#include "level_zero/core/source/driver/driver_imp.h"
20-
#include "level_zero/experimental/source/log_utility/log_manager.h"
2120
#include "level_zero/tools/source/metrics/metric.h"
2221

2322
#include "driver_version.h"
23+
#include "log_manager.h"
2424

2525
#include <memory>
2626
#include <thread>
2727

28-
#define QTR(a) #a
29-
#define TOSTR(b) QTR(b)
30-
#define LOG_INFO_VERSION_SHA(logType, version, sha) \
31-
auto logger = NEO::LogManager::getInstance()->getLogger(logType); \
32-
if (logger) { \
33-
char logBuffer[256]; \
34-
snprintf(logBuffer, 256, "Level zero driver version and SHA : %s - %s\n", version, sha); \
35-
logger->logInfo(logBuffer); \
36-
}
37-
3828
namespace L0 {
3929

4030
_ze_driver_handle_t *globalDriverHandle;
@@ -72,7 +62,7 @@ void DriverImp::initialize(ze_result_t *result) {
7262
}
7363

7464
// Logging enablement if opted
75-
initLogger();
65+
NEO::initLogger();
7666

7767
if (envVariables.fp64Emulation) {
7868
executionEnvironment->setFP64EmulationEnabled();
@@ -111,13 +101,6 @@ void DriverImp::initialize(ze_result_t *result) {
111101

112102
ze_result_t DriverImp::initStatus(ZE_RESULT_ERROR_UNINITIALIZED);
113103

114-
void DriverImp::initLogger() {
115-
if (NEO::LogManager::getLoggingLevel() != (uint32_t)NEO::LogLevel::logLevelOff) {
116-
CREATE_LOGGER(NEO::LogManager::LogType::coreLogger, "coreLogger.log", NEO::LogManager::getLoggingLevel());
117-
LOG_INFO_VERSION_SHA(NEO::LogManager::LogType::coreLogger, TOSTR(NEO_OCL_DRIVER_VERSION), NEO_REVISION);
118-
}
119-
}
120-
121104
ze_result_t DriverImp::driverInit(ze_init_flags_t flags) {
122105
std::call_once(initDriverOnce, [this]() {
123106
ze_result_t result;

level_zero/core/source/driver/driver_imp.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class DriverImp : public Driver {
2121
void initialize(ze_result_t *result) override;
2222

2323
protected:
24-
void initLogger();
2524
std::once_flag initDriverOnce;
2625
static ze_result_t initStatus;
2726
};

level_zero/core/test/unit_tests/sources/log_utility/linux/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# SPDX-License-Identifier: MIT
55
#
66

7-
if(UNIX)
7+
if(UNIX AND DEFINED NEO_SPDLOG_DIR)
88
target_sources(
99
${TARGET_NAME}
1010
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt

level_zero/experimental/source/log_utility/CMakeLists.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
# SPDX-License-Identifier: MIT
55
#
66

7-
target_sources(${L0_STATIC_LIB_NAME}
8-
PRIVATE
9-
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
10-
${CMAKE_CURRENT_SOURCE_DIR}/log_manager.h
11-
${CMAKE_CURRENT_SOURCE_DIR}/logging.h
12-
)
13-
add_subdirectories()
7+
if(DEFINED NEO_SPDLOG_DIR)
8+
target_sources(${L0_STATIC_LIB_NAME}
9+
PRIVATE
10+
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
11+
${CMAKE_CURRENT_SOURCE_DIR}/log_manager.h
12+
${CMAKE_CURRENT_SOURCE_DIR}/logging.h
13+
)
14+
add_subdirectories()
15+
endif()

level_zero/experimental/source/log_utility/linux/linux_log_manager.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,31 @@
99

1010
#include "shared/source/debug_settings/debug_settings_manager.h"
1111

12+
#include "driver_version.h"
13+
1214
#include <map>
1315

16+
#define QTR(a) #a
17+
#define TOSTR(b) QTR(b)
18+
#define LOG_INFO_VERSION_SHA(logType, version, sha) \
19+
auto logger = NEO::LogManager::getInstance()->getLogger(logType); \
20+
if (logger) { \
21+
char logBuffer[256]; \
22+
snprintf(logBuffer, 256, "Level zero driver version and SHA : %s - %s\n", version, sha); \
23+
logger->logInfo(logBuffer); \
24+
}
25+
1426
namespace NEO {
1527
std::unique_ptr<LogManager> LogManager::instancePtr = nullptr;
1628
uint32_t LogManager::logLevel = UINT32_MAX;
1729

30+
void initLogger() {
31+
if (NEO::LogManager::getLoggingLevel() != (uint32_t)NEO::LogLevel::logLevelOff) {
32+
CREATE_LOGGER(NEO::LogManager::LogType::coreLogger, "coreLogger.log", NEO::LogManager::getLoggingLevel());
33+
LOG_INFO_VERSION_SHA(NEO::LogManager::LogType::coreLogger, TOSTR(NEO_OCL_DRIVER_VERSION), NEO_REVISION);
34+
}
35+
}
36+
1837
LogManager *LogManager::getInstance() {
1938
if (instancePtr == nullptr) {
2039
LogManager::instancePtr = std::make_unique<LinuxLogManager>();

level_zero/experimental/source/log_utility/log_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,5 @@ class LogManager {
6868
} \
6969
}
7070

71+
extern void initLogger();
7172
} // namespace NEO

level_zero/experimental/source/log_utility/windows/windows_log_manager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ uint32_t LogManager::getLoggingLevel() {
3737
void WinLogManager::destroyLogger(LogManager::LogType logType) {
3838
}
3939

40+
void initLogger(){};
41+
4042
} // namespace NEO
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# Copyright (C) 2024 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#
6+
7+
if(NOT DEFINED NEO_SPDLOG_DIR)
8+
target_sources(${L0_STATIC_LIB_NAME}
9+
PRIVATE
10+
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
11+
${CMAKE_CURRENT_SOURCE_DIR}/log_manager.h
12+
${CMAKE_CURRENT_SOURCE_DIR}/log_manager_stub.cpp
13+
)
14+
endif()

0 commit comments

Comments
 (0)