ArmNN  NotReleased
BufferManager.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include "IBufferManager.hpp"
9 #include "IConsumer.hpp"
10 
11 #include <condition_variable>
12 #include <mutex>
13 #include <vector>
14 
15 namespace armnn
16 {
17 
18 namespace profiling
19 {
20 
22 {
23 public:
24  BufferManager(unsigned int numberOfBuffers = 5, unsigned int maxPacketSize = 4096);
25 
27 
28  IPacketBufferPtr Reserve(unsigned int requestedSize, unsigned int& reservedSize) override;
29 
30  void Reset();
31 
32  void Commit(IPacketBufferPtr& packetBuffer, unsigned int size, bool notifyConsumer = true) override;
33 
34  void Release(IPacketBufferPtr& packetBuffer) override;
35 
37 
38  void MarkRead(IPacketBufferPtr& packetBuffer) override;
39 
42  void SetConsumer(IConsumer* consumer) override;
43 
45  void FlushReadList() override;
46 
47 private:
48  void Initialize();
49 
50  // Maximum buffer size
51  unsigned int m_MaxBufferSize;
52  // Number of buffers
53  unsigned int m_NumberOfBuffers;
54 
55  // List of available packet buffers
56  std::vector<IPacketBufferPtr> m_AvailableList;
57 
58  // List of readable packet buffers
59  std::vector<IPacketBufferPtr> m_ReadableList;
60 
61  // Mutex for available packet buffer list
62  std::mutex m_AvailableMutex;
63 
64  // Mutex for readable packet buffer list
65  std::mutex m_ReadableMutex;
66 
67  // Consumer thread to notify packet is ready to read
68  IConsumer* m_Consumer = nullptr;
69 };
70 
71 } // namespace profiling
72 
73 } // namespace armnn
IPacketBufferPtr Reserve(unsigned int requestedSize, unsigned int &reservedSize) override
std::unique_ptr< IPacketBuffer > IPacketBufferPtr
void Commit(IPacketBufferPtr &packetBuffer, unsigned int size, bool notifyConsumer=true) override
void SetConsumer(IConsumer *consumer) override
IPacketBufferPtr GetReadableBuffer() override
BufferManager(unsigned int numberOfBuffers=5, unsigned int maxPacketSize=4096)
void FlushReadList() override
Notify the Consumer buffer can be read.
void MarkRead(IPacketBufferPtr &packetBuffer) override
void Release(IPacketBufferPtr &packetBuffer) override