18 #include <doctest/doctest.h> 20 using namespace armnn;
24 unsigned int m_inputLayerCount = 0, m_outputLayerCount = 0, m_addLayerCount = 0;
25 for(
auto layer : graph)
27 switch(layer->GetType())
31 CHECK((layer->GetName() == std::string(
"inLayer0") ||
32 layer->GetName() == std::string(
"inLayer1")));
37 CHECK(std::string(layer->GetName()) ==
"pre-compiled");
41 CHECK(std::string(layer->GetName()) ==
"outLayer");
48 CHECK(m_inputLayerCount == 2);
49 CHECK(m_outputLayerCount == 1);
50 CHECK(m_addLayerCount == 1);
55 TEST_CASE(
"OptimizedViewsSubgraphLayerCount")
69 Layer*
const substitutableCompiledLayer =
75 weightsLayer1->GetOutputSlot(0).Connect(convLayer1->
GetInputSlot(1));
77 weightsLayer2->GetOutputSlot(0).Connect(convLayer2->GetInputSlot(1));
78 convLayer2->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0));
94 {substitutableCompiledLayer});
96 Graph substitutableGraph;
97 Layer*
const substitutionpreCompiledLayer =
98 substitutableGraph.AddLayer<
PreCompiledLayer>(substitutionLayerDescriptor,
"pre-compiled");
104 {substitutionpreCompiledLayer});
115 {substitutionpreCompiledLayer});
122 {convLayer1, convLayer2, substitutionpreCompiledLayer});
124 CHECK(view.
Validate(*originalSubgraph));
128 TEST_CASE(
"OptimizedViewsSubgraphLayerCountUsingGetINetwork")
139 Layer* convLayer1 = PolymorphicDowncast<Layer*>(
140 view.
GetINetwork()->AddDepthwiseConvolution2dLayer(convDescriptor,
143 Layer* convLayer2 = PolymorphicDowncast<Layer*>(
144 view.
GetINetwork()->AddDepthwiseConvolution2dLayer(convDescriptor,
151 convLayer2->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0));
164 Layer* substitutionpreCompiledLayer = PolymorphicDowncast<Layer*>(
165 net.AddPrecompiledLayer(substitutionLayerDescriptor, std::move(blobPtr), backend));
171 {substitutionpreCompiledLayer});
178 {substitutionpreCompiledLayer});
185 {convLayer1, convLayer2, substitutionpreCompiledLayer});
187 CHECK(view.
Validate(*originalSubgraph));
190 TEST_CASE(
"OptimizedViewsSubgraphLayerCountFailValidate")
204 Layer*
const substitutableCompiledLayer =
211 weightsLayer1->GetOutputSlot(0).Connect(convLayer1->
GetInputSlot(1));
213 weightsLayer2->GetOutputSlot(0).Connect(convLayer2->GetInputSlot(1));
214 convLayer2->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0));
225 {substitutableCompiledLayer});
227 Graph substitutableGraph;
228 Layer*
const substitutionpreCompiledLayer =
229 substitutableGraph.AddLayer<
PreCompiledLayer>(substitutionLayerDescriptor,
"pre-compiled");
235 {substitutionpreCompiledLayer});
245 {substitutionpreCompiledLayer});
252 {convLayer1, convLayer2, substitutionpreCompiledLayer});
255 CHECK(!view.
Validate(*originalSubgraph));
258 TEST_CASE(
"OptimizeViewsValidateDeviceMockBackend")
TEST_SUITE("TestConstTensorLayerVisitor")
A layer that the constant data can be bound to.
static IRuntimePtr Create(const CreationOptions &options)
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
CPU Execution: Reference C++ kernels.
LayerT * AddLayer(Args &&... args)
Adds a new layer, of type LayerType, to the graph constructed with the arguments passed.
A Convolution2dDescriptor for the Convolution2dLayer.
int Connect(InputSlot &destination)
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
void CheckLayers(Graph &graph)
void AddSubstitution(SubstitutionPair &&substitution)
Copyright (c) 2021 ARM Limited and Contributors.
Private implementation of INetwork.
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
std::unique_ptr< void, CompiledBlobDeleter > CompiledBlobPtr
The SubgraphView class represents a subgraph of a Graph.
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
A layer user-provided data can be bound to (e.g. inputs, outputs).
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
Create an optimized version of the network.
static const BackendId & GetIdStatic()
void AddFailedSubgraph(SubgraphView &&subgraph)
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
INetworkPtr & GetINetwork()
bool Validate(const SubgraphView &originalSubgraph) const
void AddUntouchedSubgraph(SubgraphView &&subgraph)
void SubstituteSubgraph(SubgraphView &subgraph, IConnectableLayer *substituteLayer)
Substitutes the given sub-graph with either a new layer or a new sub-graph.
Graph & GetGraphForTesting(IOptimizedNetwork *optNet)
std::unique_ptr< SubgraphView > SubgraphViewPtr
SubgraphView::SubgraphViewPtr CreateSubgraphViewFrom(SubgraphView::InputSlots &&inputs, SubgraphView::OutputSlots &&outputs, SubgraphView::Layers &&layers)
SubgraphView::OutputSlots CreateOutputsFrom(const std::vector< Layer *> &layers)
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
This layer represents a convolution 2d operation.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
virtual int Connect(IInputSlot &destination)=0
A PreCompiledDescriptor for the PreCompiledLayer.
static INetworkPtr Create(NetworkOptions networkOptions={})
SubgraphView::InputSlots CreateInputsFrom(Layer *layer, std::vector< unsigned int > ignoreSlots)
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.