Fixed building Python package

Signed-off-by: Fabian Sauter <sauter.fabian@mailbox.org>
This commit is contained in:
Fabian Sauter
2022-07-26 12:36:46 +02:00
parent 00cc533f80
commit 4b7e3b13f8
8 changed files with 35 additions and 22 deletions

View File

@@ -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)

View File

@@ -2,6 +2,8 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <memory>
#include <kompute/Kompute.hpp>
#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");

View File

@@ -1,24 +1,30 @@
#include <kompute/Kompute.hpp>
#include <pybind11/pybind11.h>
#include <vulkan/vulkan.hpp>
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;
}

View File

@@ -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'),

View File

@@ -320,7 +320,7 @@ Manager::createDevice(const std::vector<uint32_t>& familyQueueIndices,
this->mPhysicalDevice =
std::make_shared<vk::PhysicalDevice>(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

View File

@@ -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"

View File

@@ -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( \

View File

@@ -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)