IVGCVSW-4596 Fix BufferManager's packet order
authorFinn Williams <Finn.Williams@arm.com>
Tue, 24 Mar 2020 13:46:22 +0000 (13:46 +0000)
committerfinn.williams <finn.williams@arm.com>
Tue, 24 Mar 2020 15:59:39 +0000 (15:59 +0000)
Signed-off-by: Finn Williams <Finn.Williams@arm.com>
Change-Id: I35e0a891cd69f2c130b8886460089c441d8e666d

src/armnn/test/RuntimeTests.cpp
src/profiling/BufferManager.cpp
src/profiling/BufferManager.hpp
src/profiling/test/ProfilingTestUtils.cpp

index d5bc26a72e15037582fd4dd3ca7acbe6595dd9f3..eca4bf8b135a4da29f981c6c8f7a4d051815628f 100644 (file)
@@ -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();
index f5ab7292599f736e5d8e09f7cbb774b05c8b542f..a7b71e5fa1188fbc9d1a7dd1b40ed8235406717f 100644 (file)
@@ -45,7 +45,7 @@ void BufferManager::Commit(IPacketBufferPtr& packetBuffer, unsigned int size, bo
     std::unique_lock<std::mutex> 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<PacketBuffer>(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<std::mutex> availableListLock(m_AvailableMutex);
 
     m_AvailableList.clear();
-    m_ReadableList.clear();
+    std::queue<IPacketBufferPtr>().swap(m_ReadableList);
 
     Initialize();
 }
@@ -91,8 +90,8 @@ IPacketBufferPtr BufferManager::GetReadableBuffer()
     std::unique_lock<std::mutex> 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;
     }
index d678cd3ec06107f0330505c41473bf78bd01d16c..f4e63dab11fb0acd50cacf4123555877f3228ff3 100644 (file)
@@ -11,6 +11,7 @@
 #include <condition_variable>
 #include <mutex>
 #include <vector>
+#include <queue>
 
 namespace armnn
 {
@@ -56,7 +57,7 @@ private:
     std::vector<IPacketBufferPtr> m_AvailableList;
 
     // List of readable packet buffers
-    std::vector<IPacketBufferPtr> m_ReadableList;
+    std::queue<IPacketBufferPtr> m_ReadableList;
 
     // Mutex for available packet buffer list
     std::mutex m_AvailableMutex;
index 325cb401110058569c61d5076516363c2d962a02..74e140c0930058041892fe633c9f33e7f8b8d080 100644 (file)
@@ -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();