diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a6dd6edf..48153e102 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,7 @@ endmacro() macro(kompute_log_level OPTION_NAME OPTION_TEXT OPTION_DEFAULT) set(${OPTION_NAME} ${OPTION_DEFAULT} CACHE STRING ${OPTION_TEXT}) - set_property(CACHE ${OPTION_NAME} PROPERTY STRINGS "Trace" "Debug" "Info" "Warn" "Error" "Critical") + set_property(CACHE ${OPTION_NAME} PROPERTY STRINGS "Trace" "Debug" "Info" "Warn" "Error" "Critical" "Default" "Off") if(DEFINED ENV{${OPTION_NAME}}) # Allow setting the option through an environment variable @@ -53,6 +53,12 @@ macro(kompute_log_level OPTION_NAME OPTION_TEXT OPTION_DEFAULT) add_definitions(-D${OPTION_NAME}) endif() + # Allow disabling logging completely and prevent linking against it: + if(${KOMPUTE_OPT_LOG_LEVEL} STREQUAL "Off") + set(${OPTION_NAME}_DISABLED ON) + add_compile_definitions(${OPTION_NAME}_DISABLED=1) + endif() + message(STATUS " ${OPTION_NAME}: ${${OPTION_NAME}}") endmacro() @@ -132,15 +138,17 @@ else() endif() # Spdlog -if(KOMPUTE_OPT_USE_BUILD_IN_SPDLOG) - set(SPDLOG_INSTALL ${KOMPUTE_OPT_INSTALL}) - set(SPDLOG_BUILD_SHARED ${KOMPUTE_OPT_DEPENDENCIES_SHARED_LIBS}) +if(NOT KOMPUTE_OPT_LOG_LEVEL_DISABLED) + if(KOMPUTE_OPT_USE_BUILD_IN_SPDLOG) + set(SPDLOG_INSTALL ${KOMPUTE_OPT_INSTALL}) + set(SPDLOG_BUILD_SHARED ${KOMPUTE_OPT_DEPENDENCIES_SHARED_LIBS}) - FetchContent_Declare(spdlog GIT_REPOSITORY https://github.com/gabime/spdlog.git - GIT_TAG v1.10.0) # Source: https://github.com/gabime/spdlog/releases - FetchContent_MakeAvailable(spdlog) -else() - find_package(spdlog REQUIRED) + FetchContent_Declare(spdlog GIT_REPOSITORY https://github.com/gabime/spdlog.git + GIT_TAG v1.10.0) # Source: https://github.com/gabime/spdlog/releases + FetchContent_MakeAvailable(spdlog) + else() + find_package(spdlog REQUIRED) + endif() endif() # fmt diff --git a/src/Manager.cpp b/src/Manager.cpp index fdfc0e969..d50704228 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -40,8 +40,10 @@ Manager::Manager(uint32_t physicalDeviceIndex, { this->mManageResources = true; - // Make sure the logger is setup +// Make sure the logger is setup +#if !KOMPUTE_OPT_LOG_LEVEL_DISABLED logger::setupLogger(); +#endif this->createInstance(); this->createDevice( @@ -58,8 +60,10 @@ Manager::Manager(std::shared_ptr instance, this->mPhysicalDevice = physicalDevice; this->mDevice = device; - // Make sure the logger is setup +// Make sure the logger is setup +#if !KOMPUTE_OPT_LOG_LEVEL_DISABLED logger::setupLogger(); +#endif } Manager::~Manager() diff --git a/src/include/kompute/Algorithm.hpp b/src/include/kompute/Algorithm.hpp index 804a70900..1917dd37a 100644 --- a/src/include/kompute/Algorithm.hpp +++ b/src/include/kompute/Algorithm.hpp @@ -3,6 +3,7 @@ #include "kompute/Core.hpp" +#include "fmt/format.h" #include "kompute/Tensor.hpp" #include "logger/Logger.hpp" diff --git a/src/include/kompute/logger/Logger.hpp b/src/include/kompute/logger/Logger.hpp index 92b2872c5..f24ad3a80 100644 --- a/src/include/kompute/logger/Logger.hpp +++ b/src/include/kompute/logger/Logger.hpp @@ -1,5 +1,13 @@ #pragma once +#if KOMPUTE_OPT_LOG_LEVEL_DISABLED +#define KP_LOG_TRACE(...) +#define KP_LOG_DEBUG(...) +#define KP_LOG_INFO(...) +#define KP_LOG_WARN(...) +#define KP_LOG_ERROR(...) +#else + #include #include #include @@ -34,3 +42,5 @@ vecToString(const std::vector& vec); std::string vecToString(const std::vector& vec); } // namespace logger + +#endif \ No newline at end of file diff --git a/src/logger/CMakeLists.txt b/src/logger/CMakeLists.txt index 0f54ef670..6132c1d21 100644 --- a/src/logger/CMakeLists.txt +++ b/src/logger/CMakeLists.txt @@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.14) set(LOGGER_SOURCES Logger.cpp) add_library(kp_logger ${LOGGER_SOURCES}) -target_link_libraries(kp_logger PUBLIC spdlog::spdlog) + +if(NOT KOMPUTE_OPT_LOG_LEVEL_DISABLED) + target_link_libraries(kp_logger PUBLIC spdlog::spdlog) +endif() if(${KOMPUTE_OPT_LOG_LEVEL} STREQUAL "Trace") set(KOMPUTE_OPT_LOG_LEVEL TRACE) diff --git a/src/logger/Logger.cpp b/src/logger/Logger.cpp index c82a882b6..bb02023a2 100644 --- a/src/logger/Logger.cpp +++ b/src/logger/Logger.cpp @@ -1,9 +1,10 @@ #include "kompute/logger/Logger.hpp" +#if KOMPUTE_OPT_LOG_LEVEL_DISABLED +#else #include #include #include -#include #include #include #include @@ -11,13 +12,14 @@ #include #include #include +#include #include #include #ifdef _WIN32 -#include #include +#include #endif // _WIN32 namespace logger { @@ -56,7 +58,7 @@ createDir(const std::string& path) #if defined(_WIN32) nError = _mkdir(path.c_str()); // can be used on Windows #else - mode_t nMode = 0733; // UNIX style permissions + mode_t nMode = 0733; // UNIX style permissions nError = mkdir(path.c_str(), nMode); // can be used on non-Windows #endif if (nError != 0) { @@ -192,3 +194,4 @@ vecToString(const std::vector& vec) return result.substr(0, result.size() - 2); // Remove the tailing ", " } } // namespace logger +#endif diff --git a/test/TestAsyncOperations.cpp b/test/TestAsyncOperations.cpp index a1c8de852..91a8fab1b 100644 --- a/test/TestAsyncOperations.cpp +++ b/test/TestAsyncOperations.cpp @@ -5,6 +5,7 @@ #include #include "kompute/Kompute.hpp" +#include "kompute/logger/Logger.hpp" #include "shaders/Utils.hpp" TEST(TestAsyncOperations, TestManagerParallelExecution) @@ -264,9 +265,8 @@ main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); -#if KOMPUTE_ENABLE_SPDLOG - spdlog::set_level( - static_cast(KOMPUTE_LOG_LEVEL)); +#if !KOMPUTE_OPT_LOG_LEVEL_DISABLED + logger::setupLogger(); #endif return RUN_ALL_TESTS(); diff --git a/test/TestDestroy.cpp b/test/TestDestroy.cpp index 6a4fdb345..c58557bc7 100644 --- a/test/TestDestroy.cpp +++ b/test/TestDestroy.cpp @@ -3,6 +3,7 @@ #include "gtest/gtest.h" #include "kompute/Kompute.hpp" +#include "kompute/logger/Logger.hpp" #include "shaders/Utils.hpp" @@ -145,9 +146,8 @@ main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); -#if KOMPUTE_ENABLE_SPDLOG - spdlog::set_level( - static_cast(KOMPUTE_LOG_LEVEL)); +#if !KOMPUTE_OPT_LOG_LEVEL_DISABLED + logger::setupLogger(); #endif return RUN_ALL_TESTS(); diff --git a/test/TestLogisticRegression.cpp b/test/TestLogisticRegression.cpp index 2ac52e31c..072463a18 100644 --- a/test/TestLogisticRegression.cpp +++ b/test/TestLogisticRegression.cpp @@ -3,6 +3,7 @@ #include "gtest/gtest.h" #include "kompute/Kompute.hpp" +#include "kompute/logger/Logger.hpp" #include "test_logistic_regression_shader.hpp" @@ -162,9 +163,8 @@ main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); -#if KOMPUTE_ENABLE_SPDLOG - spdlog::set_level( - static_cast(KOMPUTE_LOG_LEVEL)); +#if !KOMPUTE_OPT_LOG_LEVEL_DISABLED + logger::setupLogger(); #endif return RUN_ALL_TESTS(); diff --git a/test/TestManager.cpp b/test/TestManager.cpp index ca787a066..5b78d5c7f 100644 --- a/test/TestManager.cpp +++ b/test/TestManager.cpp @@ -3,6 +3,7 @@ #include "gtest/gtest.h" #include "kompute/Kompute.hpp" +#include "kompute/logger/Logger.hpp" TEST(TestManager, EndToEndOpMultEvalFlow) { @@ -111,9 +112,8 @@ main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); -#if KOMPUTE_ENABLE_SPDLOG - spdlog::set_level( - static_cast(KOMPUTE_LOG_LEVEL)); +#if !KOMPUTE_OPT_LOG_LEVEL_DISABLED + logger::setupLogger(); #endif return RUN_ALL_TESTS(); diff --git a/test/TestMultipleAlgoExecutions.cpp b/test/TestMultipleAlgoExecutions.cpp index 0311fcb21..75547b86c 100644 --- a/test/TestMultipleAlgoExecutions.cpp +++ b/test/TestMultipleAlgoExecutions.cpp @@ -3,6 +3,7 @@ #include "gtest/gtest.h" #include "kompute/Kompute.hpp" +#include "kompute/logger/Logger.hpp" #include "shaders/Utils.hpp" @@ -276,9 +277,8 @@ main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); -#if KOMPUTE_ENABLE_SPDLOG - spdlog::set_level( - static_cast(KOMPUTE_LOG_LEVEL)); +#if !KOMPUTE_OPT_LOG_LEVEL_DISABLED + logger::setupLogger(); #endif return RUN_ALL_TESTS(); diff --git a/test/TestOpShadersFromStringAndFile.cpp b/test/TestOpShadersFromStringAndFile.cpp index ea1a924de..12948d780 100644 --- a/test/TestOpShadersFromStringAndFile.cpp +++ b/test/TestOpShadersFromStringAndFile.cpp @@ -3,6 +3,7 @@ #include "gtest/gtest.h" #include "kompute/Kompute.hpp" +#include "kompute/logger/Logger.hpp" #include "shaders/Utils.hpp" #include "test_op_custom_shader.hpp" @@ -113,9 +114,8 @@ main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); -#if KOMPUTE_ENABLE_SPDLOG - spdlog::set_level( - static_cast(KOMPUTE_LOG_LEVEL)); +#if !KOMPUTE_OPT_LOG_LEVEL_DISABLED + logger::setupLogger(); #endif return RUN_ALL_TESTS(); diff --git a/test/TestOpTensorCopy.cpp b/test/TestOpTensorCopy.cpp index 9cebee34c..2ebb50c2a 100644 --- a/test/TestOpTensorCopy.cpp +++ b/test/TestOpTensorCopy.cpp @@ -3,6 +3,7 @@ #include "gtest/gtest.h" #include "kompute/Kompute.hpp" +#include "kompute/logger/Logger.hpp" #include "shaders/Utils.hpp" @@ -162,9 +163,8 @@ main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); -#if KOMPUTE_ENABLE_SPDLOG - spdlog::set_level( - static_cast(KOMPUTE_LOG_LEVEL)); +#if !KOMPUTE_OPT_LOG_LEVEL_DISABLED + logger::setupLogger(); #endif return RUN_ALL_TESTS(); diff --git a/test/TestOpTensorCreate.cpp b/test/TestOpTensorCreate.cpp index 40133508f..ec725915a 100644 --- a/test/TestOpTensorCreate.cpp +++ b/test/TestOpTensorCreate.cpp @@ -3,6 +3,7 @@ #include "gtest/gtest.h" #include "kompute/Kompute.hpp" +#include "kompute/logger/Logger.hpp" TEST(TestOpTensorCreate, CreateSingleTensorSingleOp) { @@ -63,9 +64,8 @@ main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); -#if KOMPUTE_ENABLE_SPDLOG - spdlog::set_level( - static_cast(KOMPUTE_LOG_LEVEL)); +#if !KOMPUTE_OPT_LOG_LEVEL_DISABLED + logger::setupLogger(); #endif return RUN_ALL_TESTS(); diff --git a/test/TestOpTensorSync.cpp b/test/TestOpTensorSync.cpp index 7c9d6cf06..fa4f76932 100644 --- a/test/TestOpTensorSync.cpp +++ b/test/TestOpTensorSync.cpp @@ -3,6 +3,7 @@ #include "gtest/gtest.h" #include "kompute/Kompute.hpp" +#include "kompute/logger/Logger.hpp" TEST(TestOpTensorSync, SyncToDeviceMemorySingleTensor) { @@ -58,9 +59,8 @@ main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); -#if KOMPUTE_ENABLE_SPDLOG - spdlog::set_level( - static_cast(KOMPUTE_LOG_LEVEL)); +#if !KOMPUTE_OPT_LOG_LEVEL_DISABLED + logger::setupLogger(); #endif return RUN_ALL_TESTS(); diff --git a/test/TestPushConstant.cpp b/test/TestPushConstant.cpp index 777ac95ec..ec03bc08c 100644 --- a/test/TestPushConstant.cpp +++ b/test/TestPushConstant.cpp @@ -3,6 +3,7 @@ #include "gtest/gtest.h" #include "kompute/Kompute.hpp" +#include "kompute/logger/Logger.hpp" #include "shaders/Utils.hpp" @@ -395,9 +396,8 @@ main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); -#if KOMPUTE_ENABLE_SPDLOG - spdlog::set_level( - static_cast(KOMPUTE_LOG_LEVEL)); +#if !KOMPUTE_OPT_LOG_LEVEL_DISABLED + logger::setupLogger(); #endif return RUN_ALL_TESTS(); diff --git a/test/TestSequence.cpp b/test/TestSequence.cpp index 27c422450..5e5e3254c 100644 --- a/test/TestSequence.cpp +++ b/test/TestSequence.cpp @@ -3,6 +3,7 @@ #include "gtest/gtest.h" #include "kompute/Kompute.hpp" +#include "kompute/logger/Logger.hpp" #include "shaders/Utils.hpp" @@ -248,9 +249,8 @@ main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); -#if KOMPUTE_ENABLE_SPDLOG - spdlog::set_level( - static_cast(KOMPUTE_LOG_LEVEL)); +#if !KOMPUTE_OPT_LOG_LEVEL_DISABLED + logger::setupLogger(); #endif return RUN_ALL_TESTS(); diff --git a/test/TestSpecializationConstant.cpp b/test/TestSpecializationConstant.cpp index 1421aaa97..3140ba5b4 100644 --- a/test/TestSpecializationConstant.cpp +++ b/test/TestSpecializationConstant.cpp @@ -3,6 +3,7 @@ #include "gtest/gtest.h" #include "kompute/Kompute.hpp" +#include "kompute/logger/Logger.hpp" #include "shaders/Utils.hpp" @@ -107,9 +108,8 @@ main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); -#if KOMPUTE_ENABLE_SPDLOG - spdlog::set_level( - static_cast(KOMPUTE_LOG_LEVEL)); +#if !KOMPUTE_OPT_LOG_LEVEL_DISABLED + logger::setupLogger(); #endif return RUN_ALL_TESTS(); diff --git a/test/TestTensor.cpp b/test/TestTensor.cpp index dc358fc82..0a53220dd 100644 --- a/test/TestTensor.cpp +++ b/test/TestTensor.cpp @@ -3,6 +3,7 @@ #include "gtest/gtest.h" #include "kompute/Kompute.hpp" +#include "kompute/logger/Logger.hpp" TEST(TestTensor, ConstructorData) { @@ -49,9 +50,8 @@ main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); -#if KOMPUTE_ENABLE_SPDLOG - spdlog::set_level( - static_cast(KOMPUTE_LOG_LEVEL)); +#if !KOMPUTE_OPT_LOG_LEVEL_DISABLED + logger::setupLogger(); #endif return RUN_ALL_TESTS(); diff --git a/test/TestWorkgroup.cpp b/test/TestWorkgroup.cpp index bd87bbab3..a2e41865b 100644 --- a/test/TestWorkgroup.cpp +++ b/test/TestWorkgroup.cpp @@ -3,6 +3,7 @@ #include "gtest/gtest.h" #include "kompute/Kompute.hpp" +#include "kompute/logger/Logger.hpp" #include "test_workgroup_shader.hpp" @@ -68,9 +69,8 @@ main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); -#if KOMPUTE_ENABLE_SPDLOG - spdlog::set_level( - static_cast(KOMPUTE_LOG_LEVEL)); +#if !KOMPUTE_OPT_LOG_LEVEL_DISABLED + logger::setupLogger(); #endif return RUN_ALL_TESTS();