Add serializer support

armnnSerializer is a library for serializing Arm NN neural networks, so that they require less memory.

To add a layer to the armnnSerializer library:

  1. Add the layer or operator to the schema file at armnn/src/armnnSerializer/ArmnnSchema.fbs. The following code shows this addition for an example SoftmaxLayer:
  2. //Softmax
    TABLE SOFTMAXLAYER {
        BASE:LAYERBASE;
        DESCRIPTOR:SOFTMAXDESCRIPTOR;
    }
    .
    .
    ENUM LAYERTYPE : UINT {
        ADDITION = 0,
        INPUT = 1,
        ...
        SOFTMAX = 6,
    }
    .
    .
    UNION LAYER {
        ACTIVATIONLAYER,
        ADDITIONLAYER,
        ...
        SOFTMAXLAYER
    }
  3. Declare and implement a Visit<LayerName>() function in armnn/src/armnnSerializer/Serializer.hpp and armnn/src/armnnSerializer/Serializer.cpp. This function serializes the layer and any other information that describes the layer, like the layers descriptor. The Arm NN Serializer uses the Visit<LayerName>() function to serialize the layer when it traverses the network graph. The following code shows this declaration and implementation for an example SoftmaxLayer in the Serializer.hpp file:
    void VisitSoftmaxLayer(const armnn::IConnectableLayer* layer,
                               const armnn::SoftmaxDescriptor& softmaxDescriptor,
                               const char* name = nullptr) override;

    The following code shows this declaration and implementation for an example SoftmaxLayer in the Serializer.cpp file:

    // Build FlatBuffer for Softmax Layer
    void SerializerVisitor::VisitSoftmaxLayer(const armnn::IConnectableLayer* layer,
                                              const armnn::SoftmaxDescriptor& softmaxDescriptor,
                                              const char* name)
    {
        IgnoreUnused(name);
    
        // Create FlatBuffer BaseLayer
        auto flatBufferSoftmaxBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Softmax);
    
        // Create the FlatBuffer SoftmaxDescriptor
        auto flatBufferSoftmaxDesc =
            serializer::CreateSoftmaxDescriptor(m_flatBufferBuilder, softmaxDescriptor.m_Beta);
    
        // Create the FlatBuffer SoftmaxLayer
        auto flatBufferSoftmaxLayer =
            serializer::CreateSoftmaxLayer(m_flatBufferBuilder,
                                           flatBufferSoftmaxBaseLayer,
                                           flatBufferSoftmaxDesc);
    
        CreateAnyLayer(flatBufferSoftmaxLayer.o, serializer::Layer::Layer_SoftmaxLayer);
    }
  4. Add the newly supported layer to the serializer documentation in src/armnnSerializer/SerializerSupport.md. The following code shows this documentation for an example SoftmaxLayer:
    The Arm NN SDK Serializer currently supports the following layers:
    *Abs
    ...
    *Softmax
    .
Previous Next