310 TEST_CASE(
"LSTMValidateTensorShapesFromInputsCIFGDisabledTest")
315 CreateLSTMLayerHelper(graph,
false);
321 TEST_CASE(
"LSTMValidateTensorShapesFromInputsCIFGEnabledTest")
326 CreateLSTMLayerHelper(graph,
true);
332 TEST_CASE(
"InsertConvertersTest")
346 ->GetOutputHandler().SetTensorInfo(info);
355 ->GetOutputHandler().SetTensorInfo(info);
360 &IsLayerOfType<armnn::InputLayer>,
361 &IsLayerOfType<armnn::InputLayer>,
362 &IsLayerOfType<armnn::MemCopyLayer>,
363 &IsLayerOfType<armnn::FloorLayer>,
364 &IsLayerOfType<armnn::AdditionLayer>,
365 &IsLayerOfType<armnn::OutputLayer>));
368 for (
auto& layer : graph)
378 for (
auto& layer : graph)
388 for (
auto& layer : graph)
410 &IsLayerOfType<armnn::InputLayer>,
411 &IsLayerOfType<armnn::InputLayer>,
412 &IsLayerOfType<armnn::ConvertFp16ToFp32Layer>,
413 &IsLayerOfType<armnn::MemCopyLayer>,
414 &IsLayerOfType<armnn::ConvertFp16ToFp32Layer>,
415 &IsLayerOfType<armnn::FloorLayer>,
416 &IsLayerOfType<armnn::ConvertFp32ToFp16Layer>,
417 &IsLayerOfType<armnn::ConvertFp16ToFp32Layer>,
418 &IsLayerOfType<armnn::AdditionLayer>,
419 &IsLayerOfType<armnn::ConvertFp32ToFp16Layer>,
420 &IsLayerOfType<armnn::OutputLayer>));
423 void CreateConvolution2dGraph(
Graph &graph,
const unsigned int* inputShape,
424 const unsigned int* weightsShape,
const unsigned int* outputShape,
430 std::vector<float> weightsVector(90);
446 weightsLayer->
m_LayerOutput = std::make_shared<ScopedTensorHandle>(weights);
450 layer->
m_Weight = std::make_unique<armnn::ScopedTensorHandle>(weights);
459 TEST_CASE(
"Conv2dValidateTensorShapesFromInputs")
462 const unsigned int inputShape[] = { 1, 3, 8, 16 };
463 const unsigned int weightsShape[] = { 2, 3, 5, 3 };
464 const unsigned int outputShape[] = { 1, 2, 4, 14 };
465 CreateConvolution2dGraph(graph, inputShape, weightsShape, outputShape);
470 TEST_CASE(
"Conv2dValidateTensorShapesFromInputsNhwc")
473 const unsigned int inputShape[] = { 1, 8, 16, 3 };
474 const unsigned int weightsShape[] = { 2, 5, 3, 3 };
475 const unsigned int outputShape[] = { 1, 4, 14, 2 };
476 CreateConvolution2dGraph(graph, inputShape, weightsShape, outputShape,
DataLayout::NHWC);
481 void CreateDepthwiseConvolution2dGraph(
Graph &graph,
const unsigned int* inputShape,
482 const unsigned int* weightsShape,
const unsigned int* outputShape,
489 std::vector<float> weightsVector(18);
504 layer->GetOutputSlot().SetTensorInfo(outputInfo);
505 weightsLayer->GetOutputSlot().SetTensorInfo(weightsInfo);
507 weightsLayer->m_LayerOutput = std::make_unique<armnn::ScopedTensorHandle>(weights);
510 weightsLayer->GetOutputSlot().Connect(layer->GetInputSlot(1));
511 layer->GetOutputSlot().Connect(output->GetInputSlot(0));
514 TEST_CASE(
"DepthwiseConv2dValidateTensorShapesFromInputs")
517 const unsigned int inputShape[] = { 1, 2, 3, 3 };
518 const unsigned int weightsShape[] = { 1, 3, 3, 2 };
519 const unsigned int outputShape[] = { 1, 2, 1, 1 };
520 CreateDepthwiseConvolution2dGraph(graph, inputShape, weightsShape, outputShape);
525 TEST_CASE(
"DepthwiseConv2dValidateTensorShapesFromInputsNhwc")
528 const unsigned int inputShape[] = { 1, 3, 3, 2 };
529 const unsigned int weightsShape[] = { 1, 3, 3, 2 };
530 const unsigned int outputShape[] = { 1, 1, 1, 2 };
531 CreateDepthwiseConvolution2dGraph(graph, inputShape, weightsShape, outputShape,
DataLayout::NHWC);
536 void CreatePooling2dGraph(
Graph& graph,
const unsigned int* inputShape,
const unsigned int* outputShape,
564 TEST_CASE(
"Pooling2dValidateTensorShapesFromInputs")
567 const unsigned int inputShape[] = { 5, 3, 52, 60 };
568 const unsigned int outputShape[] = { 5, 3, 11, 13 };
574 TEST_CASE(
"Pooling2dValidateTensorShapesFromInputsNhwc")
577 const unsigned int inputShape[] = { 5, 52, 60, 3 };
578 const unsigned int outputShape[] = { 5, 11, 13, 3 };
584 void CreateResizeBilinearGraph(
Graph& graph,
585 const unsigned int* inputShape,
586 const unsigned int* outputShape,
609 TEST_CASE(
"ResizeBilinearValidateTensorShapesFromInputs")
612 const unsigned int inputShape[] = { 1, 2, 4, 5 };
613 const unsigned int outputShape[] = { 1, 2, 3, 4 };
614 CreateResizeBilinearGraph(graph, inputShape, outputShape);
619 TEST_CASE(
"ResizeBilinearValidateTensorShapesFromInputsNhwc")
622 const unsigned int inputShape[] = { 1, 4, 5, 2 };
623 const unsigned int outputShape[] = { 1, 3, 4, 2 };
624 CreateResizeBilinearGraph(graph, inputShape, outputShape,
DataLayout::NHWC);
629 void CreateGatherGraph(
Graph& graph,
650 TEST_CASE(
"GatherValidateTensorShapesFromInputs")
657 CreateGatherGraph(graph, paramsInfo, indicesInfo, outputInfo);
662 TEST_CASE(
"GatherValidateTensorShapesFromInputs1DParams")
669 CreateGatherGraph(graph, paramsInfo, indicesInfo, outputInfo);
674 TEST_CASE(
"GatherValidateTensorShapesFromInputsMultiDimIndices")
681 CreateGatherGraph(graph, paramsInfo, indicesInfo, outputInfo);
686 TEST_CASE(
"DetectionPostProcessValidateTensorShapes")
691 std::vector<uint8_t> anchorsVector(40);
709 layer->
m_Anchors = std::make_unique<armnn::ScopedTensorHandle>(anchors);
715 input0->GetOutputSlot().Connect(layer->
GetInputSlot(0));
721 TEST_CASE(
"BackendCapabilityTest")
735 TEST_CASE(
"BackendHintTest")
737 class TestBackendAssignment :
public StrategyBase<NoThrowStrategy>
743 const std::vector<armnn::ConstTensor>& constants,
752 auto inputLayer = PolymorphicDowncast<const InputLayer*>(layer);
753 const auto connectedLayerBackendId = inputLayer->GetOutputSlot(0).GetOwningLayer().GetBackendId();
754 CHECK((inputLayer->GetBackendId() == connectedLayerBackendId));
759 auto outputLayer = PolymorphicDowncast<const OutputLayer*>(layer);
760 CHECK((outputLayer->GetBackendId() ==
"MockBackend"));
765 auto activation = PolymorphicDowncast<const ActivationLayer*>(layer);
766 CHECK((activation->GetBackendId() ==
"CustomBackend"));
797 backendRegistry.Register(
"MockBackend", []() {
return std::make_unique<CustomAllocatorBackend<MockPolicy>>(); });
799 backendRegistry.Register(
"CustomBackend",
800 []() {
return std::make_unique<CustomAllocatorBackend<CustomPolicy>>(); });
807 std::unique_ptr<Graph> graph = std::make_unique<Graph>();
808 auto input = graph->AddLayer<
InputLayer>(0,
"input");
810 auto output = graph->AddLayer<
OutputLayer>(0,
"output");
812 BackendId customBackendId(
"CustomBackend");
821 Graph& optGraph = optNet.GetGraph();
823 std::vector<BackendId> prefs{
"MockBackend",
"CustomBackend" };
825 BackendIdSet availableBackends = {
"CustomBackend",
"MockBackend" };
843 TestBackendAssignment visitor;
844 for (
auto it = firstLayer; it != lastLayer; ++it)
846 (*it)->ExecuteStrategy(visitor);
849 backendRegistry.Deregister(
"MockBackend");
850 backendRegistry.Deregister(
"CustomBackend");
854 TEST_CASE(
"OptimizeForExclusiveConnectionsFuseTest")
856 using namespace armnn;
864 const unsigned int inputDimensionSizes[] = { 1, 4, 4, 3 };
865 const unsigned int weightsDimensionSizes[] = { 1, 2, 2, 3 };
866 const unsigned int outputDimensionSizes[] = { 1, 3, 3, 1 };
867 const unsigned int outputChannelSize[] = { outputDimensionSizes[3] };
872 std::vector<float> weightsVector = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
875 std::vector<float> betaVector = { 0.1f };
876 std::vector<float> gammaVector = { 0.5f };
877 std::vector<float> meanVector = { 0 };
878 std::vector<float> varianceVector = { 1 };
897 weightsLayer->m_LayerOutput = std::make_shared<ScopedTensorHandle>(weights);
902 batchNorm->m_Beta = std::make_unique<ScopedTensorHandle>(beta);
903 batchNorm->m_Gamma = std::make_unique<ScopedTensorHandle>(gamma);
904 batchNorm->m_Mean = std::make_unique<ScopedTensorHandle>(mean);
905 batchNorm->m_Variance = std::make_unique<ScopedTensorHandle>(variance);
907 if (convolution2dDescriptor.m_BiasEnabled)
909 std::vector<float> biasVector = { 11 };
912 biasLayer->
m_LayerOutput = std::make_shared<ScopedTensorHandle>(bias);
925 conv->m_Weight = weightsLayer->m_LayerOutput;
927 if (convolution2dDescriptor.m_BiasEnabled)
931 &IsLayerOfType<InputLayer>,
932 &IsLayerOfType<ConstantLayer>,
933 &IsLayerOfType<ConstantLayer>,
934 &IsLayerOfType<Convolution2dLayer>,
935 &IsLayerOfType<BatchNormalizationLayer>,
936 &IsLayerOfType<OutputLayer>));
942 &IsLayerOfType<InputLayer>,
943 &IsLayerOfType<ConstantLayer>,
944 &IsLayerOfType<Convolution2dLayer>,
945 &IsLayerOfType<BatchNormalizationLayer>,
946 &IsLayerOfType<OutputLayer>));
952 auto checkFusedConv2d = [](
const armnn::Layer*
const layer) ->
bool {
953 return IsLayerOfType<armnn::Convolution2dLayer>(layer) &&
954 (layer->GetNameStr() ==
"fused-batchNorm-into-convolution");
959 &IsLayerOfType<InputLayer>,
960 &IsLayerOfType<ConstantLayer>,
961 &IsLayerOfType<ConstantLayer>,
963 &IsLayerOfType<OutputLayer>));
967 TEST_CASE(
"OptimizeForExclusiveConnectionsWithoutFuseTest")
988 &IsLayerOfType<armnn::InputLayer>,
989 &IsLayerOfType<armnn::Convolution2dLayer>,
990 &IsLayerOfType<armnn::BatchNormalizationLayer>,
991 &IsLayerOfType<armnn::OutputLayer>,
992 &IsLayerOfType<armnn::OutputLayer>));
998 &IsLayerOfType<armnn::InputLayer>,
999 &IsLayerOfType<armnn::Convolution2dLayer>,
1000 &IsLayerOfType<armnn::BatchNormalizationLayer>,
1001 &IsLayerOfType<armnn::OutputLayer>,
1002 &IsLayerOfType<armnn::OutputLayer>));
A layer that the constant data can be bound to.
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)
bool CheckSequence(const armnn::Graph::ConstIterator first, const armnn::Graph::ConstIterator last)
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.
std::shared_ptr< ConstTensorHandle > m_LayerOutput
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.
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.
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.