diff --git a/CMakeLists.txt b/CMakeLists.txt index c7337fd84..c70a56317 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,9 +7,11 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_VERBOSE_MAKEFILE on) # Enable or disable targets -option(KOMPUTE_OPT_BUILD_TESTS "Enable if you want to build tests" 1) -option(KOMPUTE_OPT_BUILD_DOCS "Enable if you want to build documentation" 1) -option(KOMPUTE_OPT_ENABLE_SPDLOG "Extra compile flags for Kompute, see docs for full list" 1) +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_ENABLE_SPDLOG "Extra compile flags for Kompute, see docs for full list" 0) set(KOMPUTE_EXTRA_CXX_FLAGS "" CACHE STRING "Extra compile flags for Kompute, see docs for full list") diff --git a/Makefile b/Makefile index 87e873fce..b1f6927ee 100755 --- a/Makefile +++ b/Makefile @@ -49,12 +49,10 @@ mk_cmake: cmake \ -Bbuild \ -DCMAKE_BUILD_TYPE=$(MK_BUILD_TYPE) \ - -DKOMPUTE_OPT_BUILD_DOCS=0 \ -DCMAKE_INSTALL_PREFIX=$(MK_INSTALL_PATH) \ -DCMAKE_TOOLCHAIN_FILE=$(VCPKG_UNIX_PATH) \ -DKOMPUTE_EXTRA_CXX_FLAGS=$(MK_KOMPUTE_EXTRA_CXX_FLAGS) \ $(MK_CMAKE_EXTRA_FLAGS) \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \ -G "Unix Makefiles" mk_build_all: @@ -88,12 +86,9 @@ vs_cmake: $(CMAKE_BIN) \ -Bbuild \ -DCMAKE_TOOLCHAIN_FILE=$(VCPKG_WIN_PATH) \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \ $(VS_CMAKE_EXTRA_FLAGS) \ -DKOMPUTE_EXTRA_CXX_FLAGS=$(VS_KOMPUTE_EXTRA_CXX_FLAGS) \ -DCMAKE_INSTALL_PREFIX=$(VS_INSTALL_PATH) \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - -DCMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD=ON \ -G "Visual Studio 16 2019" vs_build_all: diff --git a/examples/linear_regression/CMakeLists.txt b/examples/linear_regression/CMakeLists.txt index c76764042..c66fa6d3e 100644 --- a/examples/linear_regression/CMakeLists.txt +++ b/examples/linear_regression/CMakeLists.txt @@ -3,7 +3,7 @@ project(kompute_linear_reg VERSION 0.1.0) set(CMAKE_CXX_STANDARD 17) -option(KOMPUTE_OPT_ENABLE_SPDLOG "Extra compile flags for Kompute, see docs for full list" 1) +option(KOMPUTE_OPT_ENABLE_SPDLOG "Extra compile flags for Kompute, see docs for full list" 0) set(KOMPUTE_EXTRA_CXX_FLAGS "" CACHE STRING "Extra compile flags for Kompute, see docs for full list") if(KOMPUTE_OPT_ENABLE_SPDLOG) @@ -16,8 +16,11 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DRELEASE=1 ${KOMPUTE_EX find_package(kompute REQUIRED) find_package(Vulkan REQUIRED) -find_package(spdlog REQUIRED) -find_package(fmt REQUIRED) + +if(KOMPUTE_OPT_ENABLE_SPDLOG) + find_package(spdlog REQUIRED) + find_package(fmt REQUIRED) +endif() add_executable(kompute_linear_reg src/Main.cpp) @@ -25,7 +28,13 @@ add_executable(kompute_linear_reg target_link_libraries(kompute_linear_reg kompute::kompute Vulkan::Vulkan - fmt::fmt - spdlog::spdlog ) +if(KOMPUTE_OPT_ENABLE_SPDLOG) + target_link_libraries(kompute_linear_reg + kompute::kompute + fmt::fmt + spdlog::spdlog + ) +endif() + diff --git a/examples/linear_regression/README.md b/examples/linear_regression/README.md new file mode 100644 index 000000000..024beb8ae --- /dev/null +++ b/examples/linear_regression/README.md @@ -0,0 +1,72 @@ +# Kompute Logistic Regression Example + +This folder contains an end to end Kompute Example that implements logistic regression. + +This example is structured such that you will be able to extend it for your project. + +It contains a cmake build configuration that can be used in your production applications. + +## Pre-requisites + +In order to run this example, you will need the following dependencies: + +* REQUIRED + + Vulkan Kompute library must be accessible + + The Vulkan SDK must be installed +* OPTIONAL + + SPDLOG - for logging + + FMT - for text formatting + +We will cover how you can install Vulkan Kompute in the next section. + +For the Vulkan SDK, the simplest way to install it is through [their website](https://vulkan.lunarg.com/sdk/home). You just have to follow the instructions for the relevant platform. + +For the other libraries, because they are optional you can just make sure you build and install Kompute with these disabled (this will be covered in more detail below). + +Alternatively you can use package managers such as vcpkg to help you install them, although to simplify things you can start without the dependencies first. + +## Set Up Vulkan Kompute Dependency + +You have multiple options to set up Vulkan Kompute. The easiest is to perform a local installation. + +For this, you will want to go to the main repo and run the following cmake command, which will configure it without SPDLOG by default. + +``` +cmake \ + -Bbuild +``` + +If you wish to install with spdlog support you just have to pass `-DKOMPUTE_ENABLE_SPDLOG=1`. + +If you wish to perform the installation on the local folder instead of in your system you can use `-DCMAKE_INSTALL_PREFIX="build/src/CMakeFiles/Export/"` which will basically ensure that the final files are created in the local directory. + +Then you can proceed to run the installation: + +* For Windows / Visual Studio you just have to build `INSTALL.vcxproj` +* For Linux you can just run the `install` target via `make -C build install` + +You also have the option to build as `Release` or `Debug` - just make sure that you build your example with the same build/debug flags as required. + +## Building the example + +Now that you've set up the dependencies / installation of Vulkan Kompute you can build this example. + +You will notice that it's a standalone project, so you can re-use it for your application. + +To build you just need to run the cmake command in this folder as follows: + +``` +cmake \ + -Bbuild +``` + +Make sure to pass the required flags depending on the configuration above: +* If you built with Debug make sure you build your example with Debug as well +* If you installed in the local folder, make sure you pass the CMAKE_PREFIX_PATH pointing to the respective folder (e.g. `-DCMAKE_PREFIX_PATH=../../build/src/CMakeFiles/Export/lib/cmake/kompute/` if parent folder is main repo). +* If you built Vulkan Kompute with spdlog enabled, make sure to pass `-DKOMPUTE_OPT_ENABLE_SPDLOG=1` + +Now you just have to build your application as above: + +* For Windows / Visual Studio you just have to build and run `kompute_linear_reg.vcxproj` +* For Linux you can just run the `kompute_linear_reg` target via `make -C build kompute_linear_reg` + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 662deefe1..9b0c88185 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,12 +7,17 @@ endif() find_package(Vulkan REQUIRED) -# In production builds all shaders are compiled into cpp files -kompute_make(build_shaders - OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/include) -# In production builds all headers are compiled into a single header -kompute_make(build_single_header - OUTPUT ${PROJECT_SOURCE_DIR}/single_include) +if(KOMPUTE_OPT_BUILD_SHADERS) +# all shaders are compiled into cpp files + kompute_make(build_shaders + OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/include) +endif() + +if(KOMPUTE_OPT_BUILD_SINGLE_HEADER) +# all headers are compiled into a single header + kompute_make(build_single_header + OUTPUT ${PROJECT_SOURCE_DIR}/single_include) +endif() file(GLOB kompute_CPP "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" @@ -40,9 +45,15 @@ if(KOMPUTE_OPT_ENABLE_SPDLOG) ) endif() -add_dependencies(kompute - build_shaders - build_single_header) +if(KOMPUTE_OPT_BUILD_SHADERS) + add_dependencies(kompute + build_shaders) +endif() + +if(KOMPUTE_OPT_BUILD_SINGLE_HEADER) + add_dependencies(kompute + build_single_header) +endif() add_library(kompute::kompute ALIAS kompute)