diff --git a/README.md b/README.md index 22c846be5..2e6f19a0e 100644 --- a/README.md +++ b/README.md @@ -64,14 +64,12 @@ int main() { auto tensorRhs = std::make_shared(kp::Tensor({ 2., 4., 6. })); auto tensorOut = std::make_shared(kp::Tensor({ 0., 0., 0. })); - // Create tensor data in GPU + // Create tensors data in GPU mgr.evalOpDefault({ tensorLhs, tensorRhs, tensorOut }); // Run Kompute operation on the parameters provided with dispatch layout mgr.evalOpDefault>( - { tensorLhs, tensorRhs, tensorOut }, - true, // Whether to retrieve the output from GPU memory - std::vector(shader.begin(), shader.end())); + { tensorLhs, tensorRhs, tensorOut }); // Prints the output which is { 0, 4, 12 } std::cout << fmt::format("Output: {}", tensorOutput.data()) << std::endl; @@ -89,17 +87,20 @@ int main() { auto tensorRhs = std::make_shared(kp::Tensor({ 2, 4, 6 })); // Define your shader as a string, or directly pass the compiled bytes - std::string shader( - "#version 450\n" - "layout (local_size_x = 1) in;\n" - "layout(set = 0, binding = 0) buffer bufa { uint a[]; };\n" - "layout(set = 0, binding = 1) buffer bufb { uint b[]; };\n" - "void main() {\n" - " uint index = gl_GlobalInvocationID.x;\n" - " b[index] = a[index];\n" - " a[index] = index;\n" - "}\n" - ); + std::string shader(R"( + #version 450 + + layout (local_size_x = 1) in; + + layout(set = 0, binding = 0) buffer a { float pa[]; }; + layout(set = 0, binding = 1) buffer b { float pb[]; }; + + void main() { + uint index = gl_GlobalInvocationID.x; + pb[index] = pa[index]; + pa[index] = index; + } + )"); // Create tensor data in GPU mgr.evalOpDefault({ tensorA, tensorB }); diff --git a/single_include/kompute/Kompute.hpp b/single_include/kompute/Kompute.hpp index 6015009f5..6a5ee7698 100755 --- a/single_include/kompute/Kompute.hpp +++ b/single_include/kompute/Kompute.hpp @@ -4,10 +4,10 @@ // SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import #if !defined(SPDLOG_ACTIVE_LEVEL) -#if RELEASE -#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO -#else +#if DEBUG #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG +#else +#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO #endif #endif @@ -1137,7 +1137,7 @@ OpAlgoBase::record() if (this->mCopyOutputData) { // Barrier to ensure the shader code is executed before buffer read - for (std::shared_ptr tensor : this->mTensors) { + for (const std::shared_ptr& tensor : this->mTensors) { tensor->recordBufferMemoryBarrier( vk::AccessFlagBits::eShaderWrite, vk::AccessFlagBits::eTransferRead, diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8367bedfe..e9f13ee03 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,7 +44,6 @@ add_dependencies(kompute build_shaders build_single_header) - add_library(kompute::kompute ALIAS kompute) diff --git a/src/include/kompute/operations/OpAlgoBase.hpp b/src/include/kompute/operations/OpAlgoBase.hpp index 9242d766d..9709e146b 100644 --- a/src/include/kompute/operations/OpAlgoBase.hpp +++ b/src/include/kompute/operations/OpAlgoBase.hpp @@ -293,7 +293,7 @@ OpAlgoBase::record() if (this->mCopyOutputData) { // Barrier to ensure the shader code is executed before buffer read - for (std::shared_ptr tensor : this->mTensors) { + for (const std::shared_ptr& tensor : this->mTensors) { tensor->recordBufferMemoryBarrier( vk::AccessFlagBits::eShaderWrite, vk::AccessFlagBits::eTransferRead, diff --git a/test/TestLogisticRegression.cpp b/test/TestLogisticRegression.cpp index 4a5991556..8404ced19 100644 --- a/test/TestLogisticRegression.cpp +++ b/test/TestLogisticRegression.cpp @@ -71,6 +71,7 @@ TEST(LogisticRegressionAlgorithm, TestMainLogisticRegression) { // * wi < 0.01 // * wj > 1.0 // * b < 0 + // TODO: Add EXPECT_DOUBLE_EQ instead EXPECT_LT(wIn->data()[0], 0.01); EXPECT_GT(wIn->data()[1], 1.0); EXPECT_LT(bIn->data()[0], 0.0); diff --git a/test/TestMain.cpp b/test/TestMain.cpp index dbc580759..07370c417 100644 --- a/test/TestMain.cpp +++ b/test/TestMain.cpp @@ -9,7 +9,6 @@ int main(int argc, char *argv[]) { #if KOMPUTE_ENABLE_SPDLOG spdlog::set_level(static_cast(SPDLOG_ACTIVE_LEVEL)); - spdlog::error("default active level {}", SPDLOG_ACTIVE_LEVEL); #endif return RUN_ALL_TESTS(); diff --git a/test/TestOpShadersFromStringAndFile.cpp b/test/TestOpShadersFromStringAndFile.cpp index 39a235bb3..06772cf15 100644 --- a/test/TestOpShadersFromStringAndFile.cpp +++ b/test/TestOpShadersFromStringAndFile.cpp @@ -12,17 +12,17 @@ TEST(TestOpAlgoBase, ShaderRawDataFromConstructor) { std::shared_ptr tensorB{ new kp::Tensor({ 0, 0, 0 })}; mgr.evalOpDefault({ tensorA, tensorB }); - std::string shader( - "#version 450\n" - "layout (local_size_x = 1) in;\n" - "layout(set = 0, binding = 0) buffer a { float pa[]; };\n" - "layout(set = 0, binding = 1) buffer b { float pb[]; };\n" - "void main() {\n" - " uint index = gl_GlobalInvocationID.x;\n" - " pb[index] = pa[index];\n" - " pa[index] = index;\n" - "}\n" - ); + std::string shader(R"( + #version 450 + layout (local_size_x = 1) in; + layout(set = 0, binding = 0) buffer a { float pa[]; }; + layout(set = 0, binding = 1) buffer b { float pb[]; }; + void main() { + uint index = gl_GlobalInvocationID.x; + pb[index] = pa[index]; + pa[index] = index; + } + )"); mgr.evalOpDefault>( { tensorA, tensorB }, diff --git a/vcpkg.json.opt b/vcpkg.json.opt index 40ac04d27..ccc585b21 100644 --- a/vcpkg.json.opt +++ b/vcpkg.json.opt @@ -4,6 +4,7 @@ "dependencies": [ "spdlog", "vulkan", + "vulkan-hpp", "gtest" ] }