From 9077e95fc9ca9de7c54aef8008290e59e6dfd2ef Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Tue, 3 Nov 2020 18:32:33 +0000 Subject: [PATCH 01/11] Updated docstrings --- docs/overview/advanced-examples.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/overview/advanced-examples.rst b/docs/overview/advanced-examples.rst index cc0770a25..94d9f226e 100644 --- a/docs/overview/advanced-examples.rst +++ b/docs/overview/advanced-examples.rst @@ -23,7 +23,7 @@ End-to-end examples * `Machine Learning Logistic Regression Implementation `_ -* `Parallelizing GPU-intensive Workloads via Multi-Queue Operations [https://towardsdatascience.com/parallelizing-heavy-gpu-workloads-via-multi-queue-operations-50a38b15a1dc>`_ +* `Parallelizing GPU-intensive Workloads via Multi-Queue Operations `_ * `Android NDK Mobile Kompute ML Application `_ * `Game Development Kompute ML in Godot Engine `_ From 16f49a7c879a12e72abce2d43caca436a2dbafbf Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Tue, 3 Nov 2020 20:54:30 +0000 Subject: [PATCH 02/11] Added clearing of operations within sequence to ensure all resources are cleared --- src/Sequence.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Sequence.cpp b/src/Sequence.cpp index 4f01891c4..c151eb9c8 100644 --- a/src/Sequence.cpp +++ b/src/Sequence.cpp @@ -244,6 +244,11 @@ Sequence::freeMemoryDestroyGPUResources() SPDLOG_DEBUG("Kompute Sequence Destroyed CommandPool"); } + if (this->mOperations.size()) { + SPDLOG_INFO("Kompute Sequence clearing operations buffer"); + this->mOperations.clear(); + } + this->mIsInit = false; } From cc6bdfef4c95f2f5c73bd8bf13700cd5607c3812 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Tue, 3 Nov 2020 20:55:01 +0000 Subject: [PATCH 03/11] Updated setup.py to use submodule build and build spdlog --- setup.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 0b5db2f9c..ca1a7b0ae 100644 --- a/setup.py +++ b/setup.py @@ -23,10 +23,9 @@ class CMakeBuild(build_ext): raise RuntimeError("CMake must be installed to build the following extensions: " + ", ".join(e.name for e in self.extensions)) - if platform.system() == "Windows": - cmake_version = LooseVersion(re.search(r'version\s*([\d.]+)', out.decode()).group(1)) - if cmake_version < '3.1.0': - raise RuntimeError("CMake >= 3.1.0 is required on Windows") + cmake_version = LooseVersion(re.search(r'version\s*([\d.]+)', out.decode()).group(1)) + if cmake_version < '3.4.1': + raise RuntimeError("CMake >= 3.4.1 is required") for ext in self.extensions: self.build_extension(ext) @@ -39,7 +38,8 @@ class CMakeBuild(build_ext): cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, '-DKOMPUTE_OPT_BUILD_PYTHON=1', - '-DKOMPUTE_OPT_BUILD_SINGLE_HEADER=1', + '-DKOMPUTE_OPT_ENABLE_SPDLOG=1', + '-DKOMPUTE_OPT_REPO_SUBMODULE_BUILD=1', '-DPYTHON_EXECUTABLE=' + sys.executable] cfg = 'Debug' if self.debug else 'Release' From 9b6f5b0424704a9a36e56caf18bc4477e9104b08 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Tue, 3 Nov 2020 20:56:51 +0000 Subject: [PATCH 04/11] Updated build to always use non-submodule build but have working submodule build when people want to use it --- CMakeLists.txt | 1 + Makefile | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 454876d4e..bd489d465 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ set(KOMPUTE_EXTRA_CXX_FLAGS "" CACHE STRING "Extra compile flags for Kompute, se if(KOMPUTE_OPT_ENABLE_SPDLOG) set(KOMPUTE_EXTRA_CXX_FLAGS "${KOMPUTE_EXTRA_CXX_FLAGS} -DKOMPUTE_ENABLE_SPDLOG=1") + set(SPDLOG_INSTALL, 1) endif() if(KOMPUTE_OPT_ANDOID_BUILD) diff --git a/Makefile b/Makefile index 2ed2c457d..5aabbd294 100755 --- a/Makefile +++ b/Makefile @@ -86,7 +86,7 @@ mk_run_tests: mk_build_tests VS_BUILD_TYPE ?= "Debug" # Run with multiprocessin / parallel build by default VS_CMAKE_EXTRA_FLAGS ?= "" -VS_KOMPUTE_EXTRA_CXX_FLAGS ?= "/MP" # Adding multiprocessing by default. You should add "/MT" for submodule builds for compatibility with gtest +VS_KOMPUTE_EXTRA_CXX_FLAGS ?= "/MP" # /MP is for faster multiprocessing builds. You should add "/MT" for submodule builds for compatibility with gtest VS_INSTALL_PATH ?= "build/src/CMakeFiles/Export/" # Set to "" if prefer default vs_cmake: From fb95694944b3822e49bd7eb5483e26442bba9572 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Tue, 3 Nov 2020 21:40:49 +0000 Subject: [PATCH 05/11] ADded spdlog log level capabilites to change verbousity --- python/src/main.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/python/src/main.cpp b/python/src/main.cpp index 0f10ea349..e50ec7945 100644 --- a/python/src/main.cpp +++ b/python/src/main.cpp @@ -7,6 +7,20 @@ namespace py = pybind11; PYBIND11_MODULE(kp, m) { +#if KOMPUTE_ENABLE_SPDLOG + spdlog::set_level( + static_cast(SPDLOG_ACTIVE_LEVEL)); +#endif + + m.def("log_level", [](uint8_t logLevel) { +#if KOMPUTE_ENABLE_SPDLOG + spdlog::set_level( + static_cast(SPDLOG_LEVEL_INFO)); +#else + SPDLOG_WARN("SPDLOG not enabled so log level config function not supported"); +#endif + }); + py::enum_(m, "TensorTypes", "Enum with GPU memory types for Tensor.") .value("device", kp::Tensor::TensorTypes::eDevice, "Tensor holding data in GPU memory.") .value("staging", kp::Tensor::TensorTypes::eStaging, "Tensor used for transfer of data to device.") From 72cd1b51a3131cb8e4d298bfe9a605c7082ae406 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Tue, 3 Nov 2020 21:41:19 +0000 Subject: [PATCH 06/11] Minor refactor on spdlog_active_level macro --- single_include/kompute/Kompute.hpp | 2 +- src/include/kompute/Core.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/single_include/kompute/Kompute.hpp b/single_include/kompute/Kompute.hpp index 3ae98b483..9674d44c4 100755 --- a/single_include/kompute/Kompute.hpp +++ b/single_include/kompute/Kompute.hpp @@ -24,7 +24,7 @@ static const char* KOMPUTE_LOG_TAG = "KomputeLog"; #endif // KOMPUTE_VK_API_VERSION // SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import -#if !defined(SPDLOG_ACTIVE_LEVEL) +#ifndef SPDLOG_ACTIVE_LEVEL #if DEBUG #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG #else diff --git a/src/include/kompute/Core.hpp b/src/include/kompute/Core.hpp index 72ffa5346..73d6bc88e 100644 --- a/src/include/kompute/Core.hpp +++ b/src/include/kompute/Core.hpp @@ -24,7 +24,7 @@ static const char* KOMPUTE_LOG_TAG = "KomputeLog"; #endif // KOMPUTE_VK_API_VERSION // SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import -#if !defined(SPDLOG_ACTIVE_LEVEL) +#ifndef SPDLOG_ACTIVE_LEVEL #if DEBUG #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG #else From 752bed56382ba44238d37fb11f3282f4c2b99530 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Tue, 3 Nov 2020 21:41:42 +0000 Subject: [PATCH 07/11] ADded spdlog_active_level to 0 for defualt compilation of debug code --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ca1a7b0ae..120ea82f6 100644 --- a/setup.py +++ b/setup.py @@ -46,12 +46,13 @@ class CMakeBuild(build_ext): build_args = ['--config', cfg] if platform.system() == "Windows": + cmake_args += ['-DKOMPUTE_EXTRA_CXX_FLAGS="-DSPDLOG_ACTIVE_LEVEL=0"'] cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir)] if sys.maxsize > 2**32: cmake_args += ['-A', 'x64'] build_args += ['--', '/m'] else: - cmake_args += ['-DKOMPUTE_EXTRA_CXX_FLAGS="-fPIC"'] + cmake_args += ['-DKOMPUTE_EXTRA_CXX_FLAGS="-fPIC -DSPDLOG_ACTIVE_LEVEL=0"'] cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] build_args += ['--', '-j2'] From 68028420cb9831a7e9b5ec23c7702bb04f10bcfa Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Tue, 3 Nov 2020 21:42:38 +0000 Subject: [PATCH 08/11] Added debug information on docs --- docs/overview/python-package.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/overview/python-package.rst b/docs/overview/python-package.rst index 74e0cba91..69c1f92e4 100644 --- a/docs/overview/python-package.rst +++ b/docs/overview/python-package.rst @@ -87,5 +87,13 @@ The package can be installed through the top level `setup.py` by running: pip install . ``` +You can configure log level with the function `kp.log_level` as outlined below. + +The values are TRACE=0, DEBUG=1, INFO=2, WARN=3, ERROR=4. Kompute defaults to INFO. + +``` +import kp +kp.log_level(1) +``` From 04e9a24705a8661f880f23f99b4c3c1523724877 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Wed, 4 Nov 2020 20:58:05 +0000 Subject: [PATCH 09/11] Uplaoded python package to pypi --- MANIFEST.in | 6 ++++++ README.md | 38 +++++++++++++++++++------------------- setup.py | 13 +++++++++---- 3 files changed, 34 insertions(+), 23 deletions(-) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 000000000..e9f375e39 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,6 @@ +include CMakeLists.txt +recursive-include src * +recursive-include python * +recursive-include single_include * +recursive-include external * + diff --git a/README.md b/README.md index b745ccfbf..ad50bb4d0 100644 --- a/README.md +++ b/README.md @@ -179,6 +179,25 @@ static std::string shaderData = "path/to/shader.glsl"; static std::string shaderData = "path/to/shader.glsl.spv"; ``` +## More examples + +### Simple examples + +* [Pass shader as raw string](https://kompute.cc/overview/advanced-examples.html#simple-shader-example) +* [Record batch commands with a Kompute Sequence](https://kompute.cc/overview/advanced-examples.html#record-batch-commands) +* [Run Asynchronous Operations](https://kompute.cc/overview/advanced-examples.html#asynchronous-operations) +* [Run Parallel Operations Across Multiple GPU Queues](https://kompute.cc/overview/advanced-examples.html#parallel-operations) +* [Create your custom Kompute Operations](https://kompute.cc/overview/advanced-examples.html#your-custom-kompute-operation) +* [Implementing logistic regression from scratch](https://kompute.cc/overview/advanced-examples.html#logistic-regression-example) + +### End-to-end examples + +* [Machine Learning Logistic Regression Implementation](https://towardsdatascience.com/machine-learning-and-data-processing-in-the-gpu-with-vulkan-kompute-c9350e5e5d3a) +* [Parallelizing GPU-intensive Workloads via Multi-Queue Operations](https://towardsdatascience.com/parallelizing-heavy-gpu-workloads-via-multi-queue-operations-50a38b15a1dc) +* [Android NDK Mobile Kompute ML Application](https://towardsdatascience.com/gpu-accelerated-machine-learning-in-your-mobile-applications-using-the-android-ndk-vulkan-kompute-1e9da37b7617) +* [Game Development Kompute ML in Godot Engine](https://towardsdatascience.com/supercharging-game-development-with-gpu-accelerated-ml-using-vulkan-kompute-the-godot-game-engine-4e75a84ea9f0) + + ## Architectural Overview The core architecture of Kompute includes the following: @@ -329,25 +348,6 @@ assert tensor_out.data() == [2.0, 4.0, 6.0] For further details you can read the [Python Package documentation](https://kompute.cc/overview/python-package.html) or the [Python Class Reference documentation](https://kompute.cc/overview/python-reference.html). -## More examples - -### Simple examples - -* [Pass shader as raw string](https://kompute.cc/overview/advanced-examples.html#simple-shader-example) -* [Record batch commands with a Kompute Sequence](https://kompute.cc/overview/advanced-examples.html#record-batch-commands) -* [Run Asynchronous Operations](https://kompute.cc/overview/advanced-examples.html#asynchronous-operations) -* [Run Parallel Operations Across Multiple GPU Queues](https://kompute.cc/overview/advanced-examples.html#parallel-operations) -* [Create your custom Kompute Operations](https://kompute.cc/overview/advanced-examples.html#your-custom-kompute-operation) -* [Implementing logistic regression from scratch](https://kompute.cc/overview/advanced-examples.html#logistic-regression-example) - -### End-to-end examples - -* [Machine Learning Logistic Regression Implementation](https://towardsdatascience.com/machine-learning-and-data-processing-in-the-gpu-with-vulkan-kompute-c9350e5e5d3a) -* [Parallelizing GPU-intensive Workloads via Multi-Queue Operations](https://towardsdatascience.com/parallelizing-heavy-gpu-workloads-via-multi-queue-operations-50a38b15a1dc) -* [Android NDK Mobile Kompute ML Application](https://towardsdatascience.com/gpu-accelerated-machine-learning-in-your-mobile-applications-using-the-android-ndk-vulkan-kompute-1e9da37b7617) -* [Game Development Kompute ML in Godot Engine](https://towardsdatascience.com/supercharging-game-development-with-gpu-accelerated-ml-using-vulkan-kompute-the-godot-game-engine-4e75a84ea9f0) - - ## Build Overview The build system provided uses `cmake`, which allows for cross platform builds. diff --git a/setup.py b/setup.py index 120ea82f6..eac6985ad 100644 --- a/setup.py +++ b/setup.py @@ -8,6 +8,9 @@ from setuptools import setup, Extension from setuptools.command.build_ext import build_ext from distutils.version import LooseVersion +curr_dir = os.path.abspath(os.path.dirname(__file__)) +with open(os.path.join(curr_dir, 'README.md'), encoding='utf-8') as f: + long_description = f.read() class CMakeExtension(Extension): def __init__(self, name, sourcedir=''): @@ -46,13 +49,13 @@ class CMakeBuild(build_ext): build_args = ['--config', cfg] if platform.system() == "Windows": - cmake_args += ['-DKOMPUTE_EXTRA_CXX_FLAGS="-DSPDLOG_ACTIVE_LEVEL=0"'] + cmake_args += ['-DKOMPUTE_EXTRA_CXX_FLAGS=""'] cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir)] if sys.maxsize > 2**32: cmake_args += ['-A', 'x64'] build_args += ['--', '/m'] else: - cmake_args += ['-DKOMPUTE_EXTRA_CXX_FLAGS="-fPIC -DSPDLOG_ACTIVE_LEVEL=0"'] + cmake_args += ['-DKOMPUTE_EXTRA_CXX_FLAGS="-fPIC"'] cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] build_args += ['--', '-j2'] @@ -67,11 +70,13 @@ class CMakeBuild(build_ext): setup( name='kp', - version='0.0.1', + version='0.4.1', author='Alejandro Saucedo', description='Vulkan Kompute: Blazing fast, mobile-enabled, asynchronous, and optimized for advanced GPU processing usecases.', - long_description='', + long_description=long_description, + long_description_content_type='text/markdown', ext_modules=[CMakeExtension('kp')], cmdclass=dict(build_ext=CMakeBuild), zip_safe=False, + include_package_data=True, ) From 54cac4b7415f0c5ad3de83e55d4963e367c7f5a1 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Wed, 4 Nov 2020 21:10:53 +0000 Subject: [PATCH 10/11] Updated python package --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ad50bb4d0..43b3b8511 100644 --- a/README.md +++ b/README.md @@ -278,10 +278,16 @@ You can also access the