blob: 23c3124bad6aa216020081a50b8aed563a216b15 [file] [log] [blame]
Nikhil Rajbc626052019-08-15 15:49:45 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
Matteo Martincighd0613b52019-10-09 16:47:04 +01005
Nikhil Rajbc626052019-08-15 15:49:45 +01006#pragma once
7
Aron Virginas-Tare898db92019-08-22 12:56:34 +01008#include <armnn/Exceptions.hpp>
Nikhil Rajbc626052019-08-15 15:49:45 +01009
Matteo Martincighd0613b52019-10-09 16:47:04 +010010#include <memory>
Nikhil Rajbc626052019-08-15 15:49:45 +010011
Aron Virginas-Tare898db92019-08-22 12:56:34 +010012namespace armnn
13{
14
15namespace profiling
16{
Nikhil Rajbc626052019-08-15 15:49:45 +010017
18class Packet
19{
20public:
Matteo Martincigh24e8f922019-09-19 11:57:46 +010021 Packet()
22 : m_Header(0)
Jim Flynn01d02812020-04-29 21:12:13 +010023 , m_PacketFamily(0)
24 , m_PacketId(0)
Matteo Martincigh24e8f922019-09-19 11:57:46 +010025 , m_Length(0)
26 , m_Data(nullptr)
27 {}
28
Matteo Martincigh54fb9572019-10-02 12:50:57 +010029 Packet(uint32_t header)
30 : m_Header(header)
31 , m_Length(0)
32 , m_Data(nullptr)
33 {
34 m_PacketId = ((header >> 16) & 1023);
35 m_PacketFamily = (header >> 26);
36 }
37
Matteo Martincigh67ef2a52019-10-10 13:29:02 +010038 Packet(uint32_t header, uint32_t length, std::unique_ptr<unsigned char[]>& data)
Matteo Martincigh24e8f922019-09-19 11:57:46 +010039 : m_Header(header)
40 , m_Length(length)
41 , m_Data(std::move(data))
Matteo Martincigh149528e2019-09-05 12:02:04 +010042 {
43 m_PacketId = ((header >> 16) & 1023);
44 m_PacketFamily = (header >> 26);
Nikhil Rajbc626052019-08-15 15:49:45 +010045
Matteo Martincigh149528e2019-09-05 12:02:04 +010046 if (length == 0 && m_Data != nullptr)
47 {
48 throw armnn::InvalidArgumentException("Data should be null when length is zero");
49 }
50 }
Nikhil Rajbc626052019-08-15 15:49:45 +010051
Matteo Martincighd0613b52019-10-09 16:47:04 +010052 Packet(Packet&& other)
53 : m_Header(other.m_Header)
54 , m_PacketFamily(other.m_PacketFamily)
55 , m_PacketId(other.m_PacketId)
56 , m_Length(other.m_Length)
57 , m_Data(std::move(other.m_Data))
58 {
59 other.m_Header = 0;
60 other.m_PacketFamily = 0;
61 other.m_PacketId = 0;
62 other.m_Length = 0;
63 }
64
65 ~Packet() = default;
FinnWilliamsArma0c78712019-09-16 12:06:47 +010066
67 Packet(const Packet& other) = delete;
68 Packet& operator=(const Packet&) = delete;
Matteo Martincigh54fb9572019-10-02 12:50:57 +010069 Packet& operator=(Packet&&) = default;
FinnWilliamsArma0c78712019-09-16 12:06:47 +010070
Matteo Martincigh76c50d82019-11-21 12:10:42 +000071 uint32_t GetHeader() const { return m_Header; }
72 uint32_t GetPacketFamily() const { return m_PacketFamily; }
73 uint32_t GetPacketId() const { return m_PacketId; }
74 uint32_t GetPacketClass() const { return m_PacketId >> 3; }
75 uint32_t GetPacketType() const { return m_PacketId & 7; }
76 uint32_t GetLength() const { return m_Length; }
77 const unsigned char* GetData() const { return m_Data.get(); }
Nikhil Rajbc626052019-08-15 15:49:45 +010078
Matteo Martincigh24e8f922019-09-19 11:57:46 +010079 bool IsEmpty() { return m_Header == 0 && m_Length == 0; }
80
Nikhil Rajbc626052019-08-15 15:49:45 +010081private:
82 uint32_t m_Header;
83 uint32_t m_PacketFamily;
84 uint32_t m_PacketId;
85 uint32_t m_Length;
Matteo Martincigh67ef2a52019-10-10 13:29:02 +010086 std::unique_ptr<unsigned char[]> m_Data;
Aron Virginas-Tare898db92019-08-22 12:56:34 +010087};
88
89} // namespace profiling
90
91} // namespace armnn