diff options
author | Mike Kelly <mike.kelly@arm.com> | 2019-02-11 17:01:27 +0000 |
---|---|---|
committer | Mike Kelly <mike.kelly@arm.com> | 2019-02-11 17:01:27 +0000 |
commit | 8c1701a2d9c1da0e1decb2afdc2093aa88810242 (patch) | |
tree | 870ee9af506bb468c513214ab539f41aeb1e34dc /src/armnnSerializer/Serializer.hpp | |
parent | a40521a70e73d20a060fa2df0e83b02c4f1c6139 (diff) | |
download | armnn-8c1701a2d9c1da0e1decb2afdc2093aa88810242.tar.gz |
IVGCVSW-2531 Serialize a simple ArmNN Network
Change-Id: I68cf5072aca6e3a8b3b8c57e19b6d417cd5813fc
Signed-off-by: Mike Kelly <mike.kelly@arm.com>
Diffstat (limited to 'src/armnnSerializer/Serializer.hpp')
-rw-r--r-- | src/armnnSerializer/Serializer.hpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/armnnSerializer/Serializer.hpp b/src/armnnSerializer/Serializer.hpp new file mode 100644 index 0000000000..697e5cfaa7 --- /dev/null +++ b/src/armnnSerializer/Serializer.hpp @@ -0,0 +1,72 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// +#pragma once + +#include <armnn/ILayerVisitor.hpp> +#include <armnn/LayerVisitorBase.hpp> +#include <iostream> +#include <Schema_generated.h> + +namespace armnnSerializer +{ + +class Serializer : public armnn::LayerVisitorBase<armnn::VisitorNoThrowPolicy> +{ +public: + Serializer() {}; + ~Serializer() {}; + + void VisitAdditionLayer(const armnn::IConnectableLayer* layer, + const char* name = nullptr) override; + + void VisitInputLayer(const armnn::IConnectableLayer* layer, + armnn::LayerBindingId id, + const char* name = nullptr) override; + + void VisitOutputLayer(const armnn::IConnectableLayer* layer, + armnn::LayerBindingId id, + const char* name = nullptr) override; + + /// Serializes the network to ArmNN SerializedGraph. + /// @param [in] inNetwork The network to be serialized. + void Serialize(const armnn::INetwork& inNetwork); + + /// Serializes the SerializedGraph to the stream. + /// @param [stream] the stream to save to + /// @return true if graph is Serialized to the Stream, false otherwise + bool SaveSerializedToStream(std::ostream& stream); + +private: + + /// Creates the Input Slots and Output Slots and LayerBase for the layer. + flatbuffers::Offset<armnn::armnnSerializer::LayerBase> CreateLayerBase( + const armnn::IConnectableLayer* layer, + const armnn::armnnSerializer::LayerType layerType); + + /// Creates the serializer AnyLayer for the layer and adds it to m_serializedLayers. + void CreateAnyLayer(const flatbuffers::Offset<void>& layer, const armnn::armnnSerializer::Layer serializerLayer); + + /// Creates the serializer InputSlots for the layer. + std::vector<flatbuffers::Offset<armnn::armnnSerializer::InputSlot>> CreateInputSlots( + const armnn::IConnectableLayer* layer); + + /// Creates the serializer OutputSlots for the layer. + std::vector<flatbuffers::Offset<armnn::armnnSerializer::OutputSlot>> CreateOutputSlots( + const armnn::IConnectableLayer* layer); + + /// FlatBufferBuilder to create our layers' FlatBuffers. + flatbuffers::FlatBufferBuilder m_flatBufferBuilder; + + /// AnyLayers required by the SerializedGraph. + std::vector<flatbuffers::Offset<armnn::armnnSerializer::AnyLayer>> m_serializedLayers; + + /// Guids of all Input Layers required by the SerializedGraph. + std::vector<unsigned int> m_inputIds; + + /// Guids of all Output Layers required by the SerializedGraph. + std::vector<unsigned int> m_outputIds; +}; + +} //namespace armnnSerializer |