From b6a402f46231688f7684dcb8c8e4ef5f4579b011 Mon Sep 17 00:00:00 2001 From: Finn Williams Date: Tue, 24 Mar 2020 13:46:22 +0000 Subject: [PATCH] IVGCVSW-4596 Fix BufferManager's packet order Signed-off-by: Finn Williams Change-Id: I35e0a891cd69f2c130b8886460089c441d8e666d --- src/armnn/test/RuntimeTests.cpp | 12 ++++++------ src/profiling/BufferManager.cpp | 9 ++++----- src/profiling/BufferManager.hpp | 3 ++- src/profiling/test/ProfilingTestUtils.cpp | 12 ++++++------ 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/armnn/test/RuntimeTests.cpp b/src/armnn/test/RuntimeTests.cpp index d5bc26a72..eca4bf8b1 100644 --- a/src/armnn/test/RuntimeTests.cpp +++ b/src/armnn/test/RuntimeTests.cpp @@ -692,17 +692,17 @@ BOOST_AUTO_TEST_CASE(ProfilingEnableCpuRef) // Does the inference. runtime.EnqueueWorkload(netId, inputTensors, outputTensors); - // Get readable buffer for inference timeline - auto inferenceReadableBuffer = bufferManager.GetReadableBuffer(); - BOOST_CHECK(inferenceReadableBuffer != nullptr); + // Get readable buffer for input workload + auto inputReadableBuffer = bufferManager.GetReadableBuffer(); + BOOST_CHECK(inputReadableBuffer != nullptr); // Get readable buffer for output workload auto outputReadableBuffer = bufferManager.GetReadableBuffer(); BOOST_CHECK(outputReadableBuffer != nullptr); - // Get readable buffer for input workload - auto inputReadableBuffer = bufferManager.GetReadableBuffer(); - BOOST_CHECK(inputReadableBuffer != nullptr); + // Get readable buffer for inference timeline + auto inferenceReadableBuffer = bufferManager.GetReadableBuffer(); + BOOST_CHECK(inferenceReadableBuffer != nullptr); // Validate input workload data size = inputReadableBuffer->GetSize(); diff --git a/src/profiling/BufferManager.cpp b/src/profiling/BufferManager.cpp index f5ab72925..a7b71e5fa 100644 --- a/src/profiling/BufferManager.cpp +++ b/src/profiling/BufferManager.cpp @@ -45,7 +45,7 @@ void BufferManager::Commit(IPacketBufferPtr& packetBuffer, unsigned int size, bo std::unique_lock readableListLock(m_ReadableMutex, std::defer_lock); packetBuffer->Commit(size); readableListLock.lock(); - m_ReadableList.push_back(std::move(packetBuffer)); + m_ReadableList.push(std::move(packetBuffer)); readableListLock.unlock(); if (notifyConsumer) @@ -62,7 +62,6 @@ void BufferManager::Initialize() IPacketBufferPtr buffer = std::make_unique(m_MaxBufferSize); m_AvailableList.emplace_back(std::move(buffer)); } - m_ReadableList.reserve(m_NumberOfBuffers); } void BufferManager::Release(IPacketBufferPtr& packetBuffer) @@ -81,7 +80,7 @@ void BufferManager::Reset() std::lock_guard availableListLock(m_AvailableMutex); m_AvailableList.clear(); - m_ReadableList.clear(); + std::queue().swap(m_ReadableList); Initialize(); } @@ -91,8 +90,8 @@ IPacketBufferPtr BufferManager::GetReadableBuffer() std::unique_lock readableListLock(m_ReadableMutex); if (!m_ReadableList.empty()) { - IPacketBufferPtr buffer = std::move(m_ReadableList.back()); - m_ReadableList.pop_back(); + IPacketBufferPtr buffer = std::move(m_ReadableList.front()); + m_ReadableList.pop(); readableListLock.unlock(); return buffer; } diff --git a/src/profiling/BufferManager.hpp b/src/profiling/BufferManager.hpp index d678cd3ec..f4e63dab1 100644 --- a/src/profiling/BufferManager.hpp +++ b/src/profiling/BufferManager.hpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace armnn { @@ -56,7 +57,7 @@ private: std::vector m_AvailableList; // List of readable packet buffers - std::vector m_ReadableList; + std::queue m_ReadableList; // Mutex for available packet buffer list std::mutex m_AvailableMutex; diff --git a/src/profiling/test/ProfilingTestUtils.cpp b/src/profiling/test/ProfilingTestUtils.cpp index 325cb4011..74e140c09 100644 --- a/src/profiling/test/ProfilingTestUtils.cpp +++ b/src/profiling/test/ProfilingTestUtils.cpp @@ -773,17 +773,17 @@ void VerifyPostOptimisationStructureTestImpl(armnn::BackendId backendId) // Does the inference. runtime.EnqueueWorkload(netId, inputTensors, outputTensors); - // Get readable buffer for inference timeline - auto inferenceReadableBuffer = bufferManager.GetReadableBuffer(); - BOOST_CHECK(inferenceReadableBuffer != nullptr); + // Get readable buffer for input workload + auto inputReadableBuffer = bufferManager.GetReadableBuffer(); + BOOST_CHECK(inputReadableBuffer != nullptr); // Get readable buffer for output workload auto outputReadableBuffer = bufferManager.GetReadableBuffer(); BOOST_CHECK(outputReadableBuffer != nullptr); - // Get readable buffer for input workload - auto inputReadableBuffer = bufferManager.GetReadableBuffer(); - BOOST_CHECK(inputReadableBuffer != nullptr); + // Get readable buffer for inference timeline + auto inferenceReadableBuffer = bufferManager.GetReadableBuffer(); + BOOST_CHECK(inferenceReadableBuffer != nullptr); // Validate input workload data size = inputReadableBuffer->GetSize(); -- 2.34.1