Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added active log level definitions for kompute #280

Merged
merged 2 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ option(KOMPUTE_OPT_BUILD_SINGLE_HEADER "Enable if you want to build the single h
option(KOMPUTE_OPT_INSTALL "Enable if you want to enable installation" 0)
# Build options
option(KOMPUTE_OPT_BUILD_PYTHON "Enable if you want to build python bindings" 0)
option(KOMPUTE_OPT_ENABLE_SPDLOG "Extra compile flags for Kompute, see docs for full list" 0)
option(KOMPUTE_OPT_ENABLE_SPDLOG "Enable to compile with spdlog as the internal logging framework" 0)
option(KOMPUTE_OPT_REPO_SUBMODULE_BUILD "Use the submodule repos instead of external package manager" 0)
option(KOMPUTE_OPT_ANDROID_BUILD "Enable android compilation flags required" 0)
option(KOMPUTE_OPT_DISABLE_VK_DEBUG_LAYERS "Explicitly disable debug layers even on debug" 0)
Expand Down
22 changes: 17 additions & 5 deletions docs/overview/build-system.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,32 @@ This by default configures without any of the extra build tasks (such as buildin
- This is the path for your package manager if you use it such as vcpkg
* - -DKOMPUTE_OPT_BUILD_TESTS=1
- Enable if you wish to build and run the tests (must have deps installed.
* - -DKOMPUTE_OPT_CODE_COVERAGE=1
- Enable if you wish to build and run code coverage (must have deps installed which are limited to Windows platform)
* - -DKOMPUTE_OPT_BUILD_DOCS=1
- Enable if you wish to build the docs (must have docs deps installed)
* - -DKOMPUTE_OPT_BUILD_SHADERS=1
- Enable if you wish to build the shaders into header files (must have docs deps installed)
* - -DKOMPUTE_OPT_BUILD_SINGLE_HEADER=1
- Option to build the single header file using "quom" utility
* - -DKOMPUTE_EXTRA_CXX_FLAGS="..."
- Allows you to pass extra config flags to compiler
* - -DKOMPUTE_OPT_INSTALL=0
- Disables the install step in the cmake file (useful for android build)
* - -DKOMPUTE_OPT_BUILD_PYTHON=1
- Enable to build python bindings (used internally for python package)
* - -DKOMPUTE_OPT_ENABLE_SPDLOG=1
- Enable to compile with spdlog as the internal logging framework
* - -DKOMPUTE_OPT_REPO_SUBMODULE_BUILD=1
- Use the submodule repos instead of external packages / manager
* - -DKOMPUTE_OPT_ANDROID_BUILD=1
- Enables android build which includes and excludes relevant libraries
* - -DKOMPUTE_OPT_DISABLE_VK_DEBUG_LAYERS=1
- Explicitly disables debug layers even when on debug mode
* - -DKOMPUTE_OPT_DEPENDENCIES_SHARED_LIBS=1
- Ensures dependencies are referenced as shared libraries for kompute install
* - -DKOMPUTE_OPT_BUILD_AS_SHARED_LIB=1
- Whether to build Kompute as shared lib instead of static
* - -DKOMPUTE_EXTRA_CXX_FLAGS="..."
- Allows you to pass extra config flags to compiler


Compile Flags
Expand All @@ -57,10 +69,10 @@ Compile Flags
- Minor version to use for the Vulkan SDK
* - -DKOMPUTE_ENABLE_SPDLOG=1
- Enables the build with SPDLOG and FMT dependencies (must be installed)
* - -DKOMPUTE_LOG_VERRIDE=1
* - -DKOMPUTE_LOG_OVERRIDE=1
- Does not define the SPDLOG_\ :raw-html-m2r:`<LEVEL>` macros if these are to be overridden
* - -DSPDLOG_ACTIVE_LEVEL
- The level for the log level on compile level (whether spdlog is enabled)
* - -DKOMPUTE_LOG_LEVEL
- The level for the log level on compile level (also sets spdlog level if enabled)
* - -DVVK_USE_PLATFORM_ANDROID_KHR
- Flag to enable android imports in kompute (enabled with -DKOMPUTE_OPT_ANDROID_BUILD)
* - -DRELEASE=1
Expand Down
39 changes: 27 additions & 12 deletions single_include/kompute/Kompute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,13 +620,28 @@ typedef std::vector<float> Constants;
KOMPUTE_VK_API_MAJOR_VERSION, KOMPUTE_VK_API_MINOR_VERSION, 0)
#endif // KOMPUTE_VK_API_VERSION

// SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import
#ifndef SPDLOG_ACTIVE_LEVEL
// Defining kompute log levels analogous to spdlog log levels
#define KOMPUTE_LOG_LEVEL_TRACE 0
#define KOMPUTE_LOG_LEVEL_DEBUG 1
#define KOMPUTE_LOG_LEVEL_INFO 2
#define KOMPUTE_LOG_LEVEL_WARN 3
#define KOMPUTE_LOG_LEVEL_ERROR 4
#define KOMPUTE_LOG_LEVEL_CRITICAL 5
#define KOMPUTE_LOG_LEVEL_OFF 6

#ifndef KOMPUTE_LOG_LEVEL
#if DEBUG
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
#define KOMPUTE_LOG_LEVEL KOMPUTE_LOG_LEVEL_DEBUG
#else
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
#define KOMPUTE_LOG_LEVEL KOMPUTE_LOG_LEVEL_INFO
#endif
#endif // KOMPUTE_LOG_LEVEL

// SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import
// It is recommended that it's set via KOMPUTE_LOG_LEVEL
// but if required it can be set directly as override
#ifndef SPDLOG_ACTIVE_LEVEL
#define SPDLOG_ACTIVE_LEVEL KOMPUTE_LOG_LEVEL
#endif

#if defined(KOMPUTE_BUILD_PYTHON)
Expand All @@ -645,7 +660,7 @@ extern py::object kp_debug, kp_info, kp_warning, kp_error;
#define KP_LOG_ERROR(...) SPDLOG_ERROR(__VA_ARGS__)
#else
#include <iostream>
#if SPDLOG_ACTIVE_LEVEL > 1
#if KOMPUTE_LOG_LEVEL > 1
#define KP_LOG_DEBUG(...)
#else
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
Expand All @@ -663,9 +678,9 @@ extern py::object kp_debug, kp_info, kp_warning, kp_error;
__LINE__, \
fmt::format(__VA_ARGS__))
#endif // VK_USE_PLATFORM_ANDROID_KHR
#endif // SPDLOG_ACTIVE_LEVEL > 1
#endif // KOMPUTE_LOG_LEVEL > 1

#if SPDLOG_ACTIVE_LEVEL > 2
#if KOMPUTE_LOG_LEVEL > 2
#define KP_LOG_INFO(...)
#else
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
Expand All @@ -683,9 +698,9 @@ extern py::object kp_debug, kp_info, kp_warning, kp_error;
__LINE__, \
fmt::format(__VA_ARGS__))
#endif // VK_USE_PLATFORM_ANDROID_KHR
#endif // SPDLOG_ACTIVE_LEVEL > 2
#endif // KOMPUTE_LOG_LEVEL > 2

#if SPDLOG_ACTIVE_LEVEL > 3
#if KOMPUTE_LOG_LEVEL > 3
#define KP_LOG_WARN(...)
#else
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
Expand All @@ -703,9 +718,9 @@ extern py::object kp_debug, kp_info, kp_warning, kp_error;
__LINE__, \
fmt::format(__VA_ARGS__))
#endif // VK_USE_PLATFORM_ANDROID_KHR
#endif // SPDLOG_ACTIVE_LEVEL > 3
#endif // KOMPUTE_LOG_LEVEL > 3

#if SPDLOG_ACTIVE_LEVEL > 4
#if KOMPUTE_LOG_LEVEL > 4
#define KP_LOG_ERROR(...)
#else
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
Expand All @@ -723,7 +738,7 @@ extern py::object kp_debug, kp_info, kp_warning, kp_error;
__LINE__, \
fmt::format(__VA_ARGS__))
#endif // VK_USE_PLATFORM_ANDROID_KHR
#endif // SPDLOG_ACTIVE_LEVEL > 4
#endif // KOMPUTE_LOG_LEVEL > 4
#endif // KOMPUTE_SPDLOG_ENABLED
#endif // KOMPUTE_LOG_OVERRIDE

Expand Down
39 changes: 27 additions & 12 deletions src/include/kompute/Core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,28 @@ typedef std::vector<float> Constants;
KOMPUTE_VK_API_MAJOR_VERSION, KOMPUTE_VK_API_MINOR_VERSION, 0)
#endif // KOMPUTE_VK_API_VERSION

// SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import
#ifndef SPDLOG_ACTIVE_LEVEL
// Defining kompute log levels analogous to spdlog log levels
#define KOMPUTE_LOG_LEVEL_TRACE 0
#define KOMPUTE_LOG_LEVEL_DEBUG 1
#define KOMPUTE_LOG_LEVEL_INFO 2
#define KOMPUTE_LOG_LEVEL_WARN 3
#define KOMPUTE_LOG_LEVEL_ERROR 4
#define KOMPUTE_LOG_LEVEL_CRITICAL 5
#define KOMPUTE_LOG_LEVEL_OFF 6

#ifndef KOMPUTE_LOG_LEVEL
#if DEBUG
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
#define KOMPUTE_LOG_LEVEL KOMPUTE_LOG_LEVEL_DEBUG
#else
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
#define KOMPUTE_LOG_LEVEL KOMPUTE_LOG_LEVEL_INFO
#endif
#endif // KOMPUTE_LOG_LEVEL

// SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import
// It is recommended that it's set via KOMPUTE_LOG_LEVEL
// but if required it can be set directly as override
#ifndef SPDLOG_ACTIVE_LEVEL
#define SPDLOG_ACTIVE_LEVEL KOMPUTE_LOG_LEVEL
#endif

#if defined(KOMPUTE_BUILD_PYTHON)
Expand All @@ -57,7 +72,7 @@ extern py::object kp_debug, kp_info, kp_warning, kp_error;
#define KP_LOG_ERROR(...) SPDLOG_ERROR(__VA_ARGS__)
#else
#include <iostream>
#if SPDLOG_ACTIVE_LEVEL > 1
#if KOMPUTE_LOG_LEVEL > 1
#define KP_LOG_DEBUG(...)
#else
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
Expand All @@ -75,9 +90,9 @@ extern py::object kp_debug, kp_info, kp_warning, kp_error;
__LINE__, \
fmt::format(__VA_ARGS__))
#endif // VK_USE_PLATFORM_ANDROID_KHR
#endif // SPDLOG_ACTIVE_LEVEL > 1
#endif // KOMPUTE_LOG_LEVEL > 1

#if SPDLOG_ACTIVE_LEVEL > 2
#if KOMPUTE_LOG_LEVEL > 2
#define KP_LOG_INFO(...)
#else
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
Expand All @@ -95,9 +110,9 @@ extern py::object kp_debug, kp_info, kp_warning, kp_error;
__LINE__, \
fmt::format(__VA_ARGS__))
#endif // VK_USE_PLATFORM_ANDROID_KHR
#endif // SPDLOG_ACTIVE_LEVEL > 2
#endif // KOMPUTE_LOG_LEVEL > 2

#if SPDLOG_ACTIVE_LEVEL > 3
#if KOMPUTE_LOG_LEVEL > 3
#define KP_LOG_WARN(...)
#else
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
Expand All @@ -115,9 +130,9 @@ extern py::object kp_debug, kp_info, kp_warning, kp_error;
__LINE__, \
fmt::format(__VA_ARGS__))
#endif // VK_USE_PLATFORM_ANDROID_KHR
#endif // SPDLOG_ACTIVE_LEVEL > 3
#endif // KOMPUTE_LOG_LEVEL > 3

#if SPDLOG_ACTIVE_LEVEL > 4
#if KOMPUTE_LOG_LEVEL > 4
#define KP_LOG_ERROR(...)
#else
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
Expand All @@ -135,6 +150,6 @@ extern py::object kp_debug, kp_info, kp_warning, kp_error;
__LINE__, \
fmt::format(__VA_ARGS__))
#endif // VK_USE_PLATFORM_ANDROID_KHR
#endif // SPDLOG_ACTIVE_LEVEL > 4
#endif // KOMPUTE_LOG_LEVEL > 4
#endif // KOMPUTE_SPDLOG_ENABLED
#endif // KOMPUTE_LOG_OVERRIDE
2 changes: 1 addition & 1 deletion test/TestMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ main(int argc, char* argv[])

#if KOMPUTE_ENABLE_SPDLOG
spdlog::set_level(
static_cast<spdlog::level::level_enum>(SPDLOG_ACTIVE_LEVEL));
static_cast<spdlog::level::level_enum>(KOMPUTE_LOG_LEVEL));
#endif

return RUN_ALL_TESTS();
Expand Down