From 23d6340c3f3040e39ded086922393dce99812dc0 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 1 Nov 2020 08:05:30 +0000 Subject: [PATCH 01/13] Updated dockefile --- Makefile | 8 +------- builders/Dockerfile.linux | 10 ++++++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 43c163b61..08c9fb090 100755 --- a/Makefile +++ b/Makefile @@ -125,7 +125,7 @@ vs_run_tests: vs_build_tests ####### Create release ###### update_builder_image: - docker build -f Dockerfile.linux . \ + docker build -f builders/Dockerfile.linux . \ -t axsauze/kompute-builder:0.1 docker push axsauze/kompute-builder:0.1 @@ -152,12 +152,6 @@ build_shaders: --header-path test/compiled_shaders_include/kompute_test/shaders/ \ -v -docker_vulkan_build: - docker build . -t axsauze/vulkan-sum:0.1 - -push_vulkan_docker: - docker push axsauze/vulkan-sum:0.1 - build_single_header: quom \ --include_directory \ diff --git a/builders/Dockerfile.linux b/builders/Dockerfile.linux index bbbaecadb..cdece9e59 100644 --- a/builders/Dockerfile.linux +++ b/builders/Dockerfile.linux @@ -1,15 +1,17 @@ FROM amd64/ubuntu:20.04 +ARG VULKAN_SDK_VERSION=1.2.154.0 + # First install vulkan RUN apt-get update RUN apt-get install -y curl unzip tar wget -RUN wget -O VulkanSDK.tar.gz https://sdk.lunarg.com/sdk/download/1.2.141.2/linux/vulkansdk-linux-x86_64-1.2.141.2.tar.gz?u=true && \ +RUN wget -O VulkanSDK.tar.gz https://sdk.lunarg.com/sdk/download/${VULKAN_SDK_VERSION}/linux/vulkansdk-linux-x86_64-${VULKAN_SDK_VERSION}.tar.gz?u=true && \ mkdir VulkanSDK && \ cd VulkanSDK && \ tar xvf /VulkanSDK.tar.gz -RUN cd VulkanSDK/1.2.141.2 -ENV VULKAN_SDK="/VulkanSDK/1.2.141.2/x86_64" +RUN cd VulkanSDK/${VULKAN_SDK_VERSION} +ENV VULKAN_SDK="/VulkanSDK/${VULKAN_SDK_VERSION}/x86_64" ENV PATH="${VULKAN_SDK}/bin:${PATH}" ENV LD_LIBRARY_PATH="${VULKAN_SDK}/lib" ENV VK_LAYER_PATH="${VULKAN_SDK}/etc/explicit_layer.d" @@ -53,7 +55,7 @@ ENV VCPKG_PATH=/core/vcpkg ENV VCPKG_ROOT=/core/vcpkg # INstall dependencies for kompute -RUN vcpkg install catch2 fmt spdlog vulkan +RUN /core/vcpkg/vcpkg install fmt spdlog vulkan-headers gtest RUN mkdir /workspace WORKDIR /workspace From 44dfe2debf16273a099a03f991babb372b37664d Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 1 Nov 2020 08:05:46 +0000 Subject: [PATCH 02/13] updated vcpkg to ensure relevant packages are selected --- vcpkg.json.opt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vcpkg.json.opt b/vcpkg.json.opt index ccc585b21..2eb453f37 100644 --- a/vcpkg.json.opt +++ b/vcpkg.json.opt @@ -2,9 +2,9 @@ "name": "example", "version-string": "0.0.1", "dependencies": [ + "fmt", "spdlog", - "vulkan", - "vulkan-hpp", + "vulkan-headers", "gtest" ] } From 681defe1448479a78aa9fdc4e974e11db24b223c Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 1 Nov 2020 08:06:10 +0000 Subject: [PATCH 03/13] Added gitmodules --- .gitmodules | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..cc63b26ad --- /dev/null +++ b/.gitmodules @@ -0,0 +1,12 @@ +[submodule "external/googletest"] + path = external/googletest + url = https://github.com/google/googletest + branch = release-1.10.0 +[submodule "external/Vulkan-Headers"] + path = external/Vulkan-Headers + url = https://github.com/KhronosGroup/Vulkan-Headers + branch = v1.2.158 +[submodule "external/spdlog"] + path = external/spdlog + url = https://github.com/gabime/spdlog + branch = v1.8.1 From 4b834be99b9fcf6e3b8afbfcc49ad5aa12421194 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 1 Nov 2020 08:09:03 +0000 Subject: [PATCH 04/13] Added gitmodules --- .gitmodules | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index cc63b26ad..1c5db0adc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +1,12 @@ [submodule "external/googletest"] path = external/googletest url = https://github.com/google/googletest - branch = release-1.10.0 + branch = release-1.10.0 [submodule "external/Vulkan-Headers"] path = external/Vulkan-Headers url = https://github.com/KhronosGroup/Vulkan-Headers - branch = v1.2.158 + branch = v1.2.158 [submodule "external/spdlog"] path = external/spdlog url = https://github.com/gabime/spdlog - branch = v1.8.1 + branch = v1.8.1 From f75b6e77e498bb9fc26fc187546ec7312908368e Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 1 Nov 2020 08:09:43 +0000 Subject: [PATCH 05/13] Removed tmp gitmodules --- .gitmodules | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 1c5db0adc..000000000 --- a/.gitmodules +++ /dev/null @@ -1,12 +0,0 @@ -[submodule "external/googletest"] - path = external/googletest - url = https://github.com/google/googletest - branch = release-1.10.0 -[submodule "external/Vulkan-Headers"] - path = external/Vulkan-Headers - url = https://github.com/KhronosGroup/Vulkan-Headers - branch = v1.2.158 -[submodule "external/spdlog"] - path = external/spdlog - url = https://github.com/gabime/spdlog - branch = v1.8.1 From 20e3b9ec454b7bd6dbc48dee49bb797d9037ac1a Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 1 Nov 2020 08:11:57 +0000 Subject: [PATCH 06/13] Added googletest release 1.10.0 --- .gitmodules | 4 ++++ external/googletest | 1 + 2 files changed, 5 insertions(+) create mode 100644 .gitmodules create mode 160000 external/googletest diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..89198da65 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "external/googletest"] + path = external/googletest + url = https://github.com/google/googletest + branch = release-1.10.0 diff --git a/external/googletest b/external/googletest new file mode 160000 index 000000000..703bd9caa --- /dev/null +++ b/external/googletest @@ -0,0 +1 @@ +Subproject commit 703bd9caab50b139428cea1aaff9974ebee5742e From 5c674d510eb52c1bec614be6d92e9239df459ab2 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 1 Nov 2020 08:13:41 +0000 Subject: [PATCH 07/13] Added vulkan headers --- .gitmodules | 4 ++++ external/Vulkan-Headers | 1 + 2 files changed, 5 insertions(+) create mode 160000 external/Vulkan-Headers diff --git a/.gitmodules b/.gitmodules index 89198da65..869b893b3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,3 +2,7 @@ path = external/googletest url = https://github.com/google/googletest branch = release-1.10.0 +[submodule "external/Vulkan-Headers"] + path = external/Vulkan-Headers + url = https://github.com/KhronosGroup/Vulkan-Headers + branch = v1.2.158 diff --git a/external/Vulkan-Headers b/external/Vulkan-Headers new file mode 160000 index 000000000..320af06cb --- /dev/null +++ b/external/Vulkan-Headers @@ -0,0 +1 @@ +Subproject commit 320af06cbdd29848e1d7100d9b8e4e517db1dfd5 From 482aa294266da70c9d7b94beba3bc646ab421d71 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 1 Nov 2020 08:14:42 +0000 Subject: [PATCH 08/13] Added spdlog --- .gitmodules | 4 ++++ external/spdlog | 1 + 2 files changed, 5 insertions(+) create mode 160000 external/spdlog diff --git a/.gitmodules b/.gitmodules index 869b893b3..1c5db0adc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,3 +6,7 @@ path = external/Vulkan-Headers url = https://github.com/KhronosGroup/Vulkan-Headers branch = v1.2.158 +[submodule "external/spdlog"] + path = external/spdlog + url = https://github.com/gabime/spdlog + branch = v1.8.1 diff --git a/external/spdlog b/external/spdlog new file mode 160000 index 000000000..01b350de9 --- /dev/null +++ b/external/spdlog @@ -0,0 +1 @@ +Subproject commit 01b350de96483cf00b267c6db4c25f3b739b3fee From 8abac9fb5890aa9aa1907a9d90f95b2cd2fc3384 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 1 Nov 2020 10:46:16 +0000 Subject: [PATCH 09/13] Added fix to work for versions 1.2.55+ of vulkan headers --- src/Algorithm.cpp | 12 ++++++------ src/Manager.cpp | 6 +++--- src/Sequence.cpp | 4 ++-- src/Tensor.cpp | 6 +++--- test/TestLogisticRegression.cpp | 2 +- test/TestMain.cpp | 3 +-- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/Algorithm.cpp b/src/Algorithm.cpp index 845036475..70092a3d6 100644 --- a/src/Algorithm.cpp +++ b/src/Algorithm.cpp @@ -34,7 +34,7 @@ Algorithm::~Algorithm() SPDLOG_ERROR("Kompute Algorithm Error requested to destroy " "pipeline but it is null"); } - this->mDevice->destroy(*this->mPipeline); + this->mDevice->destroy(*this->mPipeline, (vk::Optional)nullptr); } if (this->mFreePipelineCache) { @@ -43,7 +43,7 @@ Algorithm::~Algorithm() SPDLOG_ERROR("Kompute Algorithm Error requested to destroy " "pipeline cache but it is null"); } - this->mDevice->destroy(*this->mPipelineCache); + this->mDevice->destroy(*this->mPipelineCache, (vk::Optional)nullptr); } if (this->mFreePipelineLayout) { @@ -52,7 +52,7 @@ Algorithm::~Algorithm() SPDLOG_ERROR("Kompute Algorithm Error requested to destroy " "pipeline layout but it is null"); } - this->mDevice->destroy(*this->mPipelineLayout); + this->mDevice->destroy(*this->mPipelineLayout, (vk::Optional)nullptr); } if (this->mFreeShaderModule) { @@ -61,7 +61,7 @@ Algorithm::~Algorithm() SPDLOG_ERROR("Kompute Algorithm Error requested to destroy shader " "module but it is null"); } - this->mDevice->destroy(*this->mShaderModule); + this->mDevice->destroy(*this->mShaderModule, (vk::Optional)nullptr); } if (this->mFreeDescriptorSet) { @@ -80,7 +80,7 @@ Algorithm::~Algorithm() SPDLOG_ERROR("Kompute Algorithm Error requested to destroy " "descriptor set layout but it is null"); } - this->mDevice->destroy(*this->mDescriptorSetLayout); + this->mDevice->destroy(*this->mDescriptorSetLayout, (vk::Optional)nullptr); } if (this->mFreeDescriptorPool) { @@ -89,7 +89,7 @@ Algorithm::~Algorithm() SPDLOG_ERROR("Kompute Algorithm Error requested to destroy " "descriptor pool but it is null"); } - this->mDevice->destroy(*this->mDescriptorPool); + this->mDevice->destroy(*this->mDescriptorPool, (vk::Optional)nullptr); } } diff --git a/src/Manager.cpp b/src/Manager.cpp index c779acbea..ec86b18ed 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -65,7 +65,7 @@ Manager::~Manager() if (this->mFreeDevice) { SPDLOG_INFO("Destroying device"); - this->mDevice->destroy(); + this->mDevice->destroy((vk::Optional)nullptr); SPDLOG_DEBUG("Kompute Manager Destroyed Device"); } @@ -86,7 +86,7 @@ Manager::~Manager() #endif if (this->mFreeInstance) { - this->mInstance->destroy(); + this->mInstance->destroy((vk::Optional)nullptr); SPDLOG_DEBUG("Kompute Manager Destroyed Instance"); } } @@ -175,7 +175,7 @@ Manager::createInstance() std::vector availableLayerProperties = vk::enumerateInstanceLayerProperties(); for (vk::LayerProperties layerProperties : availableLayerProperties) { - std::string layerName(layerProperties.layerName); + std::string layerName(layerProperties.layerName.data()); uniqueLayerNames.insert(layerName); } for (const char* desiredLayerName : desiredLayerNames) { diff --git a/src/Sequence.cpp b/src/Sequence.cpp index 39db62128..c4446ff37 100644 --- a/src/Sequence.cpp +++ b/src/Sequence.cpp @@ -52,7 +52,7 @@ Sequence::~Sequence() "CommandPool pointer"); return; } - this->mDevice->destroy(*this->mCommandPool); + this->mDevice->destroy(*this->mCommandPool, (vk::Optional)nullptr); SPDLOG_DEBUG("Kompute Sequence Destroyed CommandPool"); } } @@ -186,7 +186,7 @@ Sequence::evalAwait(uint64_t waitFor) vk::Result result = this->mDevice->waitForFences(1, &this->mFence, VK_TRUE, waitFor); - this->mDevice->destroy(this->mFence); + this->mDevice->destroy(this->mFence, (vk::Optional)nullptr); this->mIsRunning = false; diff --git a/src/Tensor.cpp b/src/Tensor.cpp index bec1d77f8..31777286f 100644 --- a/src/Tensor.cpp +++ b/src/Tensor.cpp @@ -2,7 +2,7 @@ #if DEBUG #if KOMPUTE_ENABLE_SPDLOG // Only enabled if spdlog is enabled -#include +#include #endif #endif @@ -357,7 +357,7 @@ Tensor::freeMemoryDestroyGPUResources() "Kompose Tensor expected to free buffer but got null buffer"); } else { SPDLOG_DEBUG("Kompose Tensor destroying buffer"); - this->mDevice->destroy(*this->mBuffer); + this->mDevice->destroy(*this->mBuffer, (vk::Optional)nullptr); this->mBuffer = nullptr; } } @@ -368,7 +368,7 @@ Tensor::freeMemoryDestroyGPUResources() "Kompose Tensor expected to free buffer but got null memory"); } else { SPDLOG_DEBUG("Kompose Tensor freeing memory"); - this->mDevice->freeMemory(*this->mMemory); + this->mDevice->freeMemory(*this->mMemory, (vk::Optional)nullptr); this->mDevice = nullptr; } } diff --git a/test/TestLogisticRegression.cpp b/test/TestLogisticRegression.cpp index 9dfd72822..3b710678a 100644 --- a/test/TestLogisticRegression.cpp +++ b/test/TestLogisticRegression.cpp @@ -1,7 +1,7 @@ #include "gtest/gtest.h" -#include "fmt/ranges.h" +#include #include "kompute/Kompute.hpp" TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegression) diff --git a/test/TestMain.cpp b/test/TestMain.cpp index dd4cd9fe2..147a77f57 100644 --- a/test/TestMain.cpp +++ b/test/TestMain.cpp @@ -1,5 +1,5 @@ -#include +#include #include @@ -7,7 +7,6 @@ int main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); - testing::InitGoogleMock(&argc, argv); #if KOMPUTE_ENABLE_SPDLOG spdlog::set_level( From 5fbf5ee7f5e1f1a0e0ed09a883e3d108bbf34a79 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 1 Nov 2020 12:19:12 +0000 Subject: [PATCH 10/13] Updated ccls for submodule builds --- .ccls | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.ccls b/.ccls index f37e98609..2ce15d72f 100644 --- a/.ccls +++ b/.ccls @@ -13,7 +13,9 @@ -DDEBUG=1 -DKOMPUTE_INCLUDE_FOR_SYNTAX --I/c/Users/axsau/Programming/lib/vcpkg/installed/x64-linux/include/ +-I./external/Vulkan-Headers/include/ +-I./external/googletest/googletest/include/ +-I./external/spdlog/include/ -I./src/include/ -I./single_include/ -I./vk_ndk_wrapper_include/ From 672c78d2909b225e042dd322d1b74c2555f53011 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 1 Nov 2020 12:19:44 +0000 Subject: [PATCH 11/13] Removed range prints to avoid fmt external dependency --- src/Tensor.cpp | 9 +-------- test/TestLogisticRegression.cpp | 18 +++++++++--------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/Tensor.cpp b/src/Tensor.cpp index 31777286f..299622ee4 100644 --- a/src/Tensor.cpp +++ b/src/Tensor.cpp @@ -1,11 +1,4 @@ -#if DEBUG -#if KOMPUTE_ENABLE_SPDLOG -// Only enabled if spdlog is enabled -#include -#endif -#endif - #include "kompute/Tensor.hpp" namespace kp { @@ -20,7 +13,7 @@ Tensor::Tensor(const std::vector& data, TensorTypes tensorType) { #if DEBUG SPDLOG_DEBUG( - "Kompute Tensor constructor data: {}, and type: {}", data, tensorType); + "Kompute Tensor constructor data length: {}, and type: {}", data.size(), tensorType); #endif this->mData = data; diff --git a/test/TestLogisticRegression.cpp b/test/TestLogisticRegression.cpp index 3b710678a..fa8dc7b59 100644 --- a/test/TestLogisticRegression.cpp +++ b/test/TestLogisticRegression.cpp @@ -1,7 +1,7 @@ #include "gtest/gtest.h" -#include +//#include #include "kompute/Kompute.hpp" TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegression) @@ -76,10 +76,10 @@ TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegression) EXPECT_LT(bIn->data()[0], 0.0); EXPECT_LT(bIn->data()[0], 0.0); - SPDLOG_WARN("Result wIn: {}, bIn: {}, loss: {}", - wIn->data(), - bIn->data(), - lOut->data()); + //SPDLOG_WARN("Result wIn: {}, bIn: {}, loss: {}", + // wIn->data(), + // bIn->data(), + // lOut->data()); } TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegressionManualCopy) @@ -158,8 +158,8 @@ TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegressionManualCopy) EXPECT_GT(wIn->data()[1], 1.0); EXPECT_LT(bIn->data()[0], 0.0); - SPDLOG_WARN("Result wIn: {}, bIn: {}, loss: {}", - wIn->data(), - bIn->data(), - lOut->data()); + //SPDLOG_WARN("Result wIn: {}, bIn: {}, loss: {}", + // wIn->data(), + // bIn->data(), + // lOut->data()); } From 80ff9f279d7d4afbb4761dcd77f713259a77441d Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 1 Nov 2020 12:20:37 +0000 Subject: [PATCH 12/13] Updated base builds to work with local repo as well as with vcpkg --- CMakeLists.txt | 7 ++++--- Makefile | 12 ++++++++---- src/CMakeLists.txt | 21 ++++++++++++++++++--- test/CMakeLists.txt | 21 +++++++++++++++++---- 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c374887ca..52e45fcf9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,12 +11,13 @@ option(KOMPUTE_OPT_BUILD_TESTS "Enable if you want to build tests" 0) option(KOMPUTE_OPT_BUILD_DOCS "Enable if you want to build documentation" 0) option(KOMPUTE_OPT_BUILD_SHADERS "Enable if you want to re-build all shader files" 0) option(KOMPUTE_OPT_BUILD_SINGLE_HEADER "Enable if you want to build the single header file" 0) -option(KOMPUTE_OPT_INSTALL "Enable if you want to enable installation" 1) +option(KOMPUTE_OPT_INSTALL "Enable if you want to enable installation" 0) +# Build options option(KOMPUTE_OPT_ENABLE_SPDLOG "Extra compile flags for Kompute, see docs for full list" 0) +option(KOMPUTE_OPT_REPO_SUBMODULE_BUILD, "Use the submodule repos instead of external package manager" 0) option(KOMPUTE_OPT_ANDOID_BUILD "Enable android compilation flags required" 0) -# TODO: Add on docs option(KOMPUTE_OPT_DISABLE_VK_DEBUG_LAYERS "Explicitly disable debug layers even on debug" 0) - +# Build flags set(KOMPUTE_EXTRA_CXX_FLAGS "" CACHE STRING "Extra compile flags for Kompute, see docs for full list") if(KOMPUTE_OPT_ENABLE_SPDLOG) diff --git a/Makefile b/Makefile index 08c9fb090..2ed2c457d 100755 --- a/Makefile +++ b/Makefile @@ -48,16 +48,18 @@ MK_KOMPUTE_EXTRA_CXX_FLAGS ?= "" mk_cmake: cmake \ -Bbuild \ + $(MK_CMAKE_EXTRA_FLAGS) \ + -DCMAKE_TOOLCHAIN_FILE=$(VCPKG_UNIX_PATH) \ -DCMAKE_BUILD_TYPE=$(MK_BUILD_TYPE) \ -DCMAKE_INSTALL_PREFIX=$(MK_INSTALL_PATH) \ - -DCMAKE_TOOLCHAIN_FILE=$(VCPKG_UNIX_PATH) \ -DKOMPUTE_EXTRA_CXX_FLAGS=$(MK_KOMPUTE_EXTRA_CXX_FLAGS) \ + -DKOMPUTE_OPT_INSTALL=1 \ + -DKOMPUTE_OPT_REPO_SUBMODULE_BUILD=0 \ -DKOMPUTE_OPT_BUILD_TESTS=1 \ -DKOMPUTE_OPT_BUILD_DOCS=1 \ -DKOMPUTE_OPT_BUILD_SHADERS=1 \ -DKOMPUTE_OPT_BUILD_SINGLE_HEADER=1 \ -DKOMPUTE_OPT_ENABLE_SPDLOG=1 \ - $(MK_CMAKE_EXTRA_FLAGS) \ -G "Unix Makefiles" mk_build_all: @@ -84,16 +86,18 @@ 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 +VS_KOMPUTE_EXTRA_CXX_FLAGS ?= "/MP" # Adding multiprocessing by default. 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: $(CMAKE_BIN) \ -Bbuild \ - -DCMAKE_TOOLCHAIN_FILE=$(VCPKG_WIN_PATH) \ $(VS_CMAKE_EXTRA_FLAGS) \ + -DCMAKE_TOOLCHAIN_FILE=$(VCPKG_WIN_PATH) \ -DKOMPUTE_EXTRA_CXX_FLAGS=$(VS_KOMPUTE_EXTRA_CXX_FLAGS) \ -DCMAKE_INSTALL_PREFIX=$(VS_INSTALL_PATH) \ + -DKOMPUTE_OPT_INSTALL=1 \ + -DKOMPUTE_OPT_REPO_SUBMODULE_BUILD=0 \ -DKOMPUTE_OPT_BUILD_TESTS=1 \ -DKOMPUTE_OPT_BUILD_DOCS=1 \ -DKOMPUTE_OPT_BUILD_SHADERS=1 \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dead02a4c..6161b782b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,13 +1,19 @@ if(KOMPUTE_OPT_ENABLE_SPDLOG) - find_package(spdlog REQUIRED) - find_package(fmt REQUIRED) + if(KOMPUTE_OPT_REPO_SUBMODULE_BUILD) + set(SPDLOG_INSTALL ON) + add_subdirectory(${PROJECT_SOURCE_DIR}/external/spdlog ${CMAKE_CURRENT_BINARY_DIR}/kompute_spdlog) + else() + find_package(spdlog REQUIRED) + endif() endif() if(KOMPUTE_OPT_ANDOID_BUILD) find_library(android android) endif() +# We don't import Vulkan library if Android build as its build dynamically +# Otherwise it is expected that the Vulkan SDK and dependencies are installed if(NOT KOMPUTE_OPT_ANDOID_BUILD) find_package(Vulkan REQUIRED) endif() @@ -62,10 +68,19 @@ else() ) endif() +if(KOMPUTE_OPT_REPO_SUBMODULE_BUILD) +# Override the default Vulkan::Vulkan headers +# In this case we only use the build interface due to https://github.com/KhronosGroup/Vulkan-Headers/issues/157 + add_subdirectory(${PROJECT_SOURCE_DIR}/external/Vulkan-Headers ${CMAKE_CURRENT_BINARY_DIR}/kompute_vulkan_headers) + get_target_property(VULKAN_HEADERS_INCLUDES Vulkan-Headers INTERFACE_INCLUDE_DIRECTORIES) + target_include_directories( + kompute PUBLIC + $) +endif() + if(KOMPUTE_OPT_ENABLE_SPDLOG) target_link_libraries( kompute - fmt::fmt spdlog::spdlog ) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 904e7b4f2..f6b04df96 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,11 @@ enable_testing() -find_package(GTest CONFIG REQUIRED) +if(KOMPUTE_OPT_REPO_SUBMODULE_BUILD) + add_subdirectory(${PROJECT_SOURCE_DIR}/external/googletest EXCLUDE_FROM_ALL + ${CMAKE_CURRENT_BINARY_DIR}/kompute_googletest) +else() + find_package(GTest CONFIG REQUIRED) +endif() file(GLOB test_kompute_CPP "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" @@ -14,9 +19,17 @@ target_include_directories( $ ) -target_link_libraries(test_kompute PRIVATE - GTest::gtest - GTest::gmock) +if(KOMPUTE_OPT_REPO_SUBMODULE_BUILD) + target_include_directories( + test_kompute PRIVATE + ${gtest_SOURCE_DIR}/include) + + target_link_libraries(test_kompute PRIVATE + gtest_main) +else() + target_link_libraries(test_kompute PRIVATE + GTest::gtest) +endif() target_link_libraries(test_kompute PRIVATE kompute) From 109d0350d090595271ad7989f178d47cf5085e15 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 1 Nov 2020 12:39:25 +0000 Subject: [PATCH 13/13] Added documentation for build system --- README.md | 63 ++-------------------- docs/index.rst | 1 + docs/overview/build-system.rst | 96 ++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 59 deletions(-) create mode 100644 docs/overview/build-system.rst diff --git a/README.md b/README.md index 9639a99fc..2ff7e0f9a 100644 --- a/README.md +++ b/README.md @@ -285,70 +285,15 @@ We are currently developing Vulkan Kompute not to hide the Vulkan SDK interface The build system provided uses `cmake`, which allows for cross platform builds. -### Build parameters (cmake) +The top level `Makefile` provides a set of optimized configurations for development as well as the docker image build, but you can start a build with the following command: -The recommended approach to build the project is as out-of-source build in the `build` folder. This project comes with a `Makefile` that provides a set of commands that help with developer workflows. You can see some of the commands if you want to add some of the more advanced commands. - -For a base build you just have to run: ``` -cmake -Bbuild + cmake -Bbuild ``` -This by default configures without any of the extra build tasks (such as building shaders) and compiles without the optional dependencies. The table below provides more detail. - -| Flag | Description | -|-------------------------------------------------------|--------------------------------------------------------------------------| -| -DCMAKE_INSTALL_PREFIX="build/src/CMakefiles/Export/" | Enables local installation (which won't require admin privileges) | -| -DCMAKE_TOOLCHAIN_FILE="..." | This is the path for your package manager if you use it such as vcpkg | -| -DKOMPUTE_OPT_BUILD_TESTS=1 | Enable if you wish to build and run the tests (must have deps installed. | -| -DKOMPUTE_OPT_BUILD_DOCS=1 | Enable if you wish to build the docs (must have docs deps installed) | -| -DKOMPUTE_OPT_BUILD_SINGLE_HEADER=1 | Option to build the single header file using "quom" utility | -| -DKOMPUTE_EXTRA_CXX_FLAGS="..." | Allows you to pass extra config flags to compiler | -| -DKOMPUTE_OPT_INSTALL=0 | Disables the install step in the cmake file (useful for android build) | -| -DKOMPUTE_OPT_ANDROID_BUILD=1 | Enables android build which includes and excludes relevant libraries | - -#### Compile Flags - - -| Flag | Description | -|--------------------------------------|-----------------------------------------------------------------------------------------| -| KOMPUTE_CREATE_PIPELINE_RESULT_VALUE | Ensure the return value of createPipeline is processed as ResultValue instead of Result | -| -DKOMPUTE_VK_API_VERSION="..." | Sets the default api version to use for vulkan kompute api | -| -DKOMPUTE_VK_API_MAJOR_VERSION=1 | Major version to use for the Vulkan API | -| -DKOMPUTE_VK_API_MINOR_VERSION=1 | Minor version to use for the Vulkan API | -| -DKOMPUTE_ENABLE_SPDLOG=1 | Enables the build with SPDLOG and FMT dependencies (must be installed) | -| -DKOMPUTE_LOG_VERRIDE=1 | Does not define the SPDLOG_ macros if these are to be overridden | -| -DSPDLOG_ACTIVE_LEVEL | The level for the log level on compile level (whether spdlog is enabled) | -| -DVVK_USE_PLATFORM_ANDROID_KHR | Flag to enable android imports in kompute (enabled with -DKOMPUTE_OPT_ANDROID_BUILD) | -| -DRELEASE=1 | Enable release build (enabled by cmake release build) | -| -DDEBUG=1 | Enable debug build including debug flags (enabled by cmake debug build) | -| -DKOMPUTE_DISABLE_VK_DEBUG_LAYERS | Disable the debug Vulkan layers, mainly used for android builds | - -### Dependencies - -Given Kompute is expected to be used across a broad range of architectures and hardware, it will be important to make sure we are able to minimise dependencies. - -#### Required dependencies - -The only required dependency in the build is Vulkan. More specifically, the header files vulkan.h and vulkan.hpp, which are both part of the Vulkan SDK. If you haven't installed the Vulkan SDK yet, you can [download it here](https://vulkan.lunarg.com/). - -#### Optional dependencies - -SPDLOG is the preferred logging library, however by default Vulkan Kompute runs without SPDLOG by overriding the macros. It also provides an easy way to override the macros if you prefer to bring your own logging framework. The macro override is the following: - -```c++ -#ifndef KOMPUTE_LOG_OVERRIDE // Use this if you want to define custom macro overrides -#if KOMPUTE_SPDLOG_ENABLED // Use this if you want to enable SPDLOG -#include -#endif //KOMPUTE_SPDLOG_ENABLED -// ... Otherwise it adds macros that use std::cout (and only print first element) -#endif // KOMPUTE_LOG_OVERRIDE -``` - -You can choose to build with or without SPDLOG by using the cmake flag `KOMPUTE_OPT_ENABLE_SPDLOG`. - -Finally, remember that you will still need to set both the compile time log level with `SPDLOG_ACTIVE_LEVEL`, and the runtime log level with `spdlog::set_level(spdlog::level::debug);`. +You also are able to add Kompute in your repo with `add_subdirectory` - the [Android example CMakeLists.txt file](https://github.com/EthicalML/vulkan-kompute/blob/7c8c0eeba2cdc098349fcd999102bb2cca1bf711/examples/android/android-simple/app/src/main/cpp/CMakeLists.txt#L3) shows how this would be done. +For a more advanced overview of the build configuration check out the [Build System Deep Dive](https://kompute.cc/overview/build-system.html) documentation. ## Kompute Development diff --git a/docs/index.rst b/docs/index.rst index 8f15a61e8..60d01f21b 100755 --- a/docs/index.rst +++ b/docs/index.rst @@ -15,6 +15,7 @@ Index Advanced Examples Asynchronous & Parallel Operations Memory Management Principles + Build System Deep Dive Converting GLSL/HLSL Shaders to C++ Headers Mobile App Integration (Android) Game Engine Integration (Godot Engine) diff --git a/docs/overview/build-system.rst b/docs/overview/build-system.rst new file mode 100644 index 000000000..dd4f8e8b9 --- /dev/null +++ b/docs/overview/build-system.rst @@ -0,0 +1,96 @@ + +Build System Deep Dive +====================== + +The recommended approach to build the project is as out-of-source build in the ``build`` folder. This project comes with a ``Makefile`` that provides a set of commands that help with developer workflows. You can see some of the commands if you want to add some of the more advanced commands. + +For a base build you just have to run: + +.. code-block:: + + cmake -Bbuild + +This by default configures without any of the extra build tasks (such as building shaders) and compiles without the optional dependencies. The table below provides more detail. + +.. list-table:: + :header-rows: 1 + + * - Flag + - Description + * - -DCMAKE_INSTALL_PREFIX="build/src/CMakefiles/Export/" + - Enables local installation (which won't require admin privileges) + * - -DCMAKE_TOOLCHAIN_FILE="..." + - This is the path for your package manager if you use it such as vcpkg + * - -DKOMPUTE_OPT_BUILD_TESTS=1 + - Enable if you wish to build and run the tests (must have deps installed. + * - -DKOMPUTE_OPT_BUILD_DOCS=1 + - Enable if you wish to build the docs (must have docs deps installed) + * - -DKOMPUTE_OPT_BUILD_SINGLE_HEADER=1 + - Option to build the single header file using "quom" utility + * - -DKOMPUTE_EXTRA_CXX_FLAGS="..." + - Allows you to pass extra config flags to compiler + * - -DKOMPUTE_OPT_INSTALL=0 + - Disables the install step in the cmake file (useful for android build) + * - -DKOMPUTE_OPT_ANDROID_BUILD=1 + - Enables android build which includes and excludes relevant libraries + + +Compile Flags +~~~~~~~~~~~~~ + +.. list-table:: + :header-rows: 1 + + * - Flag + - Description + * - KOMPUTE_CREATE_PIPELINE_RESULT_VALUE + - Ensure the return value of createPipeline is processed as ResultValue instead of Result + * - -DKOMPUTE_VK_API_VERSION="..." + - Sets the default api version to use for vulkan kompute api + * - -DKOMPUTE_VK_API_MAJOR_VERSION=1 + - Major version to use for the Vulkan API + * - -DKOMPUTE_VK_API_MINOR_VERSION=1 + - Minor version to use for the Vulkan API + * - -DKOMPUTE_ENABLE_SPDLOG=1 + - Enables the build with SPDLOG and FMT dependencies (must be installed) + * - -DKOMPUTE_LOG_VERRIDE=1 + - Does not define the SPDLOG_\ :raw-html-m2r:`` macros if these are to be overridden + * - -DSPDLOG_ACTIVE_LEVEL + - The level for the log level on compile level (whether spdlog is enabled) + * - -DVVK_USE_PLATFORM_ANDROID_KHR + - Flag to enable android imports in kompute (enabled with -DKOMPUTE_OPT_ANDROID_BUILD) + * - -DRELEASE=1 + - Enable release build (enabled by cmake release build) + * - -DDEBUG=1 + - Enable debug build including debug flags (enabled by cmake debug build) + * - -DKOMPUTE_DISABLE_VK_DEBUG_LAYERS + - Disable the debug Vulkan layers, mainly used for android builds + + +Dependencies +^^^^^^^^^^^^ + +Given Kompute is expected to be used across a broad range of architectures and hardware, it will be important to make sure we are able to minimise dependencies. + +Required dependencies +~~~~~~~~~~~~~~~~~~~~~ + +The only required dependency in the build is Vulkan. More specifically, the header files vulkan.h and vulkan.hpp, which are both part of the Vulkan SDK. If you haven't installed the Vulkan SDK yet, you can `download it here `_. + +Optional dependencies +~~~~~~~~~~~~~~~~~~~~~ + +SPDLOG is the preferred logging library, however by default Vulkan Kompute runs without SPDLOG by overriding the macros. It also provides an easy way to override the macros if you prefer to bring your own logging framework. The macro override is the following: + +.. code-block:: c++ + + #ifndef KOMPUTE_LOG_OVERRIDE // Use this if you want to define custom macro overrides + #if KOMPUTE_SPDLOG_ENABLED // Use this if you want to enable SPDLOG + #include + #endif //KOMPUTE_SPDLOG_ENABLED + // ... Otherwise it adds macros that use std::cout (and only print first element) + #endif // KOMPUTE_LOG_OVERRIDE + +You can choose to build with or without SPDLOG by using the cmake flag ``KOMPUTE_OPT_ENABLE_SPDLOG``. + +Finally, remember that you will still need to set both the compile time log level with ``SPDLOG_ACTIVE_LEVEL``\ , and the runtime log level with ``spdlog::set_level(spdlog::level::debug);``.