diff --git a/Makefile b/Makefile index 8f39a254a..74a6822b0 100644 --- a/Makefile +++ b/Makefile @@ -57,7 +57,6 @@ MK_KOMPUTE_EXTRA_CXX_FLAGS ?= "" mk_cmake: cmake \ -Bbuild \ - $(MK_CMAKE_EXTRA_FLAGS) \ -DKOMPUTE_EXTRA_CXX_FLAGS=$(MK_KOMPUTE_EXTRA_CXX_FLAGS) \ -DCMAKE_BUILD_TYPE=$(MK_BUILD_TYPE) \ -DCMAKE_INSTALL_PREFIX=$(MK_INSTALL_PATH) \ @@ -69,6 +68,7 @@ mk_cmake: -DKOMPUTE_OPT_BUILD_SINGLE_HEADER=1 \ -DKOMPUTE_OPT_ENABLE_SPDLOG=1 \ -DKOMPUTE_OPT_CODE_COVERAGE=1 \ + $(MK_CMAKE_EXTRA_FLAGS) \ -G "Unix Makefiles" mk_build_all: diff --git a/src/Algorithm.cpp b/src/Algorithm.cpp index d9dda9dfa..6ebb08efe 100644 --- a/src/Algorithm.cpp +++ b/src/Algorithm.cpp @@ -15,8 +15,6 @@ Algorithm::Algorithm( KP_LOG_DEBUG("Kompute Algorithm Constructor with device"); this->mDevice = device; - this->setWorkgroup(workgroup); - this->mPushConstants = pushConstants; this->rebuild(tensors, spirv, workgroup, specializationConstants, pushConstants); } @@ -37,8 +35,8 @@ Algorithm::rebuild( { KP_LOG_DEBUG("Kompute Algorithm rebuild started"); + this->setWorkgroup(workgroup); this->mSpirv = spirv; - this->mWorkgroup = workgroup; this->mSpecializationConstants = specializationConstants; this->mPushConstants = pushConstants; @@ -300,14 +298,20 @@ Algorithm::createPipeline() throw std::runtime_error("Failed to create pipeline result: " + vk::to_string(pipelineResult.result)); } -#else - vk::Pipeline pipelineResult = - this->mDevice->createComputePipeline(*this->mPipelineCache, pipelineInfo); + + vk::Pipeline& pipeline = pipelineResult.value; + this->mPipeline = std::make_shared(pipeline); this->mFreePipeline = true; +#else + vk::Pipeline pipeline = + this->mDevice->createComputePipeline(*this->mPipelineCache, pipelineInfo); + this->mPipeline = std::make_shared(pipeline); #endif - this->mFreePipeline = true; - this->mPipeline = std::make_shared(pipelineResult); + // TODO: Update to consistent + // this->mPipeline = std::make_shared(); + // this->mDevice->createComputePipelines( + // *this->mPipelineCache, 1, &pipelineInfo, nullptr, this->mPipeline.get()); KP_LOG_DEBUG("Kompute Algorithm Create Pipeline Success"); } @@ -317,6 +321,20 @@ Algorithm::recordDispatch(std::shared_ptr commandBuffer) { KP_LOG_DEBUG("Kompute Algorithm calling record dispatch"); + if(this->mPipelineCache) { + KP_LOG_WARN("Value valid"); + } + else { + KP_LOG_WARN("NOT Value valid"); + } + + if(this->mPipeline) { + KP_LOG_WARN("Value valid"); + } + else { + KP_LOG_WARN("NOT Value valid"); + } + commandBuffer->bindPipeline(vk::PipelineBindPoint::eCompute, *this->mPipeline); @@ -338,6 +356,12 @@ Algorithm::recordDispatch(std::shared_ptr commandBuffer) void Algorithm::setWorkgroup(const Workgroup& workgroup, uint32_t minSize) { + + KP_LOG_INFO("Kompute OpAlgoCreate setting dispatch size X: {}, Y: {}, Z: {}", + this->mWorkgroup[0], + this->mWorkgroup[1], + this->mWorkgroup[2]); + // The dispatch size is set up based on either explicitly provided template // parameters or by default it would take the shape and size of the tensors if (workgroup[0] > 0) { @@ -351,10 +375,6 @@ Algorithm::setWorkgroup(const Workgroup& workgroup, uint32_t minSize) { } else { this->mWorkgroup = { minSize, 1, 1 }; } - KP_LOG_INFO("Kompute OpAlgoCreate dispatch size X: {}, Y: {}, Z: {}", - this->mWorkgroup[0], - this->mWorkgroup[1], - this->mWorkgroup[2]); } } diff --git a/src/Manager.cpp b/src/Manager.cpp index 9b12bdf53..04e3a7e8b 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -4,6 +4,8 @@ #include "kompute/Manager.hpp" +#include "kompute/operations/OpAlgoDispatch.hpp" + namespace kp { #if DEBUG @@ -76,7 +78,7 @@ Manager::~Manager() algorithm->freeMemoryDestroyGPUResources(); } } - this->mManagedTensors.clear(); + this->mManagedAlgorithms.clear(); } if (this->mManagedTensors.size()) { @@ -324,7 +326,6 @@ Manager::tensor( return tensor; } - std::shared_ptr Manager::algorithm( const std::vector>& tensors, @@ -352,8 +353,7 @@ Manager::algorithm( std::shared_ptr Manager::sequence(uint32_t queueIndex) { - KP_LOG_DEBUG("Kompute Manager sequence() with sequenceName: {} " - "and queueIndex: {}", + KP_LOG_DEBUG("Kompute Manager sequence() with queueIndex: {}", queueIndex); std::shared_ptr sq{ diff --git a/src/OpAlgoDispatch.cpp b/src/OpAlgoDispatch.cpp index 3623fcddd..b4ecdcf57 100644 --- a/src/OpAlgoDispatch.cpp +++ b/src/OpAlgoDispatch.cpp @@ -9,6 +9,8 @@ OpAlgoDispatch::OpAlgoDispatch(const std::vector>& tenso { KP_LOG_DEBUG("Kompute OpAlgoDispatch constructor"); + this->mTensors = tensors; + this->mAlgorithm = algorithm; } OpAlgoDispatch::~OpAlgoDispatch() diff --git a/src/Sequence.cpp b/src/Sequence.cpp index 20e441500..da8771cc3 100644 --- a/src/Sequence.cpp +++ b/src/Sequence.cpp @@ -40,11 +40,9 @@ Sequence::begin() throw std::runtime_error("Kompute Sequence begin called when sequence still running"); } - if (!this->mRecording) { - KP_LOG_INFO("Kompute Sequence command recording BEGIN"); - this->mCommandBuffer->begin(vk::CommandBufferBeginInfo()); - this->mRecording = true; - } + KP_LOG_INFO("Kompute Sequence command now started recording"); + this->mCommandBuffer->begin(vk::CommandBufferBeginInfo()); + this->mRecording = true; } void @@ -161,6 +159,10 @@ Sequence::freeMemoryDestroyGPUResources() } this->mDevice->freeCommandBuffers( *this->mCommandPool, 1, this->mCommandBuffer.get()); + + this->mCommandBuffer = nullptr; + this->mFreeCommandBuffer = false; + KP_LOG_DEBUG("Kompute Sequence Freed CommandBuffer"); } @@ -175,6 +177,10 @@ Sequence::freeMemoryDestroyGPUResources() this->mDevice->destroy( *this->mCommandPool, (vk::Optional)nullptr); + + this->mCommandPool = nullptr; + this->mFreeCommandPool = false; + KP_LOG_DEBUG("Kompute Sequence Destroyed CommandPool"); } @@ -194,6 +200,7 @@ Sequence::record(std::shared_ptr op) KP_LOG_DEBUG( "Kompute Sequence running record on OpBase derived class instance"); + op->record(this->mCommandBuffer); this->mOperations.push_back(op); diff --git a/src/Tensor.cpp b/src/Tensor.cpp index 1ae4662f8..3078acd8a 100644 --- a/src/Tensor.cpp +++ b/src/Tensor.cpp @@ -449,6 +449,7 @@ Tensor::freeMemoryDestroyGPUResources() *this->mPrimaryBuffer, (vk::Optional)nullptr); this->mPrimaryBuffer = nullptr; + this->mFreePrimaryBuffer = false; } } @@ -462,6 +463,7 @@ Tensor::freeMemoryDestroyGPUResources() *this->mStagingBuffer, (vk::Optional)nullptr); this->mStagingBuffer = nullptr; + this->mFreeStagingBuffer = false; } } @@ -475,6 +477,7 @@ Tensor::freeMemoryDestroyGPUResources() *this->mPrimaryMemory, (vk::Optional)nullptr); this->mPrimaryMemory = nullptr; + this->mFreePrimaryMemory = false; } } @@ -488,6 +491,7 @@ Tensor::freeMemoryDestroyGPUResources() *this->mStagingMemory, (vk::Optional)nullptr); this->mStagingMemory = nullptr; + this->mFreeStagingMemory = false; } } diff --git a/test/TestWorkgroup.cpp b/test/TestWorkgroup.cpp index 3b5942f70..73cbdce61 100644 --- a/test/TestWorkgroup.cpp +++ b/test/TestWorkgroup.cpp @@ -8,14 +8,16 @@ TEST(TestWorkgroup, TestSimpleWorkgroup) { + std::shared_ptr tensorA = nullptr; + std::shared_ptr tensorB = nullptr; { std::shared_ptr sq = nullptr; { kp::Manager mgr; - std::shared_ptr tensorA = mgr.tensor(std::vector(16 * 8)); - std::shared_ptr tensorB = mgr.tensor(std::vector(16 * 8)); + tensorA = mgr.tensor(std::vector(16 * 8)); + tensorB = mgr.tensor(std::vector(16 * 8)); std::vector> params = {tensorA, tensorB}; @@ -33,15 +35,14 @@ TEST(TestWorkgroup, TestSimpleWorkgroup) sq->record(std::make_shared(params, algorithm)); sq->record(std::make_shared(params)); sq->eval(); - - 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); }