blob: a3f732cb55ac2daa8d87a99bfd910cd3ea4de15f [file] [log] [blame]
Colm Donelana21620d2019-10-11 13:09:49 +01001//
2// Copyright © 2019 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
Matteo Martincigh65984272019-10-17 13:26:21 +01005
Colm Donelana21620d2019-10-11 13:09:49 +01006#include "GatordMockService.hpp"
7
Matteo Martincigh65984272019-10-17 13:26:21 +01008#include <CommandHandlerRegistry.hpp>
Keith Davis3201eea2019-10-24 17:30:41 +01009#include <PacketVersionResolver.hpp>
10#include <ProfilingUtils.hpp>
Rob Hughes25b74362020-01-13 11:14:59 +000011#include <NetworkSockets.hpp>
Colm Donelana21620d2019-10-11 13:09:49 +010012
13#include <cerrno>
14#include <fcntl.h>
Colm Donelanb682d842019-10-16 12:24:20 +010015#include <iomanip>
Colm Donelana21620d2019-10-11 13:09:49 +010016#include <iostream>
Colm Donelana21620d2019-10-11 13:09:49 +010017#include <string>
Rob Hughes25b74362020-01-13 11:14:59 +000018
19using namespace armnnUtils;
Colm Donelana21620d2019-10-11 13:09:49 +010020
Colm Donelana21620d2019-10-11 13:09:49 +010021namespace armnn
22{
23
24namespace gatordmock
25{
26
Finn Williamse6a2ccd2020-02-27 16:21:41 +000027bool GatordMockService::OpenListeningSocket(armnnUtils::Sockets::Socket listeningSocket,
28 const std::string udsNamespace,
29 const int numOfConnections)
Colm Donelana21620d2019-10-11 13:09:49 +010030{
Finn Williamse6a2ccd2020-02-27 16:21:41 +000031 if (-1 == listeningSocket)
Colm Donelana21620d2019-10-11 13:09:49 +010032 {
33 std::cerr << ": Socket construction failed: " << strerror(errno) << std::endl;
34 return false;
35 }
36
37 sockaddr_un udsAddress;
38 memset(&udsAddress, 0, sizeof(sockaddr_un));
39 // We've set the first element of sun_path to be 0, skip over it and copy the namespace after it.
40 memcpy(udsAddress.sun_path + 1, udsNamespace.c_str(), strlen(udsNamespace.c_str()));
41 udsAddress.sun_family = AF_UNIX;
42
43 // Bind the socket to the UDS namespace.
Finn Williamse6a2ccd2020-02-27 16:21:41 +000044 if (-1 == bind(listeningSocket, reinterpret_cast<const sockaddr*>(&udsAddress), sizeof(sockaddr_un)))
Colm Donelana21620d2019-10-11 13:09:49 +010045 {
46 std::cerr << ": Binding on socket failed: " << strerror(errno) << std::endl;
47 return false;
48 }
Finn Williamse6a2ccd2020-02-27 16:21:41 +000049 // Listen for 10 connections.
50 if (-1 == listen(listeningSocket, numOfConnections))
Colm Donelana21620d2019-10-11 13:09:49 +010051 {
52 std::cerr << ": Listen call on socket failed: " << strerror(errno) << std::endl;
53 return false;
54 }
Colm Donelana21620d2019-10-11 13:09:49 +010055 return true;
56}
57
Colm Donelana21620d2019-10-11 13:09:49 +010058bool GatordMockService::WaitForStreamMetaData()
59{
60 if (m_EchoPackets)
61 {
62 std::cout << "Waiting for stream meta data..." << std::endl;
63 }
64 // The start of the stream metadata is 2x32bit words, 0 and packet length.
Rob Hughes270233f2019-11-13 11:53:48 +000065 uint8_t header[8];
Colm Donelana21620d2019-10-11 13:09:49 +010066 if (!ReadFromSocket(header, 8))
67 {
68 return false;
69 }
Colm Donelanb682d842019-10-16 12:24:20 +010070 EchoPacket(PacketDirection::ReceivedHeader, header, 8);
Colm Donelana21620d2019-10-11 13:09:49 +010071 // The first word, stream_metadata_identifer, should always be 0.
72 if (ToUint32(&header[0], TargetEndianness::BeWire) != 0)
73 {
74 std::cerr << ": Protocol error. The stream_metadata_identifer was not 0." << std::endl;
75 return false;
76 }
77
Rob Hughes270233f2019-11-13 11:53:48 +000078 uint8_t pipeMagic[4];
Colm Donelana21620d2019-10-11 13:09:49 +010079 if (!ReadFromSocket(pipeMagic, 4))
80 {
81 return false;
82 }
Colm Donelanb682d842019-10-16 12:24:20 +010083 EchoPacket(PacketDirection::ReceivedData, pipeMagic, 4);
Colm Donelana21620d2019-10-11 13:09:49 +010084
85 // Before we interpret the length we need to read the pipe_magic word to determine endianness.
86 if (ToUint32(&pipeMagic[0], TargetEndianness::BeWire) == PIPE_MAGIC)
87 {
88 m_Endianness = TargetEndianness::BeWire;
89 }
90 else if (ToUint32(&pipeMagic[0], TargetEndianness::LeWire) == PIPE_MAGIC)
91 {
92 m_Endianness = TargetEndianness::LeWire;
93 }
94 else
95 {
96 std::cerr << ": Protocol read error. Unable to read PIPE_MAGIC value." << std::endl;
97 return false;
98 }
99 // Now we know the endianness we can get the length from the header.
100 // Remember we already read the pipe magic 4 bytes.
101 uint32_t metaDataLength = ToUint32(&header[4], m_Endianness) - 4;
102 // Read the entire packet.
Rob Hughes25b74362020-01-13 11:14:59 +0000103 std::vector<uint8_t> packetData(metaDataLength);
104 if (metaDataLength !=
105 boost::numeric_cast<uint32_t>(Sockets::Read(m_ClientConnection, packetData.data(), metaDataLength)))
Colm Donelana21620d2019-10-11 13:09:49 +0100106 {
107 std::cerr << ": Protocol read error. Data length mismatch." << std::endl;
108 return false;
109 }
Rob Hughes25b74362020-01-13 11:14:59 +0000110 EchoPacket(PacketDirection::ReceivedData, packetData.data(), metaDataLength);
Colm Donelanb682d842019-10-16 12:24:20 +0100111 m_StreamMetaDataVersion = ToUint32(&packetData[0], m_Endianness);
Colm Donelana21620d2019-10-11 13:09:49 +0100112 m_StreamMetaDataMaxDataLen = ToUint32(&packetData[4], m_Endianness);
Colm Donelanb682d842019-10-16 12:24:20 +0100113 m_StreamMetaDataPid = ToUint32(&packetData[8], m_Endianness);
Colm Donelana21620d2019-10-11 13:09:49 +0100114
115 return true;
116}
117
118void GatordMockService::SendConnectionAck()
119{
120 if (m_EchoPackets)
121 {
122 std::cout << "Sending connection acknowledgement." << std::endl;
123 }
124 // The connection ack packet is an empty data packet with packetId == 1.
125 SendPacket(0, 1, nullptr, 0);
126}
127
Finn Williams15db7452019-10-15 14:22:13 +0100128void GatordMockService::SendRequestCounterDir()
129{
130 if (m_EchoPackets)
131 {
132 std::cout << "Sending connection acknowledgement." << std::endl;
133 }
134 // The connection ack packet is an empty data packet with packetId == 1.
135 SendPacket(0, 3, nullptr, 0);
136}
137
Colm Donelana21620d2019-10-11 13:09:49 +0100138bool GatordMockService::LaunchReceivingThread()
139{
140 if (m_EchoPackets)
141 {
142 std::cout << "Launching receiving thread." << std::endl;
143 }
144 // At this point we want to make the socket non blocking.
Rob Hughes25b74362020-01-13 11:14:59 +0000145 if (!Sockets::SetNonBlocking(m_ClientConnection))
Colm Donelana21620d2019-10-11 13:09:49 +0100146 {
Rob Hughes25b74362020-01-13 11:14:59 +0000147 Sockets::Close(m_ClientConnection);
Colm Donelana21620d2019-10-11 13:09:49 +0100148 std::cerr << "Failed to set socket as non blocking: " << strerror(errno) << std::endl;
149 return false;
150 }
151 m_ListeningThread = std::thread(&GatordMockService::ReceiveLoop, this, std::ref(*this));
152 return true;
153}
154
155void GatordMockService::WaitForReceivingThread()
156{
Colm Donelan02705242019-11-14 14:19:07 +0000157 // The receiving thread may already have died.
158 if (m_CloseReceivingThread != true)
159 {
160 m_CloseReceivingThread.store(true);
161 }
Colm Donelana21620d2019-10-11 13:09:49 +0100162 // Check that the receiving thread is running
163 if (m_ListeningThread.joinable())
164 {
165 // Wait for the receiving thread to complete operations
166 m_ListeningThread.join();
167 }
168}
169
Colm Donelanb682d842019-10-16 12:24:20 +0100170void GatordMockService::SendPeriodicCounterSelectionList(uint32_t period, std::vector<uint16_t> counters)
Colm Donelana21620d2019-10-11 13:09:49 +0100171{
Colm Donelanb682d842019-10-16 12:24:20 +0100172 // The packet body consists of a UINT32 representing the period following by zero or more
173 // UINT16's representing counter UID's. If the list is empty it implies all counters are to
174 // be disabled.
Colm Donelana21620d2019-10-11 13:09:49 +0100175
Colm Donelanb682d842019-10-16 12:24:20 +0100176 if (m_EchoPackets)
Colm Donelana21620d2019-10-11 13:09:49 +0100177 {
Colm Donelanb682d842019-10-16 12:24:20 +0100178 std::cout << "SendPeriodicCounterSelectionList: Period=" << std::dec << period << "uSec" << std::endl;
179 std::cout << "List length=" << counters.size() << std::endl;
180 ;
181 }
182 // Start by calculating the length of the packet body in bytes. This will be at least 4.
183 uint32_t dataLength = static_cast<uint32_t>(4 + (counters.size() * 2));
184
185 std::unique_ptr<unsigned char[]> uniqueData = std::make_unique<unsigned char[]>(dataLength);
186 unsigned char* data = reinterpret_cast<unsigned char*>(uniqueData.get());
187
188 uint32_t offset = 0;
189 profiling::WriteUint32(data, offset, period);
190 offset += 4;
191 for (std::vector<uint16_t>::iterator it = counters.begin(); it != counters.end(); ++it)
192 {
193 profiling::WriteUint16(data, offset, *it);
194 offset += 2;
Colm Donelana21620d2019-10-11 13:09:49 +0100195 }
196
Colm Donelanb682d842019-10-16 12:24:20 +0100197 // Send the packet.
198 SendPacket(0, 4, data, dataLength);
199 // There will be an echo response packet sitting in the receive thread. PeriodicCounterSelectionResponseHandler
200 // should deal with it.
Colm Donelana21620d2019-10-11 13:09:49 +0100201}
202
Rob Hughes25b74362020-01-13 11:14:59 +0000203void GatordMockService::WaitCommand(uint32_t timeout)
Colm Donelana21620d2019-10-11 13:09:49 +0100204{
Colm Donelan02705242019-11-14 14:19:07 +0000205 // Wait for a maximum of timeout microseconds or if the receive thread has closed.
206 // There is a certain level of rounding involved in this timing.
Rob Hughes25b74362020-01-13 11:14:59 +0000207 uint32_t iterations = timeout / 1000;
Colm Donelan02705242019-11-14 14:19:07 +0000208 std::cout << std::dec << "Wait command with timeout of " << timeout << " iterations = " << iterations << std::endl;
Rob Hughes25b74362020-01-13 11:14:59 +0000209 uint32_t count = 0;
Colm Donelan02705242019-11-14 14:19:07 +0000210 while ((this->ReceiveThreadRunning() && (count < iterations)))
211 {
212 std::this_thread::sleep_for(std::chrono::microseconds(1000));
213 ++count;
214 }
Colm Donelana21620d2019-10-11 13:09:49 +0100215 if (m_EchoPackets)
216 {
217 std::cout << std::dec << "Wait command with timeout of " << timeout << " microseconds completed. " << std::endl;
218 }
219}
220
221void GatordMockService::ReceiveLoop(GatordMockService& mockService)
222{
223 m_CloseReceivingThread.store(false);
224 while (!m_CloseReceivingThread.load())
225 {
226 try
227 {
228 armnn::profiling::Packet packet = mockService.WaitForPacket(500);
229 }
Jammy Zhoud80cc0c2019-10-21 16:44:40 +0800230 catch (const armnn::TimeoutException&)
Colm Donelana21620d2019-10-11 13:09:49 +0100231 {
232 // In this case we ignore timeouts and and keep trying to receive.
233 }
Keith Davis3201eea2019-10-24 17:30:41 +0100234 catch (const armnn::InvalidArgumentException& e)
Colm Donelanb682d842019-10-16 12:24:20 +0100235 {
236 // We couldn't find a functor to handle the packet?
237 std::cerr << "Packet received that could not be processed: " << e.what() << std::endl;
238 }
Keith Davis3201eea2019-10-24 17:30:41 +0100239 catch (const armnn::RuntimeException& e)
Colm Donelanb682d842019-10-16 12:24:20 +0100240 {
241 // A runtime exception occurred which means we must exit the loop.
242 std::cerr << "Receive thread closing: " << e.what() << std::endl;
243 m_CloseReceivingThread.store(true);
244 }
Colm Donelana21620d2019-10-11 13:09:49 +0100245 }
246}
247
248armnn::profiling::Packet GatordMockService::WaitForPacket(uint32_t timeoutMs)
249{
250 // Is there currently more than a headers worth of data waiting to be read?
251 int bytes_available;
Rob Hughes25b74362020-01-13 11:14:59 +0000252 Sockets::Ioctl(m_ClientConnection, FIONREAD, &bytes_available);
Colm Donelana21620d2019-10-11 13:09:49 +0100253 if (bytes_available > 8)
254 {
255 // Yes there is. Read it:
256 return ReceivePacket();
257 }
258 else
259 {
260 // No there's not. Poll for more data.
261 struct pollfd pollingFd[1]{};
262 pollingFd[0].fd = m_ClientConnection;
Rob Hughes25b74362020-01-13 11:14:59 +0000263 int pollResult = Sockets::Poll(pollingFd, 1, static_cast<int>(timeoutMs));
Colm Donelana21620d2019-10-11 13:09:49 +0100264
265 switch (pollResult)
266 {
267 // Error
268 case -1:
269 throw armnn::RuntimeException(std::string("File descriptor reported an error during polling: ") +
270 strerror(errno));
271
272 // Timeout
273 case 0:
274 throw armnn::TimeoutException("Timeout while waiting to receive packet.");
275
276 // Normal poll return. It could still contain an error signal
277 default:
Colm Donelana21620d2019-10-11 13:09:49 +0100278 // Check if the socket reported an error
279 if (pollingFd[0].revents & (POLLNVAL | POLLERR | POLLHUP))
280 {
Colm Donelanb682d842019-10-16 12:24:20 +0100281 if (pollingFd[0].revents == POLLNVAL)
282 {
283 throw armnn::RuntimeException(std::string("Error while polling receiving socket: POLLNVAL"));
284 }
285 if (pollingFd[0].revents == POLLERR)
286 {
287 throw armnn::RuntimeException(std::string("Error while polling receiving socket: POLLERR: ") +
288 strerror(errno));
289 }
290 if (pollingFd[0].revents == POLLHUP)
291 {
292 throw armnn::RuntimeException(std::string("Connection closed by remote client: POLLHUP"));
293 }
Colm Donelana21620d2019-10-11 13:09:49 +0100294 }
295
296 // Check if there is data to read
297 if (!(pollingFd[0].revents & (POLLIN)))
298 {
299 // This is a corner case. The socket as been woken up but not with any data.
300 // We'll throw a timeout exception to loop around again.
301 throw armnn::TimeoutException("File descriptor was polled but no data was available to receive.");
302 }
303 return ReceivePacket();
304 }
305 }
306}
307
Colm Donelana21620d2019-10-11 13:09:49 +0100308armnn::profiling::Packet GatordMockService::ReceivePacket()
309{
310 uint32_t header[2];
311 if (!ReadHeader(header))
312 {
313 return armnn::profiling::Packet();
314 }
315 // Read data_length bytes from the socket.
316 std::unique_ptr<unsigned char[]> uniquePacketData = std::make_unique<unsigned char[]>(header[1]);
Colm Donelanb682d842019-10-16 12:24:20 +0100317 unsigned char* packetData = reinterpret_cast<unsigned char*>(uniquePacketData.get());
Colm Donelana21620d2019-10-11 13:09:49 +0100318
319 if (!ReadFromSocket(packetData, header[1]))
320 {
321 return armnn::profiling::Packet();
322 }
323
Colm Donelanb682d842019-10-16 12:24:20 +0100324 EchoPacket(PacketDirection::ReceivedData, packetData, header[1]);
325
Colm Donelana21620d2019-10-11 13:09:49 +0100326 // Construct received packet
Colm Donelanb682d842019-10-16 12:24:20 +0100327 armnn::profiling::PacketVersionResolver packetVersionResolver;
Colm Donelana21620d2019-10-11 13:09:49 +0100328 armnn::profiling::Packet packetRx = armnn::profiling::Packet(header[0], header[1], uniquePacketData);
Colm Donelanb682d842019-10-16 12:24:20 +0100329 if (m_EchoPackets)
Colm Donelana21620d2019-10-11 13:09:49 +0100330 {
Colm Donelanb682d842019-10-16 12:24:20 +0100331 std::cout << "Processing packet ID= " << packetRx.GetPacketId() << " Length=" << packetRx.GetLength()
332 << std::endl;
Colm Donelana21620d2019-10-11 13:09:49 +0100333 }
334
Keith Davis3201eea2019-10-24 17:30:41 +0100335 profiling::Version version =
336 packetVersionResolver.ResolvePacketVersion(packetRx.GetPacketFamily(), packetRx.GetPacketId());
337
338 profiling::CommandHandlerFunctor* commandHandlerFunctor =
339 m_HandlerRegistry.GetFunctor(packetRx.GetPacketFamily(), packetRx.GetPacketId(), version.GetEncodedValue());
340 BOOST_ASSERT(commandHandlerFunctor);
341 commandHandlerFunctor->operator()(packetRx);
Colm Donelana21620d2019-10-11 13:09:49 +0100342 return packetRx;
343}
344
Rob Hughes270233f2019-11-13 11:53:48 +0000345bool GatordMockService::SendPacket(uint32_t packetFamily, uint32_t packetId, const uint8_t* data, uint32_t dataLength)
Colm Donelana21620d2019-10-11 13:09:49 +0100346{
347 // Construct a packet from the id and data given and send it to the client.
348 // Encode the header.
349 uint32_t header[2];
350 header[0] = packetFamily << 26 | packetId << 16;
351 header[1] = dataLength;
352 // Add the header to the packet.
Rob Hughes25b74362020-01-13 11:14:59 +0000353 std::vector<uint8_t> packet(8 + dataLength);
354 InsertU32(header[0], packet.data(), m_Endianness);
355 InsertU32(header[1], packet.data() + 4, m_Endianness);
Colm Donelana21620d2019-10-11 13:09:49 +0100356 // And the rest of the data if there is any.
357 if (dataLength > 0)
358 {
Rob Hughes25b74362020-01-13 11:14:59 +0000359 memcpy((packet.data() + 8), data, dataLength);
Colm Donelana21620d2019-10-11 13:09:49 +0100360 }
Rob Hughes25b74362020-01-13 11:14:59 +0000361 EchoPacket(PacketDirection::Sending, packet.data(), packet.size());
362 if (-1 == Sockets::Write(m_ClientConnection, packet.data(), packet.size()))
Colm Donelana21620d2019-10-11 13:09:49 +0100363 {
364 std::cerr << ": Failure when writing to client socket: " << strerror(errno) << std::endl;
365 return false;
366 }
367 return true;
368}
369
370bool GatordMockService::ReadHeader(uint32_t headerAsWords[2])
371{
Colm Donelanb682d842019-10-16 12:24:20 +0100372 // The header will always be 2x32bit words.
Rob Hughes270233f2019-11-13 11:53:48 +0000373 uint8_t header[8];
Colm Donelana21620d2019-10-11 13:09:49 +0100374 if (!ReadFromSocket(header, 8))
375 {
376 return false;
377 }
Colm Donelanb682d842019-10-16 12:24:20 +0100378 EchoPacket(PacketDirection::ReceivedHeader, header, 8);
Colm Donelana21620d2019-10-11 13:09:49 +0100379 headerAsWords[0] = ToUint32(&header[0], m_Endianness);
380 headerAsWords[1] = ToUint32(&header[4], m_Endianness);
381 return true;
382}
383
Rob Hughes270233f2019-11-13 11:53:48 +0000384bool GatordMockService::ReadFromSocket(uint8_t* packetData, uint32_t expectedLength)
Colm Donelana21620d2019-10-11 13:09:49 +0100385{
386 // This is a blocking read until either expectedLength has been received or an error is detected.
Rob Hughes25b74362020-01-13 11:14:59 +0000387 long totalBytesRead = 0;
Jammy Zhoud80cc0c2019-10-21 16:44:40 +0800388 while (boost::numeric_cast<uint32_t>(totalBytesRead) < expectedLength)
Colm Donelana21620d2019-10-11 13:09:49 +0100389 {
Rob Hughes25b74362020-01-13 11:14:59 +0000390 long bytesRead = Sockets::Read(m_ClientConnection, packetData, expectedLength);
Colm Donelana21620d2019-10-11 13:09:49 +0100391 if (bytesRead < 0)
392 {
393 std::cerr << ": Failure when reading from client socket: " << strerror(errno) << std::endl;
394 return false;
395 }
396 if (bytesRead == 0)
397 {
398 std::cerr << ": EOF while reading from client socket." << std::endl;
399 return false;
400 }
401 totalBytesRead += bytesRead;
402 }
403 return true;
404};
405
Rob Hughes270233f2019-11-13 11:53:48 +0000406void GatordMockService::EchoPacket(PacketDirection direction, uint8_t* packet, size_t lengthInBytes)
Colm Donelana21620d2019-10-11 13:09:49 +0100407{
408 // If enabled print the contents of the data packet to the console.
409 if (m_EchoPackets)
410 {
411 if (direction == PacketDirection::Sending)
412 {
Colm Donelanb682d842019-10-16 12:24:20 +0100413 std::cout << "TX " << std::dec << lengthInBytes << " bytes : ";
414 }
415 else if (direction == PacketDirection::ReceivedHeader)
Colm Donelana21620d2019-10-11 13:09:49 +0100416 {
Colm Donelanb682d842019-10-16 12:24:20 +0100417 std::cout << "RX Header " << std::dec << lengthInBytes << " bytes : ";
418 }
419 else
420 {
421 std::cout << "RX Data " << std::dec << lengthInBytes << " bytes : ";
Colm Donelana21620d2019-10-11 13:09:49 +0100422 }
423 for (unsigned int i = 0; i < lengthInBytes; i++)
424 {
425 if ((i % 10) == 0)
426 {
427 std::cout << std::endl;
428 }
Colm Donelanb682d842019-10-16 12:24:20 +0100429 std::cout << "0x" << std::setfill('0') << std::setw(2) << std::hex << static_cast<unsigned int>(packet[i])
430 << " ";
Colm Donelana21620d2019-10-11 13:09:49 +0100431 }
432 std::cout << std::endl;
433 }
434}
435
Rob Hughes270233f2019-11-13 11:53:48 +0000436uint32_t GatordMockService::ToUint32(uint8_t* data, TargetEndianness endianness)
Colm Donelana21620d2019-10-11 13:09:49 +0100437{
438 // Extract the first 4 bytes starting at data and push them into a 32bit integer based on the
439 // specified endianness.
440 if (endianness == TargetEndianness::BeWire)
441 {
442 return static_cast<uint32_t>(data[0]) << 24 | static_cast<uint32_t>(data[1]) << 16 |
443 static_cast<uint32_t>(data[2]) << 8 | static_cast<uint32_t>(data[3]);
444 }
445 else
446 {
447 return static_cast<uint32_t>(data[3]) << 24 | static_cast<uint32_t>(data[2]) << 16 |
448 static_cast<uint32_t>(data[1]) << 8 | static_cast<uint32_t>(data[0]);
449 }
450}
451
Rob Hughes270233f2019-11-13 11:53:48 +0000452void GatordMockService::InsertU32(uint32_t value, uint8_t* data, TargetEndianness endianness)
Colm Donelana21620d2019-10-11 13:09:49 +0100453{
454 // Take the bytes of a 32bit integer and copy them into char array starting at data considering
455 // the endianness value.
456 if (endianness == TargetEndianness::BeWire)
457 {
Rob Hughes270233f2019-11-13 11:53:48 +0000458 *data = static_cast<uint8_t>((value >> 24) & 0xFF);
459 *(data + 1) = static_cast<uint8_t>((value >> 16) & 0xFF);
460 *(data + 2) = static_cast<uint8_t>((value >> 8) & 0xFF);
461 *(data + 3) = static_cast<uint8_t>(value & 0xFF);
Colm Donelana21620d2019-10-11 13:09:49 +0100462 }
463 else
464 {
Rob Hughes270233f2019-11-13 11:53:48 +0000465 *(data + 3) = static_cast<uint8_t>((value >> 24) & 0xFF);
466 *(data + 2) = static_cast<uint8_t>((value >> 16) & 0xFF);
467 *(data + 1) = static_cast<uint8_t>((value >> 8) & 0xFF);
468 *data = static_cast<uint8_t>(value & 0xFF);
Colm Donelana21620d2019-10-11 13:09:49 +0100469 }
470}
471
Colm Donelanb682d842019-10-16 12:24:20 +0100472} // namespace gatordmock
Colm Donelana21620d2019-10-11 13:09:49 +0100473
Colm Donelanb682d842019-10-16 12:24:20 +0100474} // namespace armnn