native logging for python
This commit is contained in:
parent
661a50e62d
commit
059221a7de
5 changed files with 98 additions and 51 deletions
|
|
@ -30,6 +30,10 @@ if(KOMPUTE_OPT_ANDOID_BUILD)
|
||||||
set(KOMPUTE_EXTRA_CXX_FLAGS "${KOMPUTE_EXTRA_CXX_FLAGS} -DVK_USE_PLATFORM_ANDROID_KHR")
|
set(KOMPUTE_EXTRA_CXX_FLAGS "${KOMPUTE_EXTRA_CXX_FLAGS} -DVK_USE_PLATFORM_ANDROID_KHR")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(KOMPUTE_OPT_BUILD_PYTHON)
|
||||||
|
set(KOMPUTE_EXTRA_CXX_FLAGS "${KOMPUTE_EXTRA_CXX_FLAGS} -DKOMPUTE_BUILD_PYTHON")
|
||||||
|
endif()
|
||||||
|
|
||||||
if(KOMPUTE_OPT_DISABLE_VK_DEBUG_LAYERS)
|
if(KOMPUTE_OPT_DISABLE_VK_DEBUG_LAYERS)
|
||||||
set(KOMPUTE_EXTRA_CXX_FLAGS "${KOMPUTE_EXTRA_CXX_FLAGS} -DKOMPUTE_DISABLE_VK_DEBUG_LAYERS=1")
|
set(KOMPUTE_EXTRA_CXX_FLAGS "${KOMPUTE_EXTRA_CXX_FLAGS} -DKOMPUTE_DISABLE_VK_DEBUG_LAYERS=1")
|
||||||
endif()
|
endif()
|
||||||
|
|
@ -57,4 +61,3 @@ endif()
|
||||||
if(KOMPUTE_OPT_BUILD_PYTHON)
|
if(KOMPUTE_OPT_BUILD_PYTHON)
|
||||||
add_subdirectory(python)
|
add_subdirectory(python)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,25 @@
|
||||||
#include <pybind11/stl.h>
|
#include <pybind11/stl.h>
|
||||||
#include <pybind11/numpy.h>
|
#include <pybind11/numpy.h>
|
||||||
|
|
||||||
#include <kompute/Kompute.hpp>
|
#include <kompute/Core.hpp>
|
||||||
|
#include <kompute/Manager.hpp>
|
||||||
|
#include <kompute/operations/OpAlgoBase.hpp>
|
||||||
|
#include <kompute/operations/OpMult.hpp>
|
||||||
|
#include <kompute/operations/OpTensorSyncLocal.hpp>
|
||||||
|
#include <kompute/operations/OpTensorSyncDevice.hpp>
|
||||||
|
#include <kompute/operations/OpTensorCopy.hpp>
|
||||||
|
#include <kompute/operations/OpAlgoLhsRhsOut.hpp>
|
||||||
|
|
||||||
#include "docstrings.hpp"
|
#include "docstrings.hpp"
|
||||||
|
|
||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
|
//used in Core.hpp
|
||||||
|
py::object kp_logger;
|
||||||
|
|
||||||
PYBIND11_MODULE(kp, m) {
|
PYBIND11_MODULE(kp, m) {
|
||||||
|
py::module_ logging = py::module_::import("logging");
|
||||||
|
kp_logger = logging.attr("getLogger")("kp");
|
||||||
|
logging.attr("basicConfig")();
|
||||||
|
|
||||||
py::module_ np = py::module_::import("numpy");
|
py::module_ np = py::module_::import("numpy");
|
||||||
|
|
||||||
|
|
|
||||||
2
setup.py
2
setup.py
|
|
@ -41,7 +41,7 @@ class CMakeBuild(build_ext):
|
||||||
|
|
||||||
cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
|
cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
|
||||||
'-DKOMPUTE_OPT_BUILD_PYTHON=1',
|
'-DKOMPUTE_OPT_BUILD_PYTHON=1',
|
||||||
'-DKOMPUTE_OPT_ENABLE_SPDLOG=1',
|
'-DKOMPUTE_OPT_ENABLE_SPDLOG=0',
|
||||||
'-DKOMPUTE_OPT_REPO_SUBMODULE_BUILD=1',
|
'-DKOMPUTE_OPT_REPO_SUBMODULE_BUILD=1',
|
||||||
'-DPYTHON_EXECUTABLE=' + sys.executable]
|
'-DPYTHON_EXECUTABLE=' + sys.executable]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -124,3 +124,12 @@ if(KOMPUTE_OPT_INSTALL)
|
||||||
DESTINATION lib/cmake/kompute)
|
DESTINATION lib/cmake/kompute)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(KOMPUTE_OPT_BUILD_PYTHON)
|
||||||
|
include_directories(${PROJECT_SOURCE_DIR}/python/pybind11/include)
|
||||||
|
if (WIN32)
|
||||||
|
execute_process(COMMAND CMD /c python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())" OUTPUT_VARIABLE PYTHON_INCLUDE_DIR)
|
||||||
|
else()
|
||||||
|
execute_process(COMMAND python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())" OUTPUT_VARIABLE PYTHON_INCLUDE_DIR)
|
||||||
|
endif()
|
||||||
|
include_directories(${PYTHON_INCLUDE_DIR})
|
||||||
|
endif()
|
||||||
|
|
|
||||||
|
|
@ -32,53 +32,76 @@ static const char* KOMPUTE_LOG_TAG = "KomputeLog";
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(KOMPUTE_BUILD_PYTHON)
|
||||||
|
#include <pybind11/pybind11.h>
|
||||||
|
namespace py = pybind11;
|
||||||
|
//from python/src/main.cpp
|
||||||
|
extern py::object kp_logger;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef KOMPUTE_LOG_OVERRIDE
|
#ifndef KOMPUTE_LOG_OVERRIDE
|
||||||
#if KOMPUTE_ENABLE_SPDLOG
|
#if KOMPUTE_ENABLE_SPDLOG
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#else
|
#else
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#if SPDLOG_ACTIVE_LEVEL > 1
|
#if SPDLOG_ACTIVE_LEVEL > 1
|
||||||
#define SPDLOG_DEBUG(message, ...)
|
#define SPDLOG_DEBUG(message, ...)
|
||||||
#else
|
#else
|
||||||
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||||
#define SPDLOG_DEBUG(message, ...) \
|
#define SPDLOG_DEBUG(message, ...) \
|
||||||
((void)__android_log_print(ANDROID_LOG_DEBUG, KOMPUTE_LOG_TAG, message))
|
((void)__android_log_print(ANDROID_LOG_DEBUG, KOMPUTE_LOG_TAG, message))
|
||||||
#else
|
#elif defined(KOMPUTE_BUILD_PYTHON)
|
||||||
#define SPDLOG_DEBUG(message, ...) \
|
#define SPDLOG_DEBUG(message, ...) \
|
||||||
std::cout << "DEBUG: " << message << std::endl
|
kp_logger.attr("debug")(message);
|
||||||
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
#else
|
||||||
#endif // SPDLOG_ACTIVE_LEVEL > 1
|
#define SPDLOG_DEBUG(message, ...) \
|
||||||
#if SPDLOG_ACTIVE_LEVEL > 2
|
std::cout << "DEBUG: " << message << std::endl
|
||||||
#define SPDLOG_INFO(message, ...)
|
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
||||||
#else
|
#endif // SPDLOG_ACTIVE_LEVEL > 1
|
||||||
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
|
||||||
#define SPDLOG_INFO(message, ...) \
|
#if SPDLOG_ACTIVE_LEVEL > 2
|
||||||
((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message))
|
#define SPDLOG_INFO(message, ...)
|
||||||
#else
|
#else
|
||||||
#define SPDLOG_INFO(message, ...) std::cout << "INFO: " << message << std::endl
|
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||||
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
#define SPDLOG_INFO(message, ...) \
|
||||||
#endif // SPDLOG_ACTIVE_LEVEL > 2
|
((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message))
|
||||||
#if SPDLOG_ACTIVE_LEVEL > 3
|
#elif defined(KOMPUTE_BUILD_PYTHON)
|
||||||
#define SPDLOG_WARN(message, ...)
|
#define SPDLOG_INFO(message, ...) \
|
||||||
#else
|
kp_logger.attr("info")(message);
|
||||||
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
#else
|
||||||
#define SPDLOG_WARN(message, ...) \
|
#define SPDLOG_INFO(message, ...) std::cout << "INFO: " << message << std::endl
|
||||||
((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message))
|
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
||||||
#else
|
#endif // SPDLOG_ACTIVE_LEVEL > 2
|
||||||
#define SPDLOG_WARN(message, ...) \
|
|
||||||
std::cout << "WARNING: " << message << std::endl
|
#if SPDLOG_ACTIVE_LEVEL > 3
|
||||||
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
#define SPDLOG_WARN(message, ...)
|
||||||
#endif // SPDLOG_ACTIVE_LEVEL > 3
|
#else
|
||||||
#if SPDLOG_ACTIVE_LEVEL > 4
|
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||||
#define SPDLOG_ERROR(message, ...)
|
#define SPDLOG_WARN(message, ...) \
|
||||||
#else
|
((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message))
|
||||||
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
#elif defined(KOMPUTE_BUILD_PYTHON)
|
||||||
#define SPDLOG_ERROR(message, ...) \
|
#define SPDLOG_WARN(message, ...) \
|
||||||
((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message))
|
kp_logger.attr("warning")(message);
|
||||||
#else
|
#else
|
||||||
#define SPDLOG_ERROR(message, ...) \
|
#define SPDLOG_WARN(message, ...) \
|
||||||
std::cout << "ERROR: " << message << std::endl
|
std::cout << "WARNING: " << message << std::endl
|
||||||
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
||||||
#endif // SPDLOG_ACTIVE_LEVEL > 4
|
#endif // SPDLOG_ACTIVE_LEVEL > 3
|
||||||
#endif // KOMPUTE_SPDLOG_ENABLED
|
|
||||||
|
#if SPDLOG_ACTIVE_LEVEL > 4
|
||||||
|
#define SPDLOG_ERROR(message, ...)
|
||||||
|
#else
|
||||||
|
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||||
|
#define SPDLOG_ERROR(message, ...) \
|
||||||
|
((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message))
|
||||||
|
#elif defined(KOMPUTE_BUILD_PYTHON)
|
||||||
|
#define SPDLOG_ERROR(message, ...) \
|
||||||
|
kp_logger.attr("error")(message);
|
||||||
|
#else
|
||||||
|
#define SPDLOG_ERROR(message, ...) \
|
||||||
|
std::cout << "ERROR: " << message << std::endl
|
||||||
|
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
||||||
|
#endif // SPDLOG_ACTIVE_LEVEL > 4
|
||||||
|
#endif // KOMPUTE_SPDLOG_ENABLED
|
||||||
#endif // KOMPUTE_LOG_OVERRIDE
|
#endif // KOMPUTE_LOG_OVERRIDE
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue