Skip to content

Commit

Permalink
Fixed building Python package
Browse files Browse the repository at this point in the history
Signed-off-by: Fabian Sauter <[email protected]>
  • Loading branch information
COM8 committed Jul 27, 2022
1 parent 00cc533 commit 4b7e3b1
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 22 deletions.
7 changes: 3 additions & 4 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 4 additions & 1 deletion python/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include <memory>

#include <kompute/Kompute.hpp>

#include "docstrings.hpp"
Expand Down Expand Up @@ -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");
Expand Down
28 changes: 17 additions & 11 deletions python/src/utils.hpp
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def build_extension(self, 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'),
Expand Down
2 changes: 1 addition & 1 deletion src/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/include/kompute/Kompute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
10 changes: 5 additions & 5 deletions src/include/kompute/logger/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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( \
Expand All @@ -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( \
Expand All @@ -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( \
Expand All @@ -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( \
Expand All @@ -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( \
Expand Down
3 changes: 3 additions & 0 deletions src/logger/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4b7e3b1

Please sign in to comment.