From f35a62ee9d19209ba535f89646c3143d8d869f54 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Wed, 24 Feb 2021 22:53:46 +0000 Subject: [PATCH] Updated core initial running test --- src/Algorithm.cpp | 13 ++++++++++++ src/Manager.cpp | 48 ++++++++++++++++++++++-------------------- test/CMakeLists.txt | 3 ++- test/TestWorkgroup.cpp | 41 ++++++++++++++++++------------------ 4 files changed, 60 insertions(+), 45 deletions(-) diff --git a/src/Algorithm.cpp b/src/Algorithm.cpp index 512e0e5aa..d9dda9dfa 100644 --- a/src/Algorithm.cpp +++ b/src/Algorithm.cpp @@ -37,6 +37,11 @@ Algorithm::rebuild( { KP_LOG_DEBUG("Kompute Algorithm rebuild started"); + this->mSpirv = spirv; + this->mWorkgroup = workgroup; + this->mSpecializationConstants = specializationConstants; + this->mPushConstants = pushConstants; + // Descriptor pool is created first so if available then destroy all before rebuild if (this->mFreeDescriptorPool) { this->freeMemoryDestroyGPUResources(); @@ -303,6 +308,8 @@ Algorithm::createPipeline() this->mFreePipeline = true; this->mPipeline = std::make_shared(pipelineResult); + + KP_LOG_DEBUG("Kompute Algorithm Create Pipeline Success"); } void @@ -313,6 +320,8 @@ Algorithm::recordDispatch(std::shared_ptr commandBuffer) commandBuffer->bindPipeline(vk::PipelineBindPoint::eCompute, *this->mPipeline); + KP_LOG_DEBUG("Kompute Algorithm pipeline bound"); + commandBuffer->bindDescriptorSets(vk::PipelineBindPoint::eCompute, *this->mPipelineLayout, 0, // First set @@ -320,7 +329,11 @@ Algorithm::recordDispatch(std::shared_ptr commandBuffer) nullptr // Dispatcher ); + KP_LOG_DEBUG("Kompute Algorithm descriptor sets bound"); + commandBuffer->dispatch(this->mWorkgroup[0], this->mWorkgroup[1], this->mWorkgroup[2]); + + KP_LOG_DEBUG("Kompute Algorithm dispatch success"); } void diff --git a/src/Manager.cpp b/src/Manager.cpp index ba0249f1d..9b12bdf53 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -119,24 +119,6 @@ Manager::~Manager() } } -std::shared_ptr -Manager::sequence(uint32_t queueIndex) -{ - KP_LOG_DEBUG("Kompute Manager sequence() with sequenceName: {} " - "and queueIndex: {}", - queueIndex); - - std::shared_ptr sq = - std::make_shared(this->mPhysicalDevice, - this->mDevice, - this->mComputeQueues[queueIndex], - this->mComputeQueueFamilyIndices[queueIndex]); - - this->mManagedSequences.push_back(sq); - - return sq; -} - void Manager::createInstance() { @@ -334,13 +316,15 @@ Manager::tensor( { KP_LOG_DEBUG("Kompute Manager tensor creation triggered"); - std::shared_ptr tensor = std::make_shared( - kp::Tensor(this->mPhysicalDevice, this->mDevice, data, tensorType)); + std::shared_ptr tensor{ + new kp::Tensor(this->mPhysicalDevice, this->mDevice, data, tensorType) }; this->mManagedTensors.push_back(tensor); return tensor; } + + std::shared_ptr Manager::algorithm( const std::vector>& tensors, @@ -351,18 +335,36 @@ Manager::algorithm( KP_LOG_DEBUG("Kompute Manager algorithm creation triggered"); - std::shared_ptr algorithm = std::make_shared( - kp::Algorithm( + std::shared_ptr algorithm{ + new kp::Algorithm( this->mDevice, tensors, spirv, workgroup, specializationConstants, - pushConstants)); + pushConstants)}; this->mManagedAlgorithms.push_back(algorithm); return algorithm; } +std::shared_ptr +Manager::sequence(uint32_t queueIndex) +{ + KP_LOG_DEBUG("Kompute Manager sequence() with sequenceName: {} " + "and queueIndex: {}", + queueIndex); + + std::shared_ptr sq{ + new kp::Sequence(this->mPhysicalDevice, + this->mDevice, + this->mComputeQueues[queueIndex], + this->mComputeQueueFamilyIndices[queueIndex]) }; + + this->mManagedSequences.push_back(sq); + + return sq; +} + } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a30792aad..3102ec648 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,7 +11,8 @@ else() endif() file(GLOB test_kompute_CPP - "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/TestMain.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/TestWorkgroup.cpp" ) add_executable(test_kompute ${test_kompute_CPP}) diff --git a/test/TestWorkgroup.cpp b/test/TestWorkgroup.cpp index 015874546..3b5942f70 100644 --- a/test/TestWorkgroup.cpp +++ b/test/TestWorkgroup.cpp @@ -8,41 +8,40 @@ TEST(TestWorkgroup, TestSimpleWorkgroup) { - std::shared_ptr tensorA{ new kp::Tensor(std::vector(16 * 8)) }; - std::shared_ptr tensorB{ new kp::Tensor(std::vector(16 * 8)) }; - { std::shared_ptr sq = nullptr; { kp::Manager mgr; - mgr.rebuild({ tensorA, tensorB }); + std::shared_ptr tensorA = mgr.tensor(std::vector(16 * 8)); + std::shared_ptr tensorB = mgr.tensor(std::vector(16 * 8)); + + std::vector> params = {tensorA, tensorB}; + + std::vector spirv( + (uint32_t*)kp::shader_data::test_shaders_glsl_test_workgroup_comp_spv, + (uint32_t*)(kp::shader_data::test_shaders_glsl_test_workgroup_comp_spv + + kp::shader_data::test_shaders_glsl_test_workgroup_comp_spv_len)); kp::Workgroup workgroup = {16, 8, 1}; - sq = mgr.sequence(); - sq->begin(); - sq->record( - { tensorA, tensorB }, - std::vector( - (uint32_t*)kp::shader_data::test_shaders_glsl_test_workgroup_comp_spv, - (uint32_t*)(kp::shader_data::test_shaders_glsl_test_workgroup_comp_spv + - kp::shader_data::test_shaders_glsl_test_workgroup_comp_spv_len)), - workgroup); - sq->end(); + std::shared_ptr algorithm = mgr.algorithm(params, spirv, workgroup); + sq = mgr.sequence(); + sq->record(std::make_shared(params)); + sq->record(std::make_shared(params, algorithm)); + sq->record(std::make_shared(params)); sq->eval(); - mgr.evalOpDefault({ tensorA, tensorB }); + std::vector expectedA = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15}; + + std::vector expectedB = { 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7 }; + + EXPECT_EQ(tensorA->data(), expectedA); + EXPECT_EQ(tensorB->data(), expectedB); } } - std::vector expectedA = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15}; - - std::vector expectedB = { 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7 }; - - EXPECT_EQ(tensorA->data(), expectedA); - EXPECT_EQ(tensorB->data(), expectedB); }