ArmNN
 20.02
Packet.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <armnn/Exceptions.hpp>
9 
10 #include <memory>
11 
12 namespace armnn
13 {
14 
15 namespace profiling
16 {
17 
18 class Packet
19 {
20 public:
22  : m_Header(0)
23  , m_Length(0)
24  , m_Data(nullptr)
25  {}
26 
27  Packet(uint32_t header)
28  : m_Header(header)
29  , m_Length(0)
30  , m_Data(nullptr)
31  {
32  m_PacketId = ((header >> 16) & 1023);
33  m_PacketFamily = (header >> 26);
34  }
35 
36  Packet(uint32_t header, uint32_t length, std::unique_ptr<unsigned char[]>& data)
37  : m_Header(header)
38  , m_Length(length)
39  , m_Data(std::move(data))
40  {
41  m_PacketId = ((header >> 16) & 1023);
42  m_PacketFamily = (header >> 26);
43 
44  if (length == 0 && m_Data != nullptr)
45  {
46  throw armnn::InvalidArgumentException("Data should be null when length is zero");
47  }
48  }
49 
50  Packet(Packet&& other)
51  : m_Header(other.m_Header)
52  , m_PacketFamily(other.m_PacketFamily)
53  , m_PacketId(other.m_PacketId)
54  , m_Length(other.m_Length)
55  , m_Data(std::move(other.m_Data))
56  {
57  other.m_Header = 0;
58  other.m_PacketFamily = 0;
59  other.m_PacketId = 0;
60  other.m_Length = 0;
61  }
62 
63  ~Packet() = default;
64 
65  Packet(const Packet& other) = delete;
66  Packet& operator=(const Packet&) = delete;
67  Packet& operator=(Packet&&) = default;
68 
69  uint32_t GetHeader() const { return m_Header; }
70  uint32_t GetPacketFamily() const { return m_PacketFamily; }
71  uint32_t GetPacketId() const { return m_PacketId; }
72  uint32_t GetPacketClass() const { return m_PacketId >> 3; }
73  uint32_t GetPacketType() const { return m_PacketId & 7; }
74  uint32_t GetLength() const { return m_Length; }
75  const unsigned char* GetData() const { return m_Data.get(); }
76 
77  bool IsEmpty() { return m_Header == 0 && m_Length == 0; }
78 
79 private:
80  uint32_t m_Header;
81  uint32_t m_PacketFamily;
82  uint32_t m_PacketId;
83  uint32_t m_Length;
84  std::unique_ptr<unsigned char[]> m_Data;
85 };
86 
87 } // namespace profiling
88 
89 } // namespace armnn
Packet(uint32_t header, uint32_t length, std::unique_ptr< unsigned char[]> &data)
Definition: Packet.hpp:36
uint32_t GetPacketClass() const
Definition: Packet.hpp:72
Packet & operator=(const Packet &)=delete
Copyright (c) 2020 ARM Limited.
Packet(uint32_t header)
Definition: Packet.hpp:27
uint32_t GetPacketFamily() const
Definition: Packet.hpp:70
uint32_t GetPacketType() const
Definition: Packet.hpp:73
uint32_t GetLength() const
Definition: Packet.hpp:74
Packet(Packet &&other)
Definition: Packet.hpp:50
uint32_t GetHeader() const
Definition: Packet.hpp:69
uint32_t GetPacketId() const
Definition: Packet.hpp:71
const unsigned char * GetData() const
Definition: Packet.hpp:75