From bbc41aef1299f48b1528e1a72c996886f73fa191 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Mon, 24 Aug 2020 07:52:06 +0100 Subject: [PATCH] Added CMakeLists as build framework --- .gitignore | 20 +++++++++++ CMakeLists.txt | 35 +++++++++++++++++++ Makefile => MakefileKompute | 27 ++++++++++++-- README.md | 6 ++-- src/main.cpp | 14 ++++---- {external => src}/shaders/computeheadless.hpp | 0 {external => src}/shaders/machinelearning.hpp | 0 {external => src}/shaders/opmult.hpp | 0 test/Main.cpp | 4 +++ test/ManagerTest.cpp | 8 ----- test/TestTensor.cpp | 25 +++++++++++++ 11 files changed, 120 insertions(+), 19 deletions(-) create mode 100644 CMakeLists.txt rename Makefile => MakefileKompute (76%) mode change 100644 => 100755 mode change 100644 => 100755 src/main.cpp rename {external => src}/shaders/computeheadless.hpp (100%) rename {external => src}/shaders/machinelearning.hpp (100%) rename {external => src}/shaders/opmult.hpp (100%) create mode 100644 test/Main.cpp delete mode 100644 test/ManagerTest.cpp create mode 100644 test/TestTensor.cpp diff --git a/.gitignore b/.gitignore index 4830267d1..db2a13fa1 100644 --- a/.gitignore +++ b/.gitignore @@ -176,3 +176,23 @@ bin/ external/boost/ tmp/ +# CMake +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles/ +CMakeScripts +Testing +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +Makefile +*.vcxproj +*.vcxproj.filters +*.vcxproj.user +Win32/ +Debug/ + + diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..6749925e6 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.18.0) +project(kompute VERSION 0.1.0) + +set(CMAKE_CXX_STANDARD 17) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +find_package(fmt REQUIRED) +find_package(spdlog REQUIRED) +find_package(Vulkan REQUIRED) + +file(GLOB kompute_SRC + "${CMAKE_CURRENT_LIST_DIR}/src/*.hpp" + "${CMAKE_CURRENT_LIST_DIR}/src/*.cpp" + "${CMAKE_CURRENT_LIST_DIR}/src/shaders/*.hpp" + "${CMAKE_CURRENT_LIST_DIR}/src/shaders/*.cpp" +) + +add_executable(kompute + ${kompute_SRC}) + +target_include_directories( + kompute PUBLIC + fmt + spdlog + Vulkan +) + +target_link_libraries( + kompute + fmt::fmt + spdlog::spdlog + Vulkan::Vulkan +) + diff --git a/Makefile b/MakefileKompute old mode 100644 new mode 100755 similarity index 76% rename from Makefile rename to MakefileKompute index e472944c4..6d9c9463a --- a/Makefile +++ b/MakefileKompute @@ -9,17 +9,25 @@ CF=~/Programming/lib/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang-f SCMP=/c/VulkanSDK/1.2.141.2/Bin32/glslangValidator.exe +####### Package manager ####### + +VCPKG=/c/Users/axsau/Programming/lib/vcpkg/vcpkg ####### Main Target Rules ####### +run_cmake: + cmake \ + -DCMAKE_TOOLCHAIN_FILE=C:\\Users\\axsau\\Programming\\lib\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=1 + build: clean build_shaders $(CC) \ src/* \ -w \ -std=c++17 \ -DDEBUG=1 \ + -DRELEASE=1 \ -I"./external/" \ - -I"C:\\VulkanSDK\\1.2.141.2\\Include\\" \ -L"C:\\VulkanSDK\\1.2.141.2\\Lib\\" \ -lvulkan-1 \ -o ./bin/main.exe @@ -30,6 +38,21 @@ build: clean build_shaders #-g -fexceptions -fPIC \ #-static-libgcc -static-libstdc++ \ +run_test: + $(CC) \ + test/* \ + -Wall \ + -std=c++17 \ + -DDEBUG=1 \ + -DRELEASE=1 \ + -I"./external/" \ + -I"./src/" \ + -L"C:\\VulkanSDK\\1.2.141.2\\Lib\\" \ + -lvulkan-1 \ + -o ./bin/test.exe && \ + ./bin/test.exe --success + + build_linux: g++ \ -g -shared-libgcc \ @@ -45,7 +68,7 @@ build_shaders: python scripts/convert_shaders.py \ --shader-path shaders/glsl \ --shader-binary $(SCMP) \ - --header-path external/shaders \ + --header-path src/shaders \ -v docker_seldon_run: diff --git a/README.md b/README.md index f019ad754..04d77c6d3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Principles -* Single header easy to import library to boost your Vulkan compute experience +* Single header easy to import library to boost your Vulkan compute experience (WIP) * Non-vulkan naming convention to disambiguate Vulkan vs Kompute components * Extends the existing vulkan API with a simpler compute-specific interface * BYOV: Play nice with existing Vulkan applications with a bring-your-own-Vulkan design @@ -92,4 +92,6 @@ int main() { ## Development -Follows Mozilla C++ Style Guide https://www-archive.mozilla.org/hacking/mozilla-style-guide.html +* Follows Mozilla C++ Style Guide https://www-archive.mozilla.org/hacking/mozilla-style-guide.html + + Uses post-commit hook to run the linter, you can set it up so it runs the linter before commit +* Uses vcpkg for finding the dependencies, it's the recommanded set up to retrieve the libraries diff --git a/src/main.cpp b/src/main.cpp old mode 100644 new mode 100755 index e23e1929c..e5f74d6c5 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,7 +11,7 @@ #include // ranges.h must come after spdlog.h -#include +#include #include #include @@ -39,18 +39,18 @@ main() kp::Manager mgr; spdlog::info("Creating first tensor"); - std::shared_ptr tensorLHS{ new kp::Tensor( { 0.0, 1.0, 2.0 }) }; + std::shared_ptr tensorLHS{ new kp::Tensor( { 0, 1, 2 }) }; mgr.evalOp({ tensorLHS }); spdlog::info("Creating second tensor"); std::shared_ptr tensorRHS{ new kp::Tensor( - { 2.0, 4.0, 6.0 }) }; + { 2, 4, 6 }) }; mgr.evalOp({ tensorRHS }); // TODO: Add capabilities for just output tensor types spdlog::info("Creating output tensor"); std::shared_ptr tensorOutput{ new kp::Tensor( - { 0.0, 0.0, 0.0 }) }; + { 0, 0, 0 }) }; mgr.evalOp({ tensorOutput }); spdlog::info("OpCreateTensor success for tensors"); @@ -74,16 +74,16 @@ main() spdlog::info("Creating first tensor"); std::shared_ptr tensorLHS{ new kp::Tensor( - { 0.0, 1.0, 2.0 }) }; + { 0, 1, 2 }) }; spdlog::info("Creating second tensor"); std::shared_ptr tensorRHS{ new kp::Tensor( - { 2.0, 4.0, 6.0 }) }; + { 2, 4, 6 }) }; // TODO: Add capabilities for just output tensor types spdlog::info("Creating output tensor"); std::shared_ptr tensorOutput{ new kp::Tensor( - { 0.0, 0.0, 0.0 }) }; + { 0, 0, 0 }) }; sq.record({ tensorLHS }); sq.record({ tensorRHS }); diff --git a/external/shaders/computeheadless.hpp b/src/shaders/computeheadless.hpp similarity index 100% rename from external/shaders/computeheadless.hpp rename to src/shaders/computeheadless.hpp diff --git a/external/shaders/machinelearning.hpp b/src/shaders/machinelearning.hpp similarity index 100% rename from external/shaders/machinelearning.hpp rename to src/shaders/machinelearning.hpp diff --git a/external/shaders/opmult.hpp b/src/shaders/opmult.hpp similarity index 100% rename from external/shaders/opmult.hpp rename to src/shaders/opmult.hpp diff --git a/test/Main.cpp b/test/Main.cpp new file mode 100644 index 000000000..6ba5b1ed6 --- /dev/null +++ b/test/Main.cpp @@ -0,0 +1,4 @@ +#define CATCH_CONFIG_MAIN + +#include "catch2/catch.hpp" + diff --git a/test/ManagerTest.cpp b/test/ManagerTest.cpp deleted file mode 100644 index b869aa043..000000000 --- a/test/ManagerTest.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "gtest/gtest.h" - -#include "../src/Manager.hpp" - -TEST(ManagerTest, ManagerEmptyInitTest) { - kp::Manager mgr; - mgr.~Manager(); -} diff --git a/test/TestTensor.cpp b/test/TestTensor.cpp new file mode 100644 index 000000000..d471593cc --- /dev/null +++ b/test/TestTensor.cpp @@ -0,0 +1,25 @@ +#include + +#include "Tensor.hpp" + + +int Factorial( int number ) { + return number <= 1 ? number : Factorial( number - 1 ) * number; // fail +// return number <= 1 ? 1 : Factorial( number - 1 ) * number; // pass +} + +TEST_CASE( "Factorial of 0 is 1 (fail)", "[single-file]" ) { + REQUIRE( Factorial(0) == 1 ); +} + +TEST_CASE( "Factorials of 1 and higher are computed (pass)", "[single-file]" ) { + REQUIRE( Factorial(1) == 1 ); + REQUIRE( Factorial(2) == 2 ); + REQUIRE( Factorial(3) == 6 ); + REQUIRE( Factorial(10) == 3628800 ); +} + +TEST_CASE("Exploring if manager test compiles") { + kp::Tensor tensor({0,1,2}); + REQUIRE( tensor.size() == 3 ); +}