From 43a799ca3ab5ffb60a381172dba2536ebb87708a Mon Sep 17 00:00:00 2001 From: Kevin May Date: Fri, 8 Feb 2019 16:31:42 +0000 Subject: IVGCVSW-2581 Create Deserializer * Add deserialize parser for input, output and add layers * Add Unit Tests for simple network Change-Id: Ia0e2a234896bbe401ed0da5f18c065cb5df51bfb Signed-off-by: Kevin May Signed-off-by: Saoirse Stewart --- src/armnnDeserializeParser/DeserializeParser.hpp | 98 ++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/armnnDeserializeParser/DeserializeParser.hpp (limited to 'src/armnnDeserializeParser/DeserializeParser.hpp') diff --git a/src/armnnDeserializeParser/DeserializeParser.hpp b/src/armnnDeserializeParser/DeserializeParser.hpp new file mode 100644 index 0000000000..322826c762 --- /dev/null +++ b/src/armnnDeserializeParser/DeserializeParser.hpp @@ -0,0 +1,98 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include "armnn/INetwork.hpp" +#include "armnnDeserializeParser/IDeserializeParser.hpp" +#include + +namespace armnnDeserializeParser +{ +class DeserializeParser : public IDeserializeParser +{ +public: + // Shorthands for deserializer types + using GraphPtr = const armnn::armnnSerializer::SerializedGraph *; + using TensorRawPtr = const armnn::armnnSerializer::TensorInfo *; + using TensorRawPtrVector = std::vector; + using LayerRawPtr = const armnn::armnnSerializer::LayerBase *; + using LayerBaseRawPtr = const armnn::armnnSerializer::LayerBase *; + using LayerBaseRawPtrVector = std::vector; + +public: + + /// Create the network from a flatbuffers binary file on disk + virtual armnn::INetworkPtr CreateNetworkFromBinaryFile(const char* graphFile) override; + + virtual armnn::INetworkPtr CreateNetworkFromBinary(const std::vector& binaryContent) override; + + /// Retrieve binding info (layer id and tensor info) for the network input identified by the given layer name + virtual BindingPointInfo GetNetworkInputBindingInfo(unsigned int layerId, + const std::string& name) const override; + + /// Retrieve binding info (layer id and tensor info) for the network output identified by the given layer name + virtual BindingPointInfo GetNetworkOutputBindingInfo(unsigned int layerId, + const std::string& name) const override; + + DeserializeParser(); + ~DeserializeParser() {} + +public: + // testable helpers + static GraphPtr LoadGraphFromFile(const char* fileName); + static GraphPtr LoadGraphFromBinary(const uint8_t* binaryContent, size_t len); + static TensorRawPtrVector GetInputs(const GraphPtr& graph, unsigned int layerIndex); + static TensorRawPtrVector GetOutputs(const GraphPtr& graph, unsigned int layerIndex); + static LayerBaseRawPtrVector GetGraphInputs(const GraphPtr& graphPtr); + static LayerBaseRawPtrVector GetGraphOutputs(const GraphPtr& graphPtr); + static LayerBaseRawPtr GetBaseLayer(const GraphPtr& graphPtr, unsigned int layerIndex); + static int32_t GetBindingLayerInfo(const GraphPtr& graphPtr, unsigned int layerIndex); + +private: + // No copying allowed until it is wanted and properly implemented + DeserializeParser(const DeserializeParser&) = delete; + DeserializeParser& operator=(const DeserializeParser&) = delete; + + /// Create the network from an already loaded flatbuffers graph + armnn::INetworkPtr CreateNetworkFromGraph(); + + // signature for the parser functions + using LayerParsingFunction = void(DeserializeParser::*)(unsigned int layerIndex); + + void ParseUnsupportedLayer(unsigned int serializeGraphIndex); + void ParseAdd(unsigned int serializeGraphIndex); + + void RegisterOutputSlotOfConnection(uint32_t connectionIndex, armnn::IOutputSlot* slot); + void RegisterInputSlotOfConnection(uint32_t connectionIndex, armnn::IInputSlot* slot); + void RegisterInputSlots(uint32_t layerIndex, + armnn::IConnectableLayer* layer); + void RegisterOutputSlots(uint32_t layerIndex, + armnn::IConnectableLayer* layer); + void ResetParser(); + + void SetupInputLayers(); + void SetupOutputLayers(); + + /// The network we're building. Gets cleared after it is passed to the user + armnn::INetworkPtr m_Network; + GraphPtr m_Graph; + std::vector m_ParserFunctions; + + /// A mapping of an output slot to each of the input slots it should be connected to + /// The outputSlot is from the layer that creates this tensor as one of its outputs + /// The inputSlots are from the layers that use this tensor as one of their inputs + struct Slots + { + armnn::IOutputSlot* outputSlot; + std::vector inputSlots; + + Slots() : outputSlot(nullptr) { } + }; + typedef std::vector Connection; + std::vector m_GraphConnections; +}; + +} -- cgit v1.2.1