aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/PacketBuffer.cpp
blob: 88133d7674e2180ba6f2fa7e71c5164f7e00e910 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// Copyright © 2019 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "PacketBuffer.hpp"

#include <armnn/Exceptions.hpp>

namespace armnn
{

namespace profiling
{

PacketBuffer::PacketBuffer(unsigned int maxSize)
    : m_MaxSize(maxSize)
    , m_Size(0)
{
    m_Data = std::make_unique<unsigned char[]>(m_MaxSize);
}

const unsigned char* const PacketBuffer::GetReadableData() const
{
    return m_Data.get();
}

unsigned int PacketBuffer::GetSize() const
{
    return m_Size;
}

void PacketBuffer::MarkRead()
{
    m_Size = 0;
}

void PacketBuffer::Commit(unsigned int size)
{
    if (size > m_MaxSize)
    {
        throw armnn::RuntimeException("Cannot commit [" + std::to_string(size) +
                "] bytes which is more than the maximum size of the buffer [" + std::to_string(m_MaxSize) + "]");
    }
    m_Size = size;
}

void PacketBuffer::Release()
{
    m_Size = 0;
}

unsigned char* PacketBuffer::GetWritableData()
{
    return m_Data.get();
}

} // namespace profiling

} // namespace armnn