blob: 0bc54247806f998bc323da07fc2275c91199672f [file] [log] [blame]
surmeh0149b9e102018-05-17 14:11:25 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beck93e48982018-09-05 13:05:09 +01003// SPDX-License-Identifier: MIT
surmeh0149b9e102018-05-17 14:11:25 +01004//
5#include "DriverTestHelpers.hpp"
6#include "TestTensor.hpp"
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +01007
8#include "../1.0/HalPolicy.hpp"
9
surmeh0149b9e102018-05-17 14:11:25 +010010#include <boost/test/unit_test.hpp>
telsoa01ce3e84a2018-08-31 09:31:35 +010011#include <boost/test/data/test_case.hpp>
surmeh0149b9e102018-05-17 14:11:25 +010012
Colm Doneland7fdbe22020-10-30 16:57:43 +000013#include <array>
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010014#include <log/log.h>
surmeh0149b9e102018-05-17 14:11:25 +010015
Colm Doneland7fdbe22020-10-30 16:57:43 +000016
Jim Flynn7b1e41f2019-05-22 18:00:04 +010017BOOST_AUTO_TEST_SUITE(ConcatTests)
surmeh0149b9e102018-05-17 14:11:25 +010018
telsoa01ce3e84a2018-08-31 09:31:35 +010019using namespace android::hardware;
surmeh0149b9e102018-05-17 14:11:25 +010020using namespace driverTestHelpers;
telsoa01ce3e84a2018-08-31 09:31:35 +010021using namespace armnn_driver;
surmeh0149b9e102018-05-17 14:11:25 +010022
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010023using HalPolicy = hal_1_0::HalPolicy;
24
surmeh0149b9e102018-05-17 14:11:25 +010025namespace
26{
27
Kevin Mayedc5ffa2019-05-22 12:02:53 +010028#ifndef ARMCOMPUTECL_ENABLED
Colm Doneland7fdbe22020-10-30 16:57:43 +000029 static const std::array<armnn::Compute, 1> COMPUTE_DEVICES = {{ armnn::Compute::CpuRef }};
Kevin Mayedc5ffa2019-05-22 12:02:53 +010030#else
Colm Doneland7fdbe22020-10-30 16:57:43 +000031 static const std::array<armnn::Compute, 2> COMPUTE_DEVICES = {{ armnn::Compute::CpuRef, armnn::Compute::GpuAcc }};
Kevin Mayedc5ffa2019-05-22 12:02:53 +010032#endif
telsoa01ce3e84a2018-08-31 09:31:35 +010033
surmeh0149b9e102018-05-17 14:11:25 +010034void
Jim Flynn7b1e41f2019-05-22 18:00:04 +010035ConcatTestImpl(const std::vector<const TestTensor*> & inputs,
surmeh0149b9e102018-05-17 14:11:25 +010036 int32_t concatAxis,
37 const TestTensor & expectedOutputTensor,
telsoa01ce3e84a2018-08-31 09:31:35 +010038 armnn::Compute computeDevice,
Kevin Mayec1e5b82020-02-26 17:00:39 +000039 V1_0::ErrorStatus expectedPrepareStatus=V1_0::ErrorStatus::NONE,
40 V1_0::ErrorStatus expectedExecStatus=V1_0::ErrorStatus::NONE)
surmeh0149b9e102018-05-17 14:11:25 +010041{
telsoa01ce3e84a2018-08-31 09:31:35 +010042 std::unique_ptr<ArmnnDriver> driver = std::make_unique<ArmnnDriver>(DriverOptions(computeDevice));
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010043 HalPolicy::Model model{};
surmeh0149b9e102018-05-17 14:11:25 +010044
45 hidl_vec<uint32_t> modelInputIds;
46 modelInputIds.resize(inputs.size()+1);
47 for (uint32_t i = 0; i<inputs.size(); ++i)
48 {
49 modelInputIds[i] = i;
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010050 AddInputOperand<HalPolicy>(model, inputs[i]->GetDimensions());
surmeh0149b9e102018-05-17 14:11:25 +010051 }
52 modelInputIds[inputs.size()] = inputs.size(); // add an id for the axis too
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010053 AddIntOperand<HalPolicy>(model, concatAxis);
54 AddOutputOperand<HalPolicy>(model, expectedOutputTensor.GetDimensions());
surmeh0149b9e102018-05-17 14:11:25 +010055
56 // make the concat operation
57 model.operations.resize(1);
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010058 model.operations[0].type = HalPolicy::OperationType::CONCATENATION;
surmeh0149b9e102018-05-17 14:11:25 +010059 model.operations[0].inputs = modelInputIds;
60 model.operations[0].outputs = hidl_vec<uint32_t>{static_cast<uint32_t>(inputs.size()+1)};
61
62 // make the prepared model
Kevin Mayec1e5b82020-02-26 17:00:39 +000063 V1_0::ErrorStatus prepareStatus=V1_0::ErrorStatus::NONE;
Sadik Armagane6e54a82019-05-08 10:18:05 +010064 android::sp<V1_0::IPreparedModel> preparedModel = PrepareModelWithStatus(model,
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010065 *driver,
66 prepareStatus,
67 expectedPrepareStatus);
surmeh0149b9e102018-05-17 14:11:25 +010068 BOOST_TEST(prepareStatus == expectedPrepareStatus);
Kevin Mayec1e5b82020-02-26 17:00:39 +000069 if (prepareStatus != V1_0::ErrorStatus::NONE)
surmeh0149b9e102018-05-17 14:11:25 +010070 {
71 // prepare failed, we cannot continue
72 return;
73 }
74
75 BOOST_TEST(preparedModel.get() != nullptr);
76 if (preparedModel.get() == nullptr)
77 {
78 // don't spoil other tests if prepare failed
79 return;
80 }
81
82 // construct the request
83 hidl_vec<RequestArgument> inputArguments;
84 hidl_vec<RequestArgument> outputArguments;
85 inputArguments.resize(inputs.size());
86 outputArguments.resize(1);
87
88 // the request's memory pools will follow the same order as
89 // the inputs
90 for (uint32_t i = 0; i<inputs.size(); ++i)
91 {
92 DataLocation inloc = {};
93 inloc.poolIndex = i;
94 inloc.offset = 0;
95 inloc.length = inputs[i]->GetNumElements() * sizeof(float);
96 RequestArgument input = {};
97 input.location = inloc;
98 input.dimensions = inputs[i]->GetDimensions();
99 inputArguments[i] = input;
100 }
101
102 // and an additional memory pool is needed for the output
103 {
104 DataLocation outloc = {};
105 outloc.poolIndex = inputs.size();
106 outloc.offset = 0;
107 outloc.length = expectedOutputTensor.GetNumElements() * sizeof(float);
108 RequestArgument output = {};
109 output.location = outloc;
110 output.dimensions = expectedOutputTensor.GetDimensions();
111 outputArguments[0] = output;
112 }
113
114 // make the request based on the arguments
Kevin Mayec1e5b82020-02-26 17:00:39 +0000115 V1_0::Request request = {};
surmeh0149b9e102018-05-17 14:11:25 +0100116 request.inputs = inputArguments;
117 request.outputs = outputArguments;
118
119 // set the input data
120 for (uint32_t i = 0; i<inputs.size(); ++i)
121 {
122 AddPoolAndSetData(inputs[i]->GetNumElements(),
123 request,
124 inputs[i]->GetData());
125 }
126
127 // add memory for the output
Ellen Norris-Thompson976ad3e2019-08-21 15:21:14 +0100128 android::sp<IMemory> outMemory = AddPoolAndGetData<float>(expectedOutputTensor.GetNumElements(), request);
surmeh0149b9e102018-05-17 14:11:25 +0100129 float* outdata = static_cast<float*>(static_cast<void*>(outMemory->getPointer()));
130
131 // run the execution
David Monahanc60d0fd2020-05-19 14:58:34 +0100132 ARMNN_ASSERT(preparedModel.get() != nullptr);
surmeh0149b9e102018-05-17 14:11:25 +0100133 auto execStatus = Execute(preparedModel, request, expectedExecStatus);
134 BOOST_TEST(execStatus == expectedExecStatus);
135
Kevin Mayec1e5b82020-02-26 17:00:39 +0000136 if (execStatus == V1_0::ErrorStatus::NONE)
surmeh0149b9e102018-05-17 14:11:25 +0100137 {
138 // check the result if there was no error
139 const float * expectedOutput = expectedOutputTensor.GetData();
140 for (unsigned int i=0; i<expectedOutputTensor.GetNumElements();++i)
141 {
142 BOOST_TEST(outdata[i] == expectedOutput[i]);
143 }
144 }
145}
146
147} // namespace <anonymous>
148
telsoa01ce3e84a2018-08-31 09:31:35 +0100149
150BOOST_DATA_TEST_CASE(SimpleConcatAxis0, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100151{
152 int32_t axis = 0;
153 TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}};
154 TestTensor bIn{armnn::TensorShape{1,1,1,1},{1}};
155 TestTensor cIn{armnn::TensorShape{1,1,1,1},{2}};
156
157 TestTensor expected{armnn::TensorShape{3,1,1,1},{0,1,2}};
158
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100159 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100160}
161
telsoa01ce3e84a2018-08-31 09:31:35 +0100162BOOST_DATA_TEST_CASE(ConcatAxis0_NoInterleave, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100163{
164 int32_t axis = 0;
165 TestTensor aIn{armnn::TensorShape{2,1,2,1},{0, 1,
166 2, 3}};
167 TestTensor bIn{armnn::TensorShape{3,1,2,1},{4, 5,
168 6, 7,
169 8, 9}};
170 TestTensor cIn{armnn::TensorShape{1,1,2,1},{10, 11}};
171
172 TestTensor expected{armnn::TensorShape{6,1,2,1},{0, 1,
173 2, 3,
174 4, 5,
175 6, 7,
176 8, 9,
177 10, 11}};
178
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100179 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100180}
181
telsoa01ce3e84a2018-08-31 09:31:35 +0100182BOOST_DATA_TEST_CASE(SimpleConcatAxis1, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100183{
184 int32_t axis = 1;
185 TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}};
186 TestTensor bIn{armnn::TensorShape{1,1,1,1},{1}};
187 TestTensor cIn{armnn::TensorShape{1,1,1,1},{2}};
188
189 TestTensor expected{armnn::TensorShape{1,3,1,1},{0,1,2}};
190
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100191 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100192}
193
telsoa01ce3e84a2018-08-31 09:31:35 +0100194BOOST_DATA_TEST_CASE(ConcatAxis1_NoInterleave, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100195{
196 int32_t axis = 1;
197 TestTensor aIn{armnn::TensorShape{1,2,2,1},{0, 1,
198 2, 3}};
199 TestTensor bIn{armnn::TensorShape{1,3,2,1},{4, 5,
200 6, 7,
201 8, 9}};
202 TestTensor cIn{armnn::TensorShape{1,1,2,1},{10, 11}};
203
204 TestTensor expected{armnn::TensorShape{1,6,2,1},{0, 1,
205 2, 3,
206 4, 5,
207 6, 7,
208 8, 9,
209 10, 11}};
210
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100211 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100212}
213
telsoa01ce3e84a2018-08-31 09:31:35 +0100214BOOST_DATA_TEST_CASE(SimpleConcatAxis1_DoInterleave, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100215{
216 int32_t axis = 1;
217 TestTensor aIn{armnn::TensorShape{2,2,1,1},{0, 1,
218 2, 3}};
219 TestTensor bIn{armnn::TensorShape{2,3,1,1},{4, 5, 6,
220 7, 8, 9}};
221 TestTensor cIn{armnn::TensorShape{2,1,1,1},{10,
222 11}};
223
224 TestTensor expected{armnn::TensorShape{2,6,1,1},{0, 1, 4, 5, 6, 10,
225 2, 3, 7, 8, 9, 11}};
226
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100227 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100228}
229
telsoa01ce3e84a2018-08-31 09:31:35 +0100230BOOST_DATA_TEST_CASE(SimpleConcatAxis2, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100231{
232 int32_t axis = 2;
233 TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}};
234 TestTensor bIn{armnn::TensorShape{1,1,1,1},{1}};
235 TestTensor cIn{armnn::TensorShape{1,1,1,1},{2}};
236
237 TestTensor expected{armnn::TensorShape{1,1,3,1},{0,1,2}};
238
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100239 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100240}
241
telsoa01ce3e84a2018-08-31 09:31:35 +0100242BOOST_DATA_TEST_CASE(ConcatAxis2_NoInterleave, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100243{
244 int32_t axis = 2;
245 TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1,
246 2, 3}};
247 TestTensor bIn{armnn::TensorShape{1,1,3,2},{4, 5,
248 6, 7,
249 8, 9}};
250 TestTensor cIn{armnn::TensorShape{1,1,1,2},{10, 11}};
251
252 TestTensor expected{armnn::TensorShape{1,1,6,2},{0, 1,
253 2, 3,
254 4, 5,
255 6, 7,
256 8, 9,
257 10, 11}};
258
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100259 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100260}
261
telsoa01ce3e84a2018-08-31 09:31:35 +0100262BOOST_DATA_TEST_CASE(SimpleConcatAxis2_DoInterleave, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100263{
264 int32_t axis = 2;
265 TestTensor aIn{armnn::TensorShape{1,2,2,1},{0, 1,
266 2, 3}};
267 TestTensor bIn{armnn::TensorShape{1,2,3,1},{4, 5, 6,
268 7, 8, 9}};
269 TestTensor cIn{armnn::TensorShape{1,2,1,1},{10,
270 11}};
271
272 TestTensor expected{armnn::TensorShape{1,2,6,1},{0, 1, 4, 5, 6, 10,
273 2, 3, 7, 8, 9, 11}};
274
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100275 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100276}
277
telsoa01ce3e84a2018-08-31 09:31:35 +0100278BOOST_DATA_TEST_CASE(SimpleConcatAxis3, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100279{
280 int32_t axis = 3;
281 TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}};
282 TestTensor bIn{armnn::TensorShape{1,1,1,1},{1}};
283 TestTensor cIn{armnn::TensorShape{1,1,1,1},{2}};
284
285 TestTensor expected{armnn::TensorShape{1,1,1,3},{0,1,2}};
286
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100287 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100288}
289
telsoa01ce3e84a2018-08-31 09:31:35 +0100290BOOST_DATA_TEST_CASE(SimpleConcatAxis3_DoInterleave, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100291{
292 int32_t axis = 3;
293 TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1,
294 2, 3}};
295 TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6,
296 7, 8, 9}};
297 TestTensor cIn{armnn::TensorShape{1,1,2,1},{10,
298 11}};
299
300 TestTensor expected{armnn::TensorShape{1,1,2,6},{0, 1, 4, 5, 6, 10,
301 2, 3, 7, 8, 9, 11}};
302
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100303 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100304}
305
telsoa01ce3e84a2018-08-31 09:31:35 +0100306BOOST_DATA_TEST_CASE(AxisTooBig, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100307{
308 int32_t axis = 4;
309 TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}};
310 TestTensor bIn{armnn::TensorShape{1,1,1,1},{0}};
311
312 // The axis must be within the range of [-rank(values), rank(values))
313 // see: https://www.tensorflow.org/api_docs/python/tf/concat
314 TestTensor uncheckedOutput{armnn::TensorShape{1,1,1,1},{0}};
Kevin Mayec1e5b82020-02-26 17:00:39 +0000315 V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE;
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100316 ConcatTestImpl({&aIn, &bIn}, axis, uncheckedOutput, sample, expectedParserStatus);
surmeh0149b9e102018-05-17 14:11:25 +0100317}
318
telsoa01ce3e84a2018-08-31 09:31:35 +0100319BOOST_DATA_TEST_CASE(AxisTooSmall, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100320{
321 int32_t axis = -5;
322 TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}};
323 TestTensor bIn{armnn::TensorShape{1,1,1,1},{0}};
324
325 // The axis must be within the range of [-rank(values), rank(values))
326 // see: https://www.tensorflow.org/api_docs/python/tf/concat
327 TestTensor uncheckedOutput{armnn::TensorShape{1,1,1,1},{0}};
Kevin Mayec1e5b82020-02-26 17:00:39 +0000328 V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE;
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100329 ConcatTestImpl({&aIn, &bIn}, axis, uncheckedOutput, sample, expectedParserStatus);
surmeh0149b9e102018-05-17 14:11:25 +0100330}
331
telsoa01ce3e84a2018-08-31 09:31:35 +0100332BOOST_DATA_TEST_CASE(TooFewInputs, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100333{
334 int32_t axis = 0;
335 TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}};
336
337 // We need at least two tensors to concatenate
Kevin Mayec1e5b82020-02-26 17:00:39 +0000338 V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE;
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100339 ConcatTestImpl({&aIn}, axis, aIn, sample, expectedParserStatus);
surmeh0149b9e102018-05-17 14:11:25 +0100340}
341
telsoa01ce3e84a2018-08-31 09:31:35 +0100342BOOST_DATA_TEST_CASE(MismatchedInputDimensions, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100343{
344 int32_t axis = 3;
345 TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1,
346 2, 3}};
347 TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6,
348 7, 8, 9}};
349 TestTensor mismatched{armnn::TensorShape{1,1,1,1},{10}};
350
351 TestTensor expected{armnn::TensorShape{1,1,2,6},{0, 1, 4, 5, 6, 10,
352 2, 3, 7, 8, 9, 11}};
353
354 // The input dimensions must be compatible
Kevin Mayec1e5b82020-02-26 17:00:39 +0000355 V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE;
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100356 ConcatTestImpl({&aIn, &bIn, &mismatched}, axis, expected, sample, expectedParserStatus);
surmeh0149b9e102018-05-17 14:11:25 +0100357}
358
telsoa01ce3e84a2018-08-31 09:31:35 +0100359BOOST_DATA_TEST_CASE(MismatchedInputRanks, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100360{
361 int32_t axis = 2;
362 TestTensor aIn{armnn::TensorShape{1,1,2},{0,1}};
363 TestTensor bIn{armnn::TensorShape{1,1},{4}};
364 TestTensor expected{armnn::TensorShape{1,1,3},{0,1,4}};
365
366 // The input dimensions must be compatible
Kevin Mayec1e5b82020-02-26 17:00:39 +0000367 V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE;
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100368 ConcatTestImpl({&aIn, &bIn}, axis, expected, sample, expectedParserStatus);
surmeh0149b9e102018-05-17 14:11:25 +0100369}
370
telsoa01ce3e84a2018-08-31 09:31:35 +0100371BOOST_DATA_TEST_CASE(MismatchedOutputDimensions, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100372{
373 int32_t axis = 3;
374 TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1,
375 2, 3}};
376 TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6,
377 7, 8, 9}};
378 TestTensor cIn{armnn::TensorShape{1,1,2,1},{10,
379 11}};
380
381 TestTensor mismatched{armnn::TensorShape{1,1,6,2},{0, 1, 4, 5, 6, 10,
382 2, 3, 7, 8, 9, 11}};
383
384 // The input and output dimensions must be compatible
Kevin Mayec1e5b82020-02-26 17:00:39 +0000385 V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE;
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100386 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, mismatched, sample, expectedParserStatus);
surmeh0149b9e102018-05-17 14:11:25 +0100387}
388
telsoa01ce3e84a2018-08-31 09:31:35 +0100389BOOST_DATA_TEST_CASE(MismatchedOutputRank, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100390{
391 int32_t axis = 3;
392 TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1,
393 2, 3}};
394 TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6,
395 7, 8, 9}};
396 TestTensor cIn{armnn::TensorShape{1,1,2,1},{10,
397 11}};
398
399 TestTensor mismatched{armnn::TensorShape{6,2},{0, 1, 4, 5, 6, 10,
400 2, 3, 7, 8, 9, 11}};
401
402 // The input and output ranks must match
Kevin Mayec1e5b82020-02-26 17:00:39 +0000403 V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE;
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100404 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, mismatched, sample, expectedParserStatus);
surmeh0149b9e102018-05-17 14:11:25 +0100405}
406
telsoa01ce3e84a2018-08-31 09:31:35 +0100407BOOST_DATA_TEST_CASE(ValidNegativeAxis, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100408{
409 // this is the same as 3
410 // see: https://www.tensorflow.org/api_docs/python/tf/concat
411 int32_t axis = -1;
412 TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1,
413 2, 3}};
414 TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6,
415 7, 8, 9}};
416 TestTensor cIn{armnn::TensorShape{1,1,2,1},{10,
417 11}};
418
419 TestTensor expected{armnn::TensorShape{1,1,2,6},{0, 1, 4, 5, 6, 10,
420 2, 3, 7, 8, 9, 11}};
421
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100422 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
telsoa01ce3e84a2018-08-31 09:31:35 +0100423}
424
425BOOST_DATA_TEST_CASE(SimpleConcatAxisZero3D, COMPUTE_DEVICES)
426{
427 int32_t axis = 0;
428 TestTensor aIn{armnn::TensorShape{1,1,1},{0}};
429 TestTensor bIn{armnn::TensorShape{1,1,1},{1}};
430 TestTensor cIn{armnn::TensorShape{1,1,1},{2}};
431
432 TestTensor expected{armnn::TensorShape{3,1,1},{0,1,2}};
433
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100434 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
telsoa01ce3e84a2018-08-31 09:31:35 +0100435}
436
437BOOST_DATA_TEST_CASE(SimpleConcatAxisOne3D, COMPUTE_DEVICES)
438{
439 int32_t axis = 1;
440 TestTensor aIn{armnn::TensorShape{1,1,1},{0}};
441 TestTensor bIn{armnn::TensorShape{1,1,1},{1}};
442 TestTensor cIn{armnn::TensorShape{1,1,1},{2}};
443
444 TestTensor expected{armnn::TensorShape{1,3,1},{0,1,2}};
445
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100446 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
telsoa01ce3e84a2018-08-31 09:31:35 +0100447}
448
449BOOST_DATA_TEST_CASE(SimpleConcatAxisTwo3D, COMPUTE_DEVICES)
450{
451 int32_t axis = 2;
452 TestTensor aIn{armnn::TensorShape{1,1,1},{0}};
453 TestTensor bIn{armnn::TensorShape{1,1,1},{1}};
454 TestTensor cIn{armnn::TensorShape{1,1,1},{2}};
455
456 TestTensor expected{armnn::TensorShape{1,1,3},{0,1,2}};
457
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100458 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
telsoa01ce3e84a2018-08-31 09:31:35 +0100459}
460
461BOOST_DATA_TEST_CASE(SimpleConcatAxisZero2D, COMPUTE_DEVICES)
462{
463 int32_t axis = 0;
464 TestTensor aIn{armnn::TensorShape{1,1},{0}};
465 TestTensor bIn{armnn::TensorShape{1,1},{1}};
466 TestTensor cIn{armnn::TensorShape{1,1},{2}};
467
468 TestTensor expected{armnn::TensorShape{3,1},{0,1,2}};
469
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100470 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
telsoa01ce3e84a2018-08-31 09:31:35 +0100471}
472
473BOOST_DATA_TEST_CASE(SimpleConcatAxisOne2D, COMPUTE_DEVICES)
474{
475 int32_t axis = 1;
476 TestTensor aIn{armnn::TensorShape{1,1},{0}};
477 TestTensor bIn{armnn::TensorShape{1,1},{1}};
478 TestTensor cIn{armnn::TensorShape{1,1},{2}};
479
480 TestTensor expected{armnn::TensorShape{1,3},{0,1,2}};
481
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100482 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
telsoa01ce3e84a2018-08-31 09:31:35 +0100483}
484
485BOOST_DATA_TEST_CASE(SimpleConcatAxisZero1D, COMPUTE_DEVICES)
486{
487 int32_t axis = 0;
488 TestTensor aIn{armnn::TensorShape{1},{0}};
489 TestTensor bIn{armnn::TensorShape{1},{1}};
490 TestTensor cIn{armnn::TensorShape{1},{2}};
491
492 TestTensor expected{armnn::TensorShape{3},{0,1,2}};
493
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100494 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100495}
496
497BOOST_AUTO_TEST_SUITE_END()