6 #include <GraphUtils.hpp> 7 #include <TestUtils.hpp> 11 #include <doctest/doctest.h> 13 using namespace armnn;
17 #if defined(ARMCOMPUTENEON_ENABLED)||defined(ARMCOMPUTECL_ENABLED) 25 const std::string layerName(
"reduce_layer");
30 IConnectableLayer*
const reduceLayer = network->AddReduceLayer(reduceDescriptor, layerName.c_str());
44 void ReduceWithMultipleAxesTest(
INetworkPtr& network,
46 const std::vector<float>& inputData,
47 const std::vector<float>& expectedOutput,
48 const size_t numOfAxes,
60 CHECK(graph.GetNumLayers() == 5);
63 &IsLayerOfType<InputLayer>,
64 &IsLayerOfType<ReduceLayer>,
65 &IsLayerOfType<ReduceLayer>,
66 &IsLayerOfType<OutputLayer>,
67 &IsLayerOfType<OutputLayer>));
70 CHECK(graph.GetNumLayers() == 6);
73 &IsLayerOfType<InputLayer>,
74 &IsLayerOfType<ReduceLayer>,
75 &IsLayerOfType<ReduceLayer>,
76 &IsLayerOfType<ReduceLayer>,
77 &IsLayerOfType<OutputLayer>,
78 &IsLayerOfType<OutputLayer>));
82 std::string layerName =
"reduce_layer_" + std::to_string(numOfAxes - 1);
88 CHECK((reduceTensorInfo.GetShape() == outputShape));
93 run->LoadNetwork(networkIdentifier, std::move(optNet));
96 std::vector<float> outputData(expectedOutput.size());
97 armnn::TensorInfo inputTensorInfo = run->GetInputTensorInfo(networkIdentifier, 0);
105 {0,
armnn::Tensor(run->GetOutputTensorInfo(networkIdentifier, 0), outputData.data())},
106 {1,
armnn::Tensor(run->GetOutputTensorInfo(networkIdentifier, 1), outputData.data())}
110 run->EnqueueWorkload(networkIdentifier, inputTensors, outputTensors);
113 CHECK(outputData == expectedOutput);
116 void ReduceSumWithTwoAxesKeepDimsTest(
Compute backendId)
119 reduceDescriptor.
m_vAxis = {1, 2};
127 INetworkPtr network = CreateSimpleReduceNetwork(reduceDescriptor, inputShape, outputShape);
130 const std::vector<float> inputData({1.0f, 2.0f, 3.0f, 4.0f,
131 5.0f, 6.0f, 7.0f, 8.0f,
133 10.0f, 20.0f, 30.0f, 40.0f,
134 50.0f, 60.0f, 70.0f, 80.0f,
136 100.0f, 200.0f, 300.0f, 400.0f,
137 500.0f, 600.0f, 700.0f, 800.0f});
138 const std::vector<float> expectedOutput({666.0f, 888.0f, 1110.0f, 1332.0f});
140 ReduceWithMultipleAxesTest(network,
144 reduceDescriptor.
m_vAxis.size(),
148 void ReduceSumWithTwoAxesTest(
Compute backendId)
151 reduceDescriptor.
m_vAxis = {1, 2};
159 INetworkPtr network = CreateSimpleReduceNetwork(reduceDescriptor, inputShape, outputShape);
162 const std::vector<float> inputData({1.0f, 2.0f, 3.0f, 4.0f,
163 5.0f, 6.0f, 7.0f, 8.0f,
165 10.0f, 20.0f, 30.0f, 40.0f,
166 50.0f, 60.0f, 70.0f, 80.0f,
168 100.0f, 200.0f, 300.0f, 400.0f,
169 500.0f, 600.0f, 700.0f, 800.0f});
170 const std::vector<float> expectedOutput({666.0f, 888.0f, 1110.0f, 1332.0f});
172 ReduceWithMultipleAxesTest(network,
176 reduceDescriptor.
m_vAxis.size(),
180 void ReduceSumWithThreeAxesKeepDimsTest(
Compute backendId)
183 reduceDescriptor.
m_vAxis = {0, 2, 3};
191 INetworkPtr network = CreateSimpleReduceNetwork(reduceDescriptor, inputShape, outputShape);
194 const std::vector<float> inputData({1.0f, 2.0f,
205 const std::vector<float> expectedOutput({110.0f, 286.0f});
207 ReduceWithMultipleAxesTest(network,
211 reduceDescriptor.
m_vAxis.size(),
215 void ReduceSumWithThreeAxesTest(
Compute backendId)
218 reduceDescriptor.
m_vAxis = {0, 2, 3};
226 INetworkPtr network = CreateSimpleReduceNetwork(reduceDescriptor, inputShape, outputShape);
229 const std::vector<float> inputData({1.0f, 2.0f,
240 const std::vector<float> expectedOutput({110.0f, 286.0f});
242 ReduceWithMultipleAxesTest(network,
246 reduceDescriptor.
m_vAxis.size(),
252 #if defined(ARMCOMPUTENEON_ENABLED) 255 TEST_CASE(
"ReduceSumWithTwoAxesKeepDimsCpuAccTest")
260 TEST_CASE(
"ReduceSumWithTwoAxesCpuAccTest")
265 TEST_CASE(
"ReduceSumWithThreeAxesKeepDimsCpuAccTest")
270 TEST_CASE(
"ReduceSumWithThreeAxesCpuAccTest")
277 #if defined(ARMCOMPUTECL_ENABLED) 280 TEST_CASE(
"ReduceSumWithTwoAxesKeepDimsGpuAccTest")
285 TEST_CASE(
"ReduceSumWithTwoAxesGpuAccTest")
290 TEST_CASE(
"ReduceSumWithThreeAxesKeepDimsGpuAccTest")
295 TEST_CASE(
"ReduceSumWithThreeAxesGpuAccTest")
TEST_SUITE("TestConstTensorLayerVisitor")
static IRuntimePtr Create(const CreationOptions &options)
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
bool CheckSequence(const armnn::Graph::ConstIterator first, const armnn::Graph::ConstIterator last)
armnn::Layer * GetFirstLayerWithName(armnn::Graph &graph, const std::string &name)
bool m_KeepDims
if true then output shape has no change.
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
ReduceOperation m_ReduceOperation
Specifies the reduction operation to execute.
Copyright (c) 2021 ARM Limited and Contributors.
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
A tensor defined by a TensorInfo (shape and data type) and a mutable backing store.
Compute
The Compute enum is now deprecated and it is now being replaced by BackendId.
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.
A ReduceDescriptor for the REDUCE operators.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
std::vector< std::pair< LayerBindingId, class Tensor > > OutputTensors
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
GPU Execution: OpenCL: ArmCompute.
std::vector< uint32_t > m_vAxis
The indices of the dimensions to reduce.
Graph & GetGraphForTesting(IOptimizedNetwork *optNet)
CPU Execution: NEON: ArmCompute.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
void SetConstant(const bool IsConstant=true)
Marks the data corresponding to this tensor info as constant.
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.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
virtual int Connect(IInputSlot &destination)=0
const TensorInfo & GetTensorInfo() const override
static INetworkPtr Create(NetworkOptions networkOptions={})