From ba71c7ab462fe5a176839dc019b13951783a07ac Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 18 Oct 2020 16:04:35 +0100 Subject: [PATCH] Updated manager to have unique sequence added on default operations --- src/Manager.cpp | 12 +++++++++++- src/Sequence.cpp | 15 ++++++++++++--- src/include/kompute/Manager.hpp | 23 ++++++++++++----------- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/Manager.cpp b/src/Manager.cpp index b2739d6be..e306ad004 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -95,6 +95,7 @@ std::weak_ptr Manager::getOrCreateManagedSequence(std::string sequenceName) { SPDLOG_DEBUG("Kompute Manager creating Sequence object"); + std::unordered_map>::iterator found = this->mManagedSequences.find(sequenceName); @@ -120,7 +121,16 @@ Manager::createManagedSequence(std::string sequenceName, uint32_t queueIndex) this->mComputeQueues[queueIndex], this->mComputeQueueFamilyIndeces[queueIndex]); sq->init(); - this->mManagedSequences.insert({ sequenceName, sq }); + + if (sequenceName.empty()) { + this->mCurrentSequenceIndex++; + this->mManagedSequences.insert({ KP_DEFAULT_SESSION + std::to_string(this->mCurrentSequenceIndex), sq }); + } + else + { + // TODO: Check if sequence doens't already exist + this->mManagedSequences.insert({ sequenceName, sq }); + } return sq; } diff --git a/src/Sequence.cpp b/src/Sequence.cpp index a03a34afe..b286a2e44 100644 --- a/src/Sequence.cpp +++ b/src/Sequence.cpp @@ -75,10 +75,20 @@ Sequence::begin() return false; } + if (this->isRunning()) { + SPDLOG_WARN("Kompute Sequence begin called when sequence still running"); + return false; + } + if (!this->mCommandPool) { throw std::runtime_error("Kompute Sequence command pool is null"); } + if (this->mOperations.size()) { + SPDLOG_INFO("Kompute Sequence clearing previous operations"); + this->mOperations.clear(); + } + if (!this->mRecording) { SPDLOG_INFO("Kompute Sequence command recording BEGIN"); this->mCommandBuffer->begin(vk::CommandBufferBeginInfo()); @@ -177,9 +187,10 @@ Sequence::evalAwait(uint64_t waitFor) this->mDevice->waitForFences(1, &this->mFence, VK_TRUE, waitFor); this->mDevice->destroy(this->mFence); + this->mIsRunning = false; + if (result == vk::Result::eTimeout) { SPDLOG_WARN("Kompute Sequence evalAwait timed out"); - this->mIsRunning = false; return false; } @@ -187,8 +198,6 @@ Sequence::evalAwait(uint64_t waitFor) this->mOperations[i]->postEval(); } - this->mIsRunning = false; - return true; } diff --git a/src/include/kompute/Manager.hpp b/src/include/kompute/Manager.hpp index 969af9ac5..db67a3790 100644 --- a/src/include/kompute/Manager.hpp +++ b/src/include/kompute/Manager.hpp @@ -72,11 +72,11 @@ class Manager * Create a new managed Kompute sequence so it's available within the * manager. * - * @param sequenceName The name for the named sequence to be created + * @param sequenceName The name for the named sequence to be created, if empty then default indexed value is used * @param queueIndex The queue to use from the available queues * @return Weak pointer to the manager owned sequence resource */ - std::weak_ptr createManagedSequence(std::string sequenceName, + std::weak_ptr createManagedSequence(std::string sequenceName = "", uint32_t queueIndex = 0); /** @@ -113,7 +113,7 @@ class Manager } /** - * Function that evaluates operation against default sequence. + * Function that evaluates operation against a newly created sequence. * * @param tensors The tensors to be used in the operation recorded * @param TArgs Template parameters that will be used to initialise @@ -124,8 +124,9 @@ class Manager TArgs&&... params) { SPDLOG_DEBUG("Kompute Manager evalOp Default triggered"); + this->mCurrentSequenceIndex++; this->evalOp( - tensors, KP_DEFAULT_SESSION, std::forward(params)...); + tensors, KP_DEFAULT_SESSION + std::to_string(this->mCurrentSequenceIndex), std::forward(params)...); } /** @@ -142,14 +143,11 @@ class Manager TArgs&&... params) { SPDLOG_DEBUG("Kompute Manager evalOpAsync triggered"); + std::weak_ptr sqWeakPtr = this->getOrCreateManagedSequence(sequenceName); - std::unordered_map>::iterator - found = this->mManagedSequences.find(sequenceName); - - if (found != this->mManagedSequences.end()) { - std::shared_ptr sq = found->second; + if (std::shared_ptr sq = sqWeakPtr.lock()) { SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence BEGIN"); sq->begin(); @@ -181,8 +179,9 @@ class Manager TArgs&&... params) { SPDLOG_DEBUG("Kompute Manager evalOpAsyncDefault triggered"); + this->mCurrentSequenceIndex++; this->evalOpAsync( - tensors, KP_DEFAULT_SESSION, std::forward(params)...); + tensors, KP_DEFAULT_SESSION + std::to_string(this->mCurrentSequenceIndex), std::forward(params)...); } /** @@ -222,7 +221,7 @@ class Manager void evalOpAwaitDefault(uint64_t waitFor = UINT64_MAX) { SPDLOG_DEBUG("Kompute Manager evalOpAwaitDefault triggered"); - this->evalOpAwait(KP_DEFAULT_SESSION, waitFor); + this->evalOpAwait(KP_DEFAULT_SESSION + std::to_string(this->mCurrentSequenceIndex), waitFor); } /** @@ -266,6 +265,8 @@ class Manager std::vector mComputeQueueFamilyIndeces; std::vector> mComputeQueues; + uint32_t mCurrentSequenceIndex = -1; + #if DEBUG #ifndef KOMPUTE_DISABLE_VK_DEBUG_LAYERS vk::DebugReportCallbackEXT mDebugReportCallback;