From 4b7e3b13f80b42a87925125a0e77682487d47edc Mon Sep 17 00:00:00 2001 From: Fabian Sauter Date: Tue, 26 Jul 2022 12:36:46 +0200 Subject: [PATCH] Fixed building Python package Signed-off-by: Fabian Sauter --- python/CMakeLists.txt | 7 +++---- python/src/main.cpp | 5 ++++- python/src/utils.hpp | 28 ++++++++++++++++----------- setup.py | 1 + src/Manager.cpp | 2 +- src/include/kompute/Kompute.hpp | 1 + src/include/kompute/logger/Logger.hpp | 10 +++++----- src/logger/CMakeLists.txt | 3 +++ 8 files changed, 35 insertions(+), 22 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index cad7f4ffa..1b4598fb7 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -2,9 +2,8 @@ pybind11_add_module(kp src/main.cpp) include_directories( - ${PROJECT_SOURCE_DIR}/single_include/) + ${PROJECT_SOURCE_DIR}/include/) target_link_libraries( - kp PRIVATE - kompute::kompute) - + kp PRIVATE + kompute::kompute) diff --git a/python/src/main.cpp b/python/src/main.cpp index 850a15a56..6c0f640c6 100644 --- a/python/src/main.cpp +++ b/python/src/main.cpp @@ -2,6 +2,8 @@ #include #include +#include + #include #include "docstrings.hpp" @@ -53,7 +55,8 @@ PYBIND11_MODULE(kp, m) // The logging modules are used in the Kompute.hpp file py::module_ logging = py::module_::import("logging"); py::object kp_logger = logging.attr("getLogger")("kp"); - kp_trace = kp_logger.attr("trace"); + kp_trace = kp_logger.attr( + "debug"); // Same as for debug since python has no trace logging level kp_debug = kp_logger.attr("debug"); kp_info = kp_logger.attr("info"); kp_warning = kp_logger.attr("warning"); diff --git a/python/src/utils.hpp b/python/src/utils.hpp index 367871344..3c9e45c86 100644 --- a/python/src/utils.hpp +++ b/python/src/utils.hpp @@ -1,24 +1,30 @@ #include #include +#include using namespace pybind11::literals; // for the `_a` literal namespace kp { namespace py { -static pybind11::dict vkPropertiesToDict(const vk::PhysicalDeviceProperties& properties) { +static pybind11::dict +vkPropertiesToDict(const vk::PhysicalDeviceProperties& properties) +{ pybind11::dict pyDict( - "device_name"_a = std::string(properties.deviceName.data()), - "max_work_group_count"_a = pybind11::make_tuple(properties.limits.maxComputeWorkGroupCount[0], - properties.limits.maxComputeWorkGroupCount[1], - properties.limits.maxComputeWorkGroupCount[2]), - "max_work_group_invocations"_a = properties.limits.maxComputeWorkGroupInvocations, - "max_work_group_size"_a = pybind11::make_tuple(properties.limits.maxComputeWorkGroupSize[0], - properties.limits.maxComputeWorkGroupSize[1], - properties.limits.maxComputeWorkGroupSize[2]), - "timestamps_supported"_a = (bool)properties.limits.timestampComputeAndGraphics - ); + "device_name"_a = std::string(properties.deviceName.data()), + "max_work_group_count"_a = + pybind11::make_tuple(properties.limits.maxComputeWorkGroupCount[0], + properties.limits.maxComputeWorkGroupCount[1], + properties.limits.maxComputeWorkGroupCount[2]), + "max_work_group_invocations"_a = + properties.limits.maxComputeWorkGroupInvocations, + "max_work_group_size"_a = + pybind11::make_tuple(properties.limits.maxComputeWorkGroupSize[0], + properties.limits.maxComputeWorkGroupSize[1], + properties.limits.maxComputeWorkGroupSize[2]), + "timestamps_supported"_a = + (bool)properties.limits.timestampComputeAndGraphics); return pyDict; } diff --git a/setup.py b/setup.py index 0b39e9080..b94748007 100644 --- a/setup.py +++ b/setup.py @@ -43,6 +43,7 @@ class CMakeBuild(build_ext): cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, '-DKOMPUTE_OPT_BUILD_PYTHON=ON', '-DKOMPUTE_OPT_LOG_LEVEL=Off', + '-DKOMPUTE_OPT_USE_SPDLOG=Off', '-DKOMPUTE_OPT_DISABLE_VULKAN_VERSION_CHECK=ON' '-DPYTHON_EXECUTABLE=' + sys.executable, '-DPYTHON_INCLUDE_DIR=' + sysconfig.get_path('include'), diff --git a/src/Manager.cpp b/src/Manager.cpp index 5e9ee9d31..211cd7967 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -320,7 +320,7 @@ Manager::createDevice(const std::vector& familyQueueIndices, this->mPhysicalDevice = std::make_shared(physicalDevice); -#if KOMPUTE_OPT_LOG_LEVEL <= KOMPUTE_LOG_LEVEL_INFO +#if KOMPUTE_OPT_ACTIVE_LOG_LEVEL <= KOMPUTE_LOG_LEVEL_INFO vk::PhysicalDeviceProperties physicalDeviceProperties = physicalDevice.getProperties(); #endif diff --git a/src/include/kompute/Kompute.hpp b/src/include/kompute/Kompute.hpp index 2413dd139..e54adc1b7 100644 --- a/src/include/kompute/Kompute.hpp +++ b/src/include/kompute/Kompute.hpp @@ -14,5 +14,6 @@ #include "operations/OpTensorSyncDevice.hpp" #include "operations/OpTensorSyncLocal.hpp" +// Will be build by CMake and placed inside the build directory #include "ShaderLogisticRegression.hpp" #include "ShaderOpMult.hpp" diff --git a/src/include/kompute/logger/Logger.hpp b/src/include/kompute/logger/Logger.hpp index 79b88a1bd..977c6350e 100644 --- a/src/include/kompute/logger/Logger.hpp +++ b/src/include/kompute/logger/Logger.hpp @@ -51,7 +51,7 @@ setupLogger(); #if !KOMPUTE_OPT_USE_SPDLOG #ifndef KP_LOG_TRACE -#if KOMPUTE_OPT_LOG_LEVEL <= KOMPUTE_LOG_LEVEL_TRACE +#if KOMPUTE_OPT_ACTIVE_LOG_LEVEL <= KOMPUTE_LOG_LEVEL_TRACE #if VK_USE_PLATFORM_ANDROID_KHR #define KP_LOG_TRACE(...) \ ((void)__android_log_write( \ @@ -75,7 +75,7 @@ setupLogger(); #endif // !KP_LOG_TRACE #ifndef KP_LOG_DEBUG -#if KOMPUTE_OPT_LOG_LEVEL <= KOMPUTE_LOG_LEVEL_DEBUG +#if KOMPUTE_OPT_ACTIVE_LOG_LEVEL <= KOMPUTE_LOG_LEVEL_DEBUG #if VK_USE_PLATFORM_ANDROID_KHR #define KP_LOG_DEBUG(...) \ ((void)__android_log_write( \ @@ -99,7 +99,7 @@ setupLogger(); #endif // !KP_LOG_DEBUG #ifndef KP_LOG_INFO -#if KOMPUTE_OPT_LOG_LEVEL <= KOMPUTE_LOG_LEVEL_INFO +#if KOMPUTE_OPT_ACTIVE_LOG_LEVEL <= KOMPUTE_LOG_LEVEL_INFO #if VK_USE_PLATFORM_ANDROID_KHR #define KP_LOG_INFO(...) \ ((void)__android_log_write( \ @@ -123,7 +123,7 @@ setupLogger(); #endif // !KP_LOG_INFO #ifndef KP_LOG_WARN -#if KOMPUTE_OPT_LOG_LEVEL <= KOMPUTE_LOG_LEVEL_WARN +#if KOMPUTE_OPT_ACTIVE_LOG_LEVEL <= KOMPUTE_LOG_LEVEL_WARN #if VK_USE_PLATFORM_ANDROID_KHR #define KP_LOG_WARN(...) \ ((void)__android_log_write( \ @@ -147,7 +147,7 @@ setupLogger(); #endif // !KP_LOG_WARN #ifndef KP_LOG_ERROR -#if KOMPUTE_OPT_LOG_LEVEL <= KOMPUTE_LOG_LEVEL_ERROR +#if KOMPUTE_OPT_ACTIVE_LOG_LEVEL <= KOMPUTE_LOG_LEVEL_ERROR #if VK_USE_PLATFORM_ANDROID_KHR #define KP_LOG_ERROR(...) \ ((void)__android_log_write( \ diff --git a/src/logger/CMakeLists.txt b/src/logger/CMakeLists.txt index b4d2fea49..8e63aba05 100644 --- a/src/logger/CMakeLists.txt +++ b/src/logger/CMakeLists.txt @@ -49,6 +49,9 @@ else() message(FATAL_ERROR "Log level '${KOMPUTE_OPT_LOG_LEVEL}' unknown, use -DKOMPUTE_OPT_LOG_LEVEL={Trace, Debug, Info, Warn, Error, Critical, Off, Default} to set it to a correct value.") endif() +# Always make sure we define the Kompute log level independent of the Spdlog log level +target_compile_definitions(kp_logger INTERFACE KOMPUTE_OPT_ACTIVE_LOG_LEVEL=KOMPUTE_LOG_LEVEL_${KOMPUTE_OPT_LOG_LEVEL}) + # Link depending on how the logger should be setup if(NOT KOMPUTE_OPT_LOG_LEVEL_DISABLED) if(KOMPUTE_OPT_USE_SPDLOG)