From: Colm Donelan Date: Wed, 16 Oct 2019 11:24:20 +0000 (+0100) Subject: IVGCVSW-3721 Add support for startup sequence (Mock Gatord service). X-Git-Tag: submit/tizen/20200316.035456~146 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b682d840bb0b4cc34f4febb69c2385feec880ae1;p=platform%2Fupstream%2Farmnn.git IVGCVSW-3721 Add support for startup sequence (Mock Gatord service). * Updated ExecuteNetwork to propagate a configured Runtime down to RunTest. * Fixed the creation of PeriodicCounterCaptureCommandHandler to match other handlers. * Moved around some printouts to make the MockGatorD output more useful. * Added details to the exception handling for problems in the GatordMockService receive thread. * Mockutils::ConstructHeader is only used in GatordMockTests. Moved it in there and deleted MockUtils.hpp * Refactored SendPeriodicCounterSelectionList to use ProfilingUtils. * Added PeriodicCounterSelectionResponseHandler to received packet echoed back. Signed-off-by: Colm Donelan Change-Id: I4accdbf6cf5dd3f7dcc12b210b8360b4a5e4e277 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index e1af11e..3ad2eb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -901,9 +901,10 @@ if(BUILD_GATORD_MOCK) tests/profiling/gatordmock/CommandLineProcessor.cpp tests/profiling/gatordmock/GatordMockService.hpp tests/profiling/gatordmock/GatordMockService.cpp - tests/profiling/gatordmock/MockUtils.hpp tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.hpp + tests/profiling/gatordmock/PeriodicCounterSelectionResponseHandler.cpp + tests/profiling/gatordmock/PeriodicCounterSelectionResponseHandler.hpp ) include_directories(${Boost_INCLUDE_DIRS} src/profiling) diff --git a/tests/ExecuteNetwork/ExecuteNetwork.cpp b/tests/ExecuteNetwork/ExecuteNetwork.cpp index 1c1fa10..931bcd4 100644 --- a/tests/ExecuteNetwork/ExecuteNetwork.cpp +++ b/tests/ExecuteNetwork/ExecuteNetwork.cpp @@ -41,7 +41,6 @@ int main(int argc, const char* argv[]) const std::string backendsMessage = "REQUIRED: Which device to run layers on by default. Possible choices: " + armnn::BackendRegistryInstance().GetBackendIdsAsString(); - po::options_description desc("Options"); try { @@ -185,7 +184,6 @@ int main(int argc, const char* argv[]) options.m_ProfilingOptions.m_OutgoingCaptureFile = outgoingCaptureFile; options.m_ProfilingOptions.m_FileOnly = fileOnlyExternalProfiling; options.m_ProfilingOptions.m_CapturePeriod = counterCapturePeriod; - std::shared_ptr runtime(armnn::IRuntime::Create(options)); const std::string executableName("ExecuteNetwork"); @@ -254,10 +252,18 @@ int main(int argc, const char* argv[]) std::cerr << desc << std::endl; return EXIT_FAILURE; } - + // Create runtime + armnn::IRuntime::CreationOptions options; + options.m_EnableGpuProfiling = enableProfiling; + options.m_ProfilingOptions.m_EnableProfiling = enableExternalProfiling; + options.m_ProfilingOptions.m_IncomingCaptureFile = incomingCaptureFile; + options.m_ProfilingOptions.m_OutgoingCaptureFile = outgoingCaptureFile; + options.m_ProfilingOptions.m_FileOnly = fileOnlyExternalProfiling; + options.m_ProfilingOptions.m_CapturePeriod = counterCapturePeriod; + std::shared_ptr runtime(armnn::IRuntime::Create(options)); return RunTest(modelFormat, inputTensorShapes, computeDevices, dynamicBackendsPath, modelPath, inputNames, inputTensorDataFilePaths, inputTypes, quantizeInput, outputTypes, outputNames, outputTensorFiles, enableProfiling, enableFp16TurboMode, thresholdTime, printIntermediate, - subgraphId, enableLayerDetails); + subgraphId, enableLayerDetails, runtime); } } diff --git a/tests/profiling/gatordmock/CommandFileParser.hpp b/tests/profiling/gatordmock/CommandFileParser.hpp index e95395d..fd4a4fd 100644 --- a/tests/profiling/gatordmock/CommandFileParser.hpp +++ b/tests/profiling/gatordmock/CommandFileParser.hpp @@ -5,8 +5,8 @@ #pragma once -#include #include "GatordMockService.hpp" +#include namespace armnn { @@ -25,7 +25,5 @@ public: void ParseFile(std::string CommandFile, GatordMockService& mockService); }; -} // namespace gatordmock -} // namespace armnn - - +} // namespace gatordmock +} // namespace armnn diff --git a/tests/profiling/gatordmock/CommandLineProcessor.hpp b/tests/profiling/gatordmock/CommandLineProcessor.hpp index 0eed23a..532948a 100644 --- a/tests/profiling/gatordmock/CommandLineProcessor.hpp +++ b/tests/profiling/gatordmock/CommandLineProcessor.hpp @@ -12,7 +12,6 @@ namespace armnn namespace gatordmock { - /// Use Boost program options to process the command line. /// -h or --help to print the options. /// -n or --namespace to specify the UDS namespace that the server will be listening on. @@ -21,11 +20,20 @@ namespace gatordmock class CommandLineProcessor { public: - bool ProcessCommandLine(int argc, char *argv[]); - bool IsEchoEnabled() { return m_Echo; } - - std::string GetUdsNamespace() { return m_UdsNamespace; } - std::string GetCommandFile() { return m_File; } + bool ProcessCommandLine(int argc, char* argv[]); + bool IsEchoEnabled() + { + return m_Echo; + } + + std::string GetUdsNamespace() + { + return m_UdsNamespace; + } + std::string GetCommandFile() + { + return m_File; + } private: std::string m_UdsNamespace; @@ -34,6 +42,6 @@ private: bool m_Echo; }; -} // namespace gatordmock +} // namespace gatordmock -} // namespace armnn +} // namespace armnn diff --git a/tests/profiling/gatordmock/GatordMockMain.cpp b/tests/profiling/gatordmock/GatordMockMain.cpp index 500b016..002d6c7 100644 --- a/tests/profiling/gatordmock/GatordMockMain.cpp +++ b/tests/profiling/gatordmock/GatordMockMain.cpp @@ -3,15 +3,18 @@ // SPDX-License-Identifier: MIT // +#include "../../../src/profiling/PacketVersionResolver.hpp" +#include "../../../src/profiling/PeriodicCounterSelectionCommandHandler.hpp" #include "CommandFileParser.hpp" #include "CommandLineProcessor.hpp" #include "GatordMockService.hpp" -#include "MockUtils.hpp" #include "PeriodicCounterCaptureCommandHandler.hpp" +#include "PeriodicCounterSelectionResponseHandler.hpp" +#include #include -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { // Process command line arguments armnn::gatordmock::CommandLineProcessor cmdLine; @@ -20,21 +23,19 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - // Initialise functors and register into the CommandHandlerRegistry - uint32_t version = 1; - - // Create headers - uint32_t counterCaptureCommandHeader = armnn::gatordmock::ConstructHeader(1,0,0); - + armnn::profiling::PacketVersionResolver packetVersionResolver; // Create the Command Handler Registry armnn::profiling::CommandHandlerRegistry registry; - // Update with derived functors - armnn::gatordmock::PeriodicCounterCaptureCommandHandler counterCaptureCommandHandler(counterCaptureCommandHeader, - version, - cmdLine.IsEchoEnabled()); + // This functor will receive back the selection response packet. + armnn::gatordmock::PeriodicCounterSelectionResponseHandler periodicCounterSelectionResponseHandler( + 4, packetVersionResolver.ResolvePacketVersion(4).GetEncodedValue()); + // This functor will receive the counter data. + armnn::gatordmock::PeriodicCounterCaptureCommandHandler counterCaptureCommandHandler( + 0, packetVersionResolver.ResolvePacketVersion(0).GetEncodedValue()); // Register different derived functors + registry.RegisterFunctor(&periodicCounterSelectionResponseHandler); registry.RegisterFunctor(&counterCaptureCommandHandler); armnn::gatordmock::GatordMockService mockService(registry, cmdLine.IsEchoEnabled()); @@ -43,12 +44,14 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } + std::cout << "Bound to UDS namespace: \\0" << cmdLine.GetUdsNamespace() << std::endl; // Wait for a single connection. if (-1 == mockService.BlockForOneClient()) { return EXIT_FAILURE; } + std::cout << "Client connection established." << std::endl; // Send receive the strweam metadata and send connection ack. if (!mockService.WaitForStreamMetaData()) diff --git a/tests/profiling/gatordmock/GatordMockService.cpp b/tests/profiling/gatordmock/GatordMockService.cpp index b5531c4..4b9d752 100644 --- a/tests/profiling/gatordmock/GatordMockService.cpp +++ b/tests/profiling/gatordmock/GatordMockService.cpp @@ -6,9 +6,12 @@ #include "GatordMockService.hpp" #include +#include "../../src/profiling/PacketVersionResolver.hpp" +#include "../../src/profiling/ProfilingUtils.hpp" #include #include +#include #include #include #include @@ -39,7 +42,7 @@ bool GatordMockService::OpenListeningSocket(std::string udsNamespace) udsAddress.sun_family = AF_UNIX; // Bind the socket to the UDS namespace. - if (-1 == bind(m_ListeningSocket, reinterpret_cast(&udsAddress), sizeof(sockaddr_un))) + if (-1 == bind(m_ListeningSocket, reinterpret_cast(&udsAddress), sizeof(sockaddr_un))) { std::cerr << ": Binding on socket failed: " << strerror(errno) << std::endl; return false; @@ -50,30 +53,17 @@ bool GatordMockService::OpenListeningSocket(std::string udsNamespace) std::cerr << ": Listen call on socket failed: " << strerror(errno) << std::endl; return false; } - if (m_EchoPackets) - { - std::cout << "Bound to UDS namespace: \\0" << udsNamespace << std::endl; - } return true; } int GatordMockService::BlockForOneClient() { - if (m_EchoPackets) - { - std::cout << "Waiting for client connection." << std::endl; - } m_ClientConnection = accept4(m_ListeningSocket, nullptr, nullptr, SOCK_CLOEXEC); if (-1 == m_ClientConnection) { std::cerr << ": Failure when waiting for a client connection: " << strerror(errno) << std::endl; return -1; } - - if (m_EchoPackets) - { - std::cout << "Client connection established." << std::endl; - } return m_ClientConnection; } @@ -89,7 +79,7 @@ bool GatordMockService::WaitForStreamMetaData() { return false; } - EchoPacket(PacketDirection::Received, header, 8); + EchoPacket(PacketDirection::ReceivedHeader, header, 8); // The first word, stream_metadata_identifer, should always be 0. if (ToUint32(&header[0], TargetEndianness::BeWire) != 0) { @@ -102,7 +92,7 @@ bool GatordMockService::WaitForStreamMetaData() { return false; } - EchoPacket(PacketDirection::Received, pipeMagic, 4); + EchoPacket(PacketDirection::ReceivedData, pipeMagic, 4); // Before we interpret the length we need to read the pipe_magic word to determine endianness. if (ToUint32(&pipeMagic[0], TargetEndianness::BeWire) == PIPE_MAGIC) @@ -128,10 +118,10 @@ bool GatordMockService::WaitForStreamMetaData() std::cerr << ": Protocol read error. Data length mismatch." << std::endl; return false; } - EchoPacket(PacketDirection::Received, packetData, metaDataLength); - m_StreamMetaDataVersion = ToUint32(&packetData[0], m_Endianness); + EchoPacket(PacketDirection::ReceivedData, packetData, metaDataLength); + m_StreamMetaDataVersion = ToUint32(&packetData[0], m_Endianness); m_StreamMetaDataMaxDataLen = ToUint32(&packetData[4], m_Endianness); - m_StreamMetaDataPid = ToUint32(&packetData[8], m_Endianness); + m_StreamMetaDataPid = ToUint32(&packetData[8], m_Endianness); return true; } @@ -175,27 +165,37 @@ void GatordMockService::WaitForReceivingThread() } } - -void GatordMockService::SendPeriodicCounterSelectionList(uint period, std::vector counters) +void GatordMockService::SendPeriodicCounterSelectionList(uint32_t period, std::vector counters) { - //get the datalength in bytes - uint32_t datalength = static_cast(4 + counters.size() * 2); + // The packet body consists of a UINT32 representing the period following by zero or more + // UINT16's representing counter UID's. If the list is empty it implies all counters are to + // be disabled. - u_char data[datalength]; + if (m_EchoPackets) + { + std::cout << "SendPeriodicCounterSelectionList: Period=" << std::dec << period << "uSec" << std::endl; + std::cout << "List length=" << counters.size() << std::endl; + ; + } + // Start by calculating the length of the packet body in bytes. This will be at least 4. + uint32_t dataLength = static_cast(4 + (counters.size() * 2)); - *data = static_cast(period >> 24); - *(data + 1) = static_cast(period >> 16 & 0xFF); - *(data + 2) = static_cast(period >> 8 & 0xFF); - *(data + 3) = static_cast(period & 0xFF); + std::unique_ptr uniqueData = std::make_unique(dataLength); + unsigned char* data = reinterpret_cast(uniqueData.get()); - for (unsigned long i = 0; i < counters.size(); ++i) + uint32_t offset = 0; + profiling::WriteUint32(data, offset, period); + offset += 4; + for (std::vector::iterator it = counters.begin(); it != counters.end(); ++it) { - *(data + 4 + i * 2) = static_cast(counters[i] >> 8); - *(data + 5 + i * 2) = static_cast(counters[i] & 0xFF); + profiling::WriteUint16(data, offset, *it); + offset += 2; } - // create packet send packet - SendPacket(0, 4, data, datalength); + // Send the packet. + SendPacket(0, 4, data, dataLength); + // There will be an echo response packet sitting in the receive thread. PeriodicCounterSelectionResponseHandler + // should deal with it. } void GatordMockService::WaitCommand(uint timeout) @@ -217,10 +217,21 @@ void GatordMockService::ReceiveLoop(GatordMockService& mockService) { armnn::profiling::Packet packet = mockService.WaitForPacket(500); } - catch(armnn::TimeoutException) + catch (armnn::TimeoutException) { // In this case we ignore timeouts and and keep trying to receive. } + catch (armnn::InvalidArgumentException e) + { + // We couldn't find a functor to handle the packet? + std::cerr << "Packet received that could not be processed: " << e.what() << std::endl; + } + catch (armnn::RuntimeException e) + { + // A runtime exception occurred which means we must exit the loop. + std::cerr << "Receive thread closing: " << e.what() << std::endl; + m_CloseReceivingThread.store(true); + } } } @@ -239,7 +250,7 @@ armnn::profiling::Packet GatordMockService::WaitForPacket(uint32_t timeoutMs) // No there's not. Poll for more data. struct pollfd pollingFd[1]{}; pollingFd[0].fd = m_ClientConnection; - int pollResult = poll(pollingFd, 1, static_cast(timeoutMs)); + int pollResult = poll(pollingFd, 1, static_cast(timeoutMs)); switch (pollResult) { @@ -254,13 +265,22 @@ armnn::profiling::Packet GatordMockService::WaitForPacket(uint32_t timeoutMs) // Normal poll return. It could still contain an error signal default: - // Check if the socket reported an error if (pollingFd[0].revents & (POLLNVAL | POLLERR | POLLHUP)) { - std::cout << "Error while polling receiving socket." << std::endl; - throw armnn::RuntimeException(std::string("File descriptor reported an error during polling: ") + - strerror(errno)); + if (pollingFd[0].revents == POLLNVAL) + { + throw armnn::RuntimeException(std::string("Error while polling receiving socket: POLLNVAL")); + } + if (pollingFd[0].revents == POLLERR) + { + throw armnn::RuntimeException(std::string("Error while polling receiving socket: POLLERR: ") + + strerror(errno)); + } + if (pollingFd[0].revents == POLLHUP) + { + throw armnn::RuntimeException(std::string("Connection closed by remote client: POLLHUP")); + } } // Check if there is data to read @@ -275,7 +295,6 @@ armnn::profiling::Packet GatordMockService::WaitForPacket(uint32_t timeoutMs) } } - armnn::profiling::Packet GatordMockService::ReceivePacket() { uint32_t header[2]; @@ -285,24 +304,30 @@ armnn::profiling::Packet GatordMockService::ReceivePacket() } // Read data_length bytes from the socket. std::unique_ptr uniquePacketData = std::make_unique(header[1]); - unsigned char *packetData = reinterpret_cast(uniquePacketData.get()); + unsigned char* packetData = reinterpret_cast(uniquePacketData.get()); if (!ReadFromSocket(packetData, header[1])) { return armnn::profiling::Packet(); } + EchoPacket(PacketDirection::ReceivedData, packetData, header[1]); + // Construct received packet + armnn::profiling::PacketVersionResolver packetVersionResolver; armnn::profiling::Packet packetRx = armnn::profiling::Packet(header[0], header[1], uniquePacketData); - - // Pass packet into the handler registry - if (packetRx.GetHeader()!= 0) + if (m_EchoPackets) { - m_PacketsReceivedCount.operator++(std::memory_order::memory_order_release); - m_HandlerRegistry.GetFunctor(header[0],1)->operator()(packetRx); + std::cout << "Processing packet ID= " << packetRx.GetPacketId() << " Length=" << packetRx.GetLength() + << std::endl; } + // Pass packet into the handler registry + m_PacketsReceivedCount.operator++(std::memory_order::memory_order_release); + m_HandlerRegistry + .GetFunctor(packetRx.GetPacketId(), + packetVersionResolver.ResolvePacketVersion(packetRx.GetPacketId()).GetEncodedValue()) + ->operator()(packetRx); - EchoPacket(PacketDirection::Received, packetData, sizeof(packetData)); return packetRx; } @@ -314,7 +339,7 @@ bool GatordMockService::SendPacket(uint32_t packetFamily, uint32_t packetId, con header[0] = packetFamily << 26 | packetId << 16; header[1] = dataLength; // Add the header to the packet. - u_char packet[8 + dataLength ]; + u_char packet[8 + dataLength]; InsertU32(header[0], packet, m_Endianness); InsertU32(header[1], packet + 4, m_Endianness); // And the rest of the data if there is any. @@ -333,12 +358,13 @@ bool GatordMockService::SendPacket(uint32_t packetFamily, uint32_t packetId, con bool GatordMockService::ReadHeader(uint32_t headerAsWords[2]) { - // The herader will always be 2x32bit words. + // The header will always be 2x32bit words. u_char header[8]; if (!ReadFromSocket(header, 8)) { return false; } + EchoPacket(PacketDirection::ReceivedHeader, header, 8); headerAsWords[0] = ToUint32(&header[0], m_Endianness); headerAsWords[1] = ToUint32(&header[4], m_Endianness); return true; @@ -373,10 +399,15 @@ void GatordMockService::EchoPacket(PacketDirection direction, u_char* packet, si { if (direction == PacketDirection::Sending) { - std::cout << "Sending " << std::dec << lengthInBytes << " bytes : "; - } else + std::cout << "TX " << std::dec << lengthInBytes << " bytes : "; + } + else if (direction == PacketDirection::ReceivedHeader) + { + std::cout << "RX Header " << std::dec << lengthInBytes << " bytes : "; + } + else { - std::cout << "Received " << std::dec << lengthInBytes << " bytes : "; + std::cout << "RX Data " << std::dec << lengthInBytes << " bytes : "; } for (unsigned int i = 0; i < lengthInBytes; i++) { @@ -384,7 +415,8 @@ void GatordMockService::EchoPacket(PacketDirection direction, u_char* packet, si { std::cout << std::endl; } - std::cout << std::hex << "0x" << static_cast(packet[i]) << " "; + std::cout << "0x" << std::setfill('0') << std::setw(2) << std::hex << static_cast(packet[i]) + << " "; } std::cout << std::endl; } @@ -412,7 +444,7 @@ void GatordMockService::InsertU32(uint32_t value, u_char* data, TargetEndianness // the endianness value. if (endianness == TargetEndianness::BeWire) { - *data = static_cast((value >> 24) & 0xFF); + *data = static_cast((value >> 24) & 0xFF); *(data + 1) = static_cast((value >> 16) & 0xFF); *(data + 2) = static_cast((value >> 8) & 0xFF); *(data + 3) = static_cast(value & 0xFF); @@ -422,10 +454,10 @@ void GatordMockService::InsertU32(uint32_t value, u_char* data, TargetEndianness *(data + 3) = static_cast((value >> 24) & 0xFF); *(data + 2) = static_cast((value >> 16) & 0xFF); *(data + 1) = static_cast((value >> 8) & 0xFF); - *data = static_cast(value & 0xFF); + *data = static_cast(value & 0xFF); } } -} // namespace gatordmock +} // namespace gatordmock -} // namespace armnn +} // namespace armnn diff --git a/tests/profiling/gatordmock/GatordMockService.hpp b/tests/profiling/gatordmock/GatordMockService.hpp index c860f16..10bf884 100644 --- a/tests/profiling/gatordmock/GatordMockService.hpp +++ b/tests/profiling/gatordmock/GatordMockService.hpp @@ -8,9 +8,9 @@ #include #include +#include #include #include -#include namespace armnn { @@ -20,12 +20,15 @@ namespace gatordmock enum class TargetEndianness { - BeWire, LeWire + BeWire, + LeWire }; enum class PacketDirection { - Sending, Received + Sending, + ReceivedHeader, + ReceivedData }; /// A class that implements a Mock Gatord server. It will listen on a specified Unix domain socket (UDS) @@ -33,8 +36,6 @@ enum class PacketDirection class GatordMockService { public: - - /// @param registry reference to a command handler registry. /// @param echoPackets if true the raw packets will be printed to stdout. GatordMockService(armnn::profiling::CommandHandlerRegistry& registry, bool echoPackets) @@ -83,7 +84,7 @@ public: void WaitForReceivingThread(); /// Send the counter list to ArmNN. - void SendPeriodicCounterSelectionList(uint period, std::vector counters); + void SendPeriodicCounterSelectionList(uint32_t period, std::vector counters); /// Execute the WAIT command from the comamnd file. void WaitCommand(uint timeout); @@ -104,7 +105,6 @@ public: } private: - void ReceiveLoop(GatordMockService& mockService); /// Block on the client connection until a complete packet has been received. This is a placeholder function to @@ -129,10 +129,10 @@ private: static const uint32_t PIPE_MAGIC = 0x45495434; std::atomic m_PacketsReceivedCount; - TargetEndianness m_Endianness; - uint32_t m_StreamMetaDataVersion; - uint32_t m_StreamMetaDataMaxDataLen; - uint32_t m_StreamMetaDataPid; + TargetEndianness m_Endianness; + uint32_t m_StreamMetaDataVersion; + uint32_t m_StreamMetaDataMaxDataLen; + uint32_t m_StreamMetaDataPid; armnn::profiling::CommandHandlerRegistry& m_HandlerRegistry; @@ -142,8 +142,6 @@ private: std::thread m_ListeningThread; std::atomic m_CloseReceivingThread; }; -} // namespace gatordmock - -} // namespace armnn - +} // namespace gatordmock +} // namespace armnn diff --git a/tests/profiling/gatordmock/MockUtils.hpp b/tests/profiling/gatordmock/MockUtils.hpp deleted file mode 100644 index 93fc408..0000000 --- a/tests/profiling/gatordmock/MockUtils.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// -// Copyright © 2017 Arm Ltd. All rights reserved. -// SPDX-License-Identifier: MIT -// - -#pragma once - -#include - -namespace armnn -{ - -namespace gatordmock -{ - - -uint32_t ConstructHeader(uint32_t packetFamily, - uint32_t packetClass, - uint32_t packetType) -{ - return ((packetFamily & 0x3F) << 26)| - ((packetClass & 0x3FF) << 19)| - ((packetType & 0x3FFF) << 16); -} - -uint32_t ConstructHeader(uint32_t packetFamily, - uint32_t packetId) -{ - return ((packetFamily & 0x3F) << 26)| - ((packetId & 0x3FF) << 16); -} - -} // gatordmock - -} // armnn diff --git a/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp b/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp index f3bf796..90d52a7 100644 --- a/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp +++ b/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp @@ -97,7 +97,7 @@ void PeriodicCounterCaptureCommandHandler::ParseData(const armnn::profiling::Pac void PeriodicCounterCaptureCommandHandler::operator()(const profiling::Packet& packet) { ParseData(packet); - if (m_EchoPackets) + if (!m_QuietOperation) // Are we supposed to print to stdout? { std::string header, body, uidString, valueString; diff --git a/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.hpp b/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.hpp index 7d6471b..b2fd48f 100644 --- a/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.hpp +++ b/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.hpp @@ -7,6 +7,7 @@ #include #include +#include "../../armnn/src/profiling/Packet.hpp" #include @@ -27,11 +28,15 @@ class PeriodicCounterCaptureCommandHandler : public profiling::CommandHandlerFun { public: - PeriodicCounterCaptureCommandHandler(uint32_t packetId, - uint32_t version, - bool echoPackets) + /** + * + * @param packetId The id of packets this handler will process. + * @param version The version of that id. + * @param quietOperation Optional parameter to turn off printouts. This is useful for unittests. + */ + PeriodicCounterCaptureCommandHandler(uint32_t packetId, uint32_t version, bool quietOperation = false) : CommandHandlerFunctor(packetId, version) - , m_EchoPackets(echoPackets) + , m_QuietOperation(quietOperation) {} void operator()(const armnn::profiling::Packet& packet) override; @@ -46,9 +51,9 @@ private: uint64_t m_FirstTimestamp = 0, m_SecondTimestamp = 0; bool m_HeaderPrinted = false; - bool m_EchoPackets; + bool m_QuietOperation; }; -} // namespace gatordmock +} // namespace gatordmock -} // namespace armnn +} // namespace armnn diff --git a/tests/profiling/gatordmock/PeriodicCounterSelectionResponseHandler.cpp b/tests/profiling/gatordmock/PeriodicCounterSelectionResponseHandler.cpp new file mode 100644 index 0000000..645b0b3 --- /dev/null +++ b/tests/profiling/gatordmock/PeriodicCounterSelectionResponseHandler.cpp @@ -0,0 +1,37 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "PeriodicCounterSelectionResponseHandler.hpp" + +#include "../../../src/profiling/ProfilingUtils.hpp" + +#include + +namespace armnn +{ + +namespace gatordmock +{ + +void PeriodicCounterSelectionResponseHandler::operator()(const profiling::Packet& packet) +{ + if (!m_QuietOperation) // Are we supposed to print to stdout? + { + uint32_t period = profiling::ReadUint32(reinterpret_cast(packet.GetData()), 0); + uint32_t numCounters = 0; + // First check if there are any counters mentioned. + if(packet.GetLength() > 4) + { + // Length will be 4 bytes for the period and then a list of 16 bit UIDS. + numCounters = ((packet.GetLength() - 4) / 2); + } + std::cout << "PeriodicCounterSelectionResponse: Collection interval = " << std::dec << period << "uSec" + << " Num counters activated = " << numCounters << std::endl; + } +} + +} // namespace gatordmock + +} // namespace armnn \ No newline at end of file diff --git a/tests/profiling/gatordmock/PeriodicCounterSelectionResponseHandler.hpp b/tests/profiling/gatordmock/PeriodicCounterSelectionResponseHandler.hpp new file mode 100644 index 0000000..e1172e2 --- /dev/null +++ b/tests/profiling/gatordmock/PeriodicCounterSelectionResponseHandler.hpp @@ -0,0 +1,42 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "../../armnn/src/profiling/CommandHandlerFunctor.hpp" +#include "../../armnn/src/profiling/Packet.hpp" + +#include + +namespace armnn +{ + +namespace gatordmock +{ + +#pragma once + +class PeriodicCounterSelectionResponseHandler : public profiling::CommandHandlerFunctor +{ + +public: + /** + * + * @param packetId The id of packets this handler will process. + * @param version The version of that id. + * @param quietOperation Optional parameter to turn off printouts. This is useful for unittests. + */ + PeriodicCounterSelectionResponseHandler(uint32_t packetId, uint32_t version, bool quietOperation = true) + : CommandHandlerFunctor(packetId, version) + , m_QuietOperation(quietOperation) + {} + + void operator()(const armnn::profiling::Packet& packet) override; + +private: + bool m_QuietOperation; +}; + +} // namespace gatordmock + +} // namespace armnn \ No newline at end of file diff --git a/tests/profiling/gatordmock/tests/GatordMockTests.cpp b/tests/profiling/gatordmock/tests/GatordMockTests.cpp index a6297e9..3f58f39 100644 --- a/tests/profiling/gatordmock/tests/GatordMockTests.cpp +++ b/tests/profiling/gatordmock/tests/GatordMockTests.cpp @@ -4,7 +4,6 @@ // #include "../GatordMockService.hpp" -#include "../MockUtils.hpp" #include "../PeriodicCounterCaptureCommandHandler.hpp" #include @@ -25,12 +24,22 @@ using namespace std::chrono_literals; // Required so build succeeds when local variable used only in assert #define _unused(x) ((void)(x)) +uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetClass, uint32_t packetType) +{ + return ((packetFamily & 0x3F) << 26) | ((packetClass & 0x3FF) << 19) | ((packetType & 0x3FFF) << 16); +} + +uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetId) +{ + return ((packetFamily & 0x3F) << 26) | ((packetId & 0x3FF) << 16); +} + BOOST_AUTO_TEST_CASE(CounterCaptureHandlingTest) { using boost::numeric_cast; // Initialise functors and register into the CommandHandlerRegistry - uint32_t headerWord1 = gatordmock::ConstructHeader(1, 0, 0); + uint32_t headerWord1 = ConstructHeader(1, 0, 0); // Create the Command Handler Registry profiling::CommandHandlerRegistry registry; @@ -56,10 +65,10 @@ BOOST_AUTO_TEST_CASE(CounterCaptureHandlingTest) // UniqueData required for Packet class std::unique_ptr uniqueData1 = std::make_unique(dataLength); - unsigned char* data1 = reinterpret_cast(uniqueData1.get()); + unsigned char* data1 = reinterpret_cast(uniqueData1.get()); std::unique_ptr uniqueData2 = std::make_unique(dataLength); - unsigned char* data2 = reinterpret_cast(uniqueData2.get()); + unsigned char* data2 = reinterpret_cast(uniqueData2.get()); uint32_t sizeOfUint64 = numeric_cast(sizeof(uint64_t)); uint32_t sizeOfUint32 = numeric_cast(sizeof(uint32_t)); @@ -94,7 +103,7 @@ BOOST_AUTO_TEST_CASE(CounterCaptureHandlingTest) profiling::Packet packet2(headerWord1, dataLength, uniqueData2); uint32_t version = 1; - gatordmock::PeriodicCounterCaptureCommandHandler commandHandler(headerWord1, version, false); + gatordmock::PeriodicCounterCaptureCommandHandler commandHandler(headerWord1, version, true); // Simulate two separate packets coming in to calculate period commandHandler(packet1); @@ -114,14 +123,14 @@ BOOST_AUTO_TEST_CASE(GatorDMockEndToEnd) // performance data. // Initialise functors and register into the CommandHandlerRegistry - uint32_t counterCaptureHeader = gatordmock::ConstructHeader(1, 0); + uint32_t counterCaptureHeader = ConstructHeader(1, 0); uint32_t version = 1; // Create the Command Handler Registry profiling::CommandHandlerRegistry registry; // Update with derived functors - gatordmock::PeriodicCounterCaptureCommandHandler counterCaptureCommandHandler(counterCaptureHeader, version, false); + gatordmock::PeriodicCounterCaptureCommandHandler counterCaptureCommandHandler(counterCaptureHeader, version, true); // Register different derived functors registry.RegisterFunctor(&counterCaptureCommandHandler);