diff --git a/examples/array_multiplication/CMakeLists.txt b/examples/array_multiplication/CMakeLists.txt index 5aeebb450..63c58a842 100644 --- a/examples/array_multiplication/CMakeLists.txt +++ b/examples/array_multiplication/CMakeLists.txt @@ -3,6 +3,7 @@ project(kompute_array_mult VERSION 0.1.0) set(CMAKE_CXX_STANDARD 14) +option(KOMPUTE_ARR_OPT_INSTALLED_KOMPUTE "Enable if you prefer to use your installed Kompute library" 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") @@ -10,13 +11,30 @@ set(KOMPUTE_EXTRA_CXX_FLAGS "" CACHE STRING "Extra compile flags for Kompute, se set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG=1 ${KOMPUTE_EXTRA_CXX_FLAGS}") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DRELEASE=1 ${KOMPUTE_EXTRA_CXX_FLAGS}") -find_package(kompute REQUIRED) +if(KOMPUTE_ARR_OPT_INSTALLED_KOMPUTE) + find_package(kompute REQUIRED) +else() + add_subdirectory(../../ ${CMAKE_CURRENT_BINARY_DIR}/kompute_build) +endif() + find_package(Vulkan REQUIRED) +if(KOMPUTE_OPT_ENABLE_SPDLOG) + find_package(spdlog REQUIRED) +endif() + add_executable(kompute_array_mult src/Main.cpp) target_link_libraries(kompute_array_mult kompute::kompute - Vulkan::Vulkan -) + Vulkan::Vulkan) + +include_directories( + ../../single_include/) + +if(KOMPUTE_OPT_ENABLE_SPDLOG) + target_link_libraries(kompute_array_mult + spdlog::spdlog) +endif() + diff --git a/examples/array_multiplication/README.md b/examples/array_multiplication/README.md index 9838b7217..2a1ab8ae1 100644 --- a/examples/array_multiplication/README.md +++ b/examples/array_multiplication/README.md @@ -25,35 +25,12 @@ For the other libraries, because they are optional you can just make sure you bu 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 -``` - -You can pass the following optional parameters based on your desired configuration: -* 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. -* If you are using a package manager such as `vcpkg` make sure you pass the `-DCMAKE_TOOLCHAIN_FILE=` parameter - -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. +This project has the option to either import the Kompute dependency relative to the project or use your existing installation of Kompute. + To build you just need to run the cmake command in this folder as follows: ``` @@ -61,14 +38,9 @@ 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` +You can pass the following optional parameters based on your desired configuration: +* If you wish to install with spdlog support you just have to pass `-DKOMPUTE_OPT_ENABLE_SPDLOG=1`. * If you are using a package manager such as `vcpkg` make sure you pass the `-DCMAKE_TOOLCHAIN_FILE=` parameter +* If you wish to load shader from raw glsl string instead of spirv bytes you can use `-DKOMPUTE_ANDROID_SHADER_FROM_STRING` -Now you just have to build your application as above: - -* For Windows / Visual Studio you just have to build and run `kompute_array_mult.vcxproj` -* For Linux you can just run the `kompute_array_mult` target via `make -C build kompute_array_mult` diff --git a/examples/array_multiplication/src/Main.cpp b/examples/array_multiplication/src/Main.cpp index f3587cae8..14b58cba9 100755 --- a/examples/array_multiplication/src/Main.cpp +++ b/examples/array_multiplication/src/Main.cpp @@ -18,6 +18,7 @@ int main() auto tensorInB = mgr.buildTensor({ 0.0, 1.0, 2.0 }); auto tensorOut = mgr.buildTensor({ 0.0, 0.0, 0.0 }); +#ifdef KOMPUTE_ANDROID_SHADER_FROM_STRING std::string shader(R"( // The version to use #version 450 @@ -37,9 +38,17 @@ int main() } )"); - mgr.evalOpDefault>( + mgr.evalOpDefault( { tensorInA, tensorInB, tensorOut }, std::vector(shader.begin(), shader.end())); +#else + mgr.evalOpDefault( + { tensorInA, tensorInB, tensorOut }, + std::vector( + kp::shader_data::shaders_glsl_opmult_comp_spv, + kp::shader_data::shaders_glsl_opmult_comp_spv + + kp::shader_data::shaders_glsl_opmult_comp_spv_len)); +#endif mgr.evalOpDefault({tensorOut}); diff --git a/src/Manager.cpp b/src/Manager.cpp old mode 100644 new mode 100755