287 TEST_CASE(
"LSTMValidateTensorShapesFromInputsCIFGDisabledTest")
292 CreateLSTMLayerHelper(graph,
false);
298 TEST_CASE(
"LSTMValidateTensorShapesFromInputsCIFGEnabledTest")
303 CreateLSTMLayerHelper(graph,
true);
309 TEST_CASE(
"InsertConvertersTest")
323 ->GetOutputHandler().SetTensorInfo(info);
332 ->GetOutputHandler().SetTensorInfo(info);
337 &IsLayerOfType<armnn::InputLayer>,
338 &IsLayerOfType<armnn::InputLayer>,
339 &IsLayerOfType<armnn::MemCopyLayer>,
340 &IsLayerOfType<armnn::FloorLayer>,
341 &IsLayerOfType<armnn::AdditionLayer>,
342 &IsLayerOfType<armnn::OutputLayer>));
345 for (
auto& layer : graph)
355 for (
auto& layer : graph)
365 for (
auto& layer : graph)
387 &IsLayerOfType<armnn::InputLayer>,
388 &IsLayerOfType<armnn::InputLayer>,
389 &IsLayerOfType<armnn::ConvertFp16ToFp32Layer>,
390 &IsLayerOfType<armnn::MemCopyLayer>,
391 &IsLayerOfType<armnn::ConvertFp16ToFp32Layer>,
392 &IsLayerOfType<armnn::FloorLayer>,
393 &IsLayerOfType<armnn::ConvertFp32ToFp16Layer>,
394 &IsLayerOfType<armnn::ConvertFp16ToFp32Layer>,
395 &IsLayerOfType<armnn::AdditionLayer>,
396 &IsLayerOfType<armnn::ConvertFp32ToFp16Layer>,
397 &IsLayerOfType<armnn::OutputLayer>));
400 void CreateConvolution2dGraph(
Graph &graph,
const unsigned int* inputShape,
401 const unsigned int* weightsShape,
const unsigned int* outputShape,
407 std::vector<float> weightsVector(90);
422 layer->
m_Weight = std::make_unique<armnn::ScopedTensorHandle>(weights);
430 TEST_CASE(
"Conv2dValidateTensorShapesFromInputs")
433 const unsigned int inputShape[] = { 1, 3, 8, 16 };
434 const unsigned int weightsShape[] = { 2, 3, 5, 3 };
435 const unsigned int outputShape[] = { 1, 2, 4, 14 };
436 CreateConvolution2dGraph(graph, inputShape, weightsShape, outputShape);
441 TEST_CASE(
"Conv2dValidateTensorShapesFromInputsNhwc")
444 const unsigned int inputShape[] = { 1, 8, 16, 3 };
445 const unsigned int weightsShape[] = { 2, 5, 3, 3 };
446 const unsigned int outputShape[] = { 1, 4, 14, 2 };
447 CreateConvolution2dGraph(graph, inputShape, weightsShape, outputShape,
DataLayout::NHWC);
452 void CreateDepthwiseConvolution2dGraph(
Graph &graph,
const unsigned int* inputShape,
453 const unsigned int* weightsShape,
const unsigned int* outputShape,
459 std::vector<float> weightsVector(18);
474 layer->
m_Weight = std::make_unique<armnn::ScopedTensorHandle>(weights);
482 TEST_CASE(
"DepthwiseConv2dValidateTensorShapesFromInputs")
485 const unsigned int inputShape[] = { 1, 2, 3, 3 };
486 const unsigned int weightsShape[] = { 1, 3, 3, 2 };
487 const unsigned int outputShape[] = { 1, 2, 1, 1 };
488 CreateDepthwiseConvolution2dGraph(graph, inputShape, weightsShape, outputShape);
493 TEST_CASE(
"DepthwiseConv2dValidateTensorShapesFromInputsNhwc")
496 const unsigned int inputShape[] = { 1, 3, 3, 2 };
497 const unsigned int weightsShape[] = { 1, 3, 3, 2 };
498 const unsigned int outputShape[] = { 1, 1, 1, 2 };
499 CreateDepthwiseConvolution2dGraph(graph, inputShape, weightsShape, outputShape,
DataLayout::NHWC);
504 void CreatePooling2dGraph(
Graph& graph,
const unsigned int* inputShape,
const unsigned int* outputShape,
532 TEST_CASE(
"Pooling2dValidateTensorShapesFromInputs")
535 const unsigned int inputShape[] = { 5, 3, 52, 60 };
536 const unsigned int outputShape[] = { 5, 3, 11, 13 };
542 TEST_CASE(
"Pooling2dValidateTensorShapesFromInputsNhwc")
545 const unsigned int inputShape[] = { 5, 52, 60, 3 };
546 const unsigned int outputShape[] = { 5, 11, 13, 3 };
552 void CreateResizeBilinearGraph(
Graph& graph,
553 const unsigned int* inputShape,
554 const unsigned int* outputShape,
577 TEST_CASE(
"ResizeBilinearValidateTensorShapesFromInputs")
580 const unsigned int inputShape[] = { 1, 2, 4, 5 };
581 const unsigned int outputShape[] = { 1, 2, 3, 4 };
582 CreateResizeBilinearGraph(graph, inputShape, outputShape);
587 TEST_CASE(
"ResizeBilinearValidateTensorShapesFromInputsNhwc")
590 const unsigned int inputShape[] = { 1, 4, 5, 2 };
591 const unsigned int outputShape[] = { 1, 3, 4, 2 };
592 CreateResizeBilinearGraph(graph, inputShape, outputShape,
DataLayout::NHWC);
597 void CreateGatherGraph(
Graph& graph,
618 TEST_CASE(
"GatherValidateTensorShapesFromInputs")
625 CreateGatherGraph(graph, paramsInfo, indicesInfo, outputInfo);
630 TEST_CASE(
"GatherValidateTensorShapesFromInputs1DParams")
637 CreateGatherGraph(graph, paramsInfo, indicesInfo, outputInfo);
642 TEST_CASE(
"GatherValidateTensorShapesFromInputsMultiDimIndices")
649 CreateGatherGraph(graph, paramsInfo, indicesInfo, outputInfo);
654 TEST_CASE(
"DetectionPostProcessValidateTensorShapes")
659 std::vector<uint8_t> anchorsVector(40);
677 layer->
m_Anchors = std::make_unique<armnn::ScopedTensorHandle>(anchors);
683 input0->GetOutputSlot().Connect(layer->
GetInputSlot(0));
689 TEST_CASE(
"BackendCapabilityTest")
703 TEST_CASE(
"BackendHintTest")
705 class TestBackendAssignment :
public StrategyBase<NoThrowStrategy>
711 const std::vector<armnn::ConstTensor>& constants,
720 auto inputLayer = PolymorphicDowncast<const InputLayer*>(layer);
721 const auto connectedLayerBackendId = inputLayer->GetOutputSlot(0).GetOwningLayer().GetBackendId();
722 CHECK((inputLayer->GetBackendId() == connectedLayerBackendId));
727 auto outputLayer = PolymorphicDowncast<const OutputLayer*>(layer);
728 CHECK((outputLayer->GetBackendId() ==
"MockBackend"));
733 auto activation = PolymorphicDowncast<const ActivationLayer*>(layer);
734 CHECK((activation->GetBackendId() ==
"CustomBackend"));
765 backendRegistry.Register(
"MockBackend", []() {
return std::make_unique<MockBackend<MockPolicy>>(); });
767 backendRegistry.Register(
"CustomBackend", []() {
return std::make_unique<MockBackend<CustomPolicy>>(); });
774 std::unique_ptr<Graph> graph = std::make_unique<Graph>();
775 auto input = graph->AddLayer<
InputLayer>(0,
"input");
777 auto output = graph->AddLayer<
OutputLayer>(0,
"output");
779 BackendId customBackendId(
"CustomBackend");
788 Graph& optGraph = optNet.GetGraph();
790 std::vector<BackendId> prefs{
"MockBackend",
"CustomBackend" };
792 BackendIdSet availableBackends = {
"CustomBackend",
"MockBackend" };
810 TestBackendAssignment visitor;
811 for (
auto it = firstLayer; it != lastLayer; ++it)
813 (*it)->ExecuteStrategy(visitor);
816 backendRegistry.Deregister(
"MockBackend");
817 backendRegistry.Deregister(
"CustomBackend");
821 TEST_CASE(
"OptimizeForExclusiveConnectionsFuseTest")
823 using namespace armnn;
831 const unsigned int inputDimensionSizes[] = { 1, 4, 4, 3 };
832 const unsigned int weightsDimensionSizes[] = { 1, 2, 2, 3 };
833 const unsigned int outputDimensionSizes[] = { 1, 3, 3, 1 };
834 const unsigned int outputChannelSize[] = { outputDimensionSizes[3] };
839 std::vector<float> weightsVector = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
842 std::vector<float> betaVector = { 0.1f };
843 std::vector<float> gammaVector = { 0.5f };
844 std::vector<float> meanVector = { 0 };
845 std::vector<float> varianceVector = { 1 };
862 conv->m_Weight = std::make_unique<ScopedTensorHandle>(weights);
863 batchNorm->m_Beta = std::make_unique<ScopedTensorHandle>(beta);
864 batchNorm->m_Gamma = std::make_unique<ScopedTensorHandle>(gamma);
865 batchNorm->m_Mean = std::make_unique<ScopedTensorHandle>(mean);
866 batchNorm->m_Variance = std::make_unique<ScopedTensorHandle>(variance);
867 if (convolution2dDescriptor.m_BiasEnabled)
869 std::vector<float> biasVector = { 11 };
871 conv->m_Bias = std::make_unique<ScopedTensorHandle>(bias);
881 &IsLayerOfType<InputLayer>,
882 &IsLayerOfType<Convolution2dLayer>,
883 &IsLayerOfType<BatchNormalizationLayer>,
884 &IsLayerOfType<OutputLayer>));
889 auto checkFusedConv2d = [](
const armnn::Layer*
const layer) ->
bool {
890 return IsLayerOfType<armnn::Convolution2dLayer>(layer) &&
891 (layer->GetNameStr() ==
"fused-batchNorm-into-convolution");
896 &IsLayerOfType<InputLayer>,
898 &IsLayerOfType<OutputLayer>));
902 TEST_CASE(
"OptimizeForExclusiveConnectionsWithoutFuseTest")
923 &IsLayerOfType<armnn::InputLayer>,
924 &IsLayerOfType<armnn::Convolution2dLayer>,
925 &IsLayerOfType<armnn::BatchNormalizationLayer>,
926 &IsLayerOfType<armnn::OutputLayer>,
927 &IsLayerOfType<armnn::OutputLayer>));
933 &IsLayerOfType<armnn::InputLayer>,
934 &IsLayerOfType<armnn::Convolution2dLayer>,
935 &IsLayerOfType<armnn::BatchNormalizationLayer>,
936 &IsLayerOfType<armnn::OutputLayer>,
937 &IsLayerOfType<armnn::OutputLayer>));
Iterator begin()
Returns iterator pointing to the beginning of the list. Lowercase for range-based for loops...
bool m_BiasEnabled
Enable/disable bias.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
OptimizationResult AssignBackends(OptimizedNetworkImpl *optNetObjPtr, BackendSettings &backendSettings, Graph::Iterator &firstLayer, Graph::Iterator &lastLayer, Optional< std::vector< std::string > &> errMessages)
bool HasCapability(const std::string &name, const BackendCapabilities &capabilities)
Convenience function to check if a capability exists in a BackendCapabilites struct.
This layer represents a batch normalization operation.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
uint32_t m_PadBottom
Padding bottom value in the height dimension.
std::vector< ConvertFp32ToFp16Layer * > InsertConvertFp32ToFp16LayersAfter(Graph &graph, Layer &layer)
bool m_BiasEnabled
Enable/disable bias.
std::vector< ConvertFp16ToFp32Layer * > InsertConvertFp16ToFp32LayersBefore(Graph &graph, Layer &layer, bool expectCorrectInputType)
uint32_t m_PadLeft
Padding left value in the width dimension.
Optimizer::Optimizations MakeOptimizations(Args &&... args)
std::unordered_set< BackendId > BackendIdSet
void BackendSelectionHint(Optional< BackendId > backend) final
Provide a hint for the optimizer as to which backend to prefer for this layer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
Optional< const BackendOptions::BackendOption > GetCapability(const std::string &backendCapabilityName, const BackendCapabilities &capabilities)
Returns a BackendCapability if the backend lists the capability The BackendCapability must then be in...
This layer represents a depthwise convolution 2d operation.
LayerT * AddLayer(Args &&... args)
Adds a new layer, of type LayerType, to the graph constructed with the arguments passed.
uint32_t m_PoolWidth
Pooling width value.
ConstIterator cbegin() const
Returns const iterator pointing to the beginning of the list. Lowercase for range-based for loops...
A Convolution2dDescriptor for the Convolution2dLayer.
int Connect(InputSlot &destination)
ResizeMethod m_Method
The Interpolation method to use (Bilinear, NearestNeighbor).
static void Pass(Graph &graph, const Optimizations &optimizations)
The padding fields don't count and are ignored.
PaddingMethod m_PaddingMethod
The padding method to be used. (Exclude, IgnoreValue).
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
OptimizeForExclusiveConnection< Convolution2dLayer, BatchNormalizationLayer, FuseBatchNorm< Convolution2dLayer, armnn::DataType::Float32 > > FuseBatchNormIntoConvolution2DFloat32
std::shared_ptr< ConstTensorHandle > m_Weight
A unique pointer to store Weight values.
This layer represents an activation operation with the specified activation function.
BackendRegistry & BackendRegistryInstance()
uint32_t m_PadTop
Padding top value in the height dimension.
This layer represents a detection postprocess operator.
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)
LayerList::const_iterator Iterator
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
A ResizeBilinearDescriptor for the ResizeBilinearLayer.
Base class for all descriptors.
Strategy base class with empty implementations.
uint32_t m_PoolHeight
Pooling height value.
uint32_t m_MaxDetections
Maximum numbers of detections.
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
A layer user-provided data can be bound to (e.g. inputs, outputs).
This layer represents a Gather operator.
uint32_t m_PadRight
Padding right value in the width dimension.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
uint32_t m_TargetWidth
Target width value.
A GatherDescriptor for the GatherLayer.
This layer represents a memory copy operation.
#define ARMNN_ASSERT(COND)
An ActivationDescriptor for the ActivationLayer.
This layer represents a floor operation.
uint32_t m_TargetHeight
Target height value.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
virtual LayerType GetType() const =0
Returns the armnn::LayerType of this layer.
This layer represents a pooling 2d operation.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
This layer represents an addition operation.
void SetTensorInfo(const TensorInfo &tensorInfo)
Sets the TensorInfo used by this output handler.
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
PoolingAlgorithm m_PoolType
The pooling algorithm to use (Max. Average, L2).
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
std::shared_ptr< ConstTensorHandle > m_Weight
A unique pointer to store Weight values.
const OutputHandler & GetOutputHandler(unsigned int i=0) const
Iterator end()
Returns iterator pointing to the end of the list. Lowercase for range-based for loops.
bool CheckSequence(const armnn::Graph::ConstIterator first, const armnn::Graph::ConstIterator last)
void SetTensorInfo(const TensorInfo &tensorInfo) override
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
ConstIterator cend() const
Returns const iterator pointing to the end of the list. Lowercase for range-based for loops...
This layer represents a convolution 2d operation.
A Pooling2dDescriptor for the Pooling2dLayer.
size_t GetNumLayers() const
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
std::shared_ptr< ConstTensorHandle > m_Anchors
A unique pointer to store Anchor values.
static INetworkPtr Create(NetworkOptions networkOptions={})
const char * GetLayerTypeAsCString(LayerType type)
ActivationFunction m_Function
The activation function to use (Sigmoid, TanH, Linear, ReLu, BoundedReLu, SoftReLu, LeakyReLu, Abs, Sqrt, Square, Elu).
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
This layer represents a resize operation.