From 0e9ba00b710e060b46ec1c23a4ee4f9542b3b031 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 1 Nov 2020 15:14:22 +0000 Subject: [PATCH] Added base capabilities for tensor in python --- python/CMakeLists.txt | 9 ++++++++- python/src/main.cpp | 22 ++++++++++++++++++++-- setup.py | 10 +++++----- src/CMakeLists.txt | 3 ++- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index f0b4949ac..6ef7fde4b 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,4 +1,11 @@ add_subdirectory(pybind11) -pybind11_add_module(cmake_example src/main.cpp) +pybind11_add_module(komputepy src/main.cpp) + +include_directories( + ${PROJECT_SOURCE_DIR}/single_include/) + +target_link_libraries( + komputepy PRIVATE + kompute::kompute) diff --git a/python/src/main.cpp b/python/src/main.cpp index 1330bab19..5fe74f021 100644 --- a/python/src/main.cpp +++ b/python/src/main.cpp @@ -1,9 +1,27 @@ #include -#include "kompute/Kompute.hpp" +#include + +#include namespace py = pybind11; -PYBIND11_MODULE(cmake_example, m) { +PYBIND11_MODULE(komputepy, m) { + + py::enum_(m, "TensorTypes") + .value("eDevice", kp::Tensor::TensorTypes::eDevice) + .value("eStaging", kp::Tensor::TensorTypes::eStaging) + .value("eStorage", kp::Tensor::TensorTypes::eStorage) + .export_values(); + + py::class_(m, "Tensor") + .def(py::init( + [](const std::vector& data) { + return std::unique_ptr(new kp::Tensor(data)); + })) + .def(py::init( + [](const std::vector& data, kp::Tensor::TensorTypes tensorTypes) { + return std::unique_ptr(new kp::Tensor(data, tensorTypes)); + })); #ifdef VERSION_INFO m.attr("__version__") = VERSION_INFO; diff --git a/setup.py b/setup.py index 07d769b5b..e09673a97 100644 --- a/setup.py +++ b/setup.py @@ -51,6 +51,7 @@ class CMakeBuild(build_ext): cmake_args += ['-A', 'x64'] build_args += ['--', '/m'] else: + cmake_args += ['-DKOMPUTE_EXTRA_CXX_FLAGS="-fPIC"'] cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] build_args += ['--', '-j2'] @@ -64,13 +65,12 @@ class CMakeBuild(build_ext): subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp) setup( - name='cmake_example', + name='komputepy', version='0.0.1', - author='Dean Moldovan', - author_email='dean0x7d@gmail.com', - description='A test project using pybind11 and CMake', + author='Alejandro Saucedo', + description='Blazing fast, mobile-enabled, asynchronous, and optimized for advanced GPU processing usecases.', long_description='', - ext_modules=[CMakeExtension('cmake_example')], + ext_modules=[CMakeExtension('komputepy')], cmdclass=dict(build_ext=CMakeBuild), zip_safe=False, ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6161b782b..348c0536a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -48,7 +48,8 @@ if(KOMPUTE_OPT_ANDOID_BUILD) ${PROJECT_SOURCE_DIR}/vk_ndk_wrapper_include/kompute_vk_ndk_wrapper.cpp) endif() -add_library(kompute +add_library( + kompute STATIC ${kompute_CPP}) target_include_directories(