blob: 54ee8a230a6211f259a0d29bdddc2530f29e6299 [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;
Sadik Armagan188675f2021-02-12 17:16:42 +000024using RequestArgument = V1_0::RequestArgument;
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010025
surmeh0149b9e102018-05-17 14:11:25 +010026namespace
27{
28
Kevin Mayedc5ffa2019-05-22 12:02:53 +010029#ifndef ARMCOMPUTECL_ENABLED
Colm Doneland7fdbe22020-10-30 16:57:43 +000030 static const std::array<armnn::Compute, 1> COMPUTE_DEVICES = {{ armnn::Compute::CpuRef }};
Kevin Mayedc5ffa2019-05-22 12:02:53 +010031#else
Colm Doneland7fdbe22020-10-30 16:57:43 +000032 static const std::array<armnn::Compute, 2> COMPUTE_DEVICES = {{ armnn::Compute::CpuRef, armnn::Compute::GpuAcc }};
Kevin Mayedc5ffa2019-05-22 12:02:53 +010033#endif
telsoa01ce3e84a2018-08-31 09:31:35 +010034
surmeh0149b9e102018-05-17 14:11:25 +010035void
Jim Flynn7b1e41f2019-05-22 18:00:04 +010036ConcatTestImpl(const std::vector<const TestTensor*> & inputs,
surmeh0149b9e102018-05-17 14:11:25 +010037 int32_t concatAxis,
38 const TestTensor & expectedOutputTensor,
telsoa01ce3e84a2018-08-31 09:31:35 +010039 armnn::Compute computeDevice,
Kevin Mayec1e5b82020-02-26 17:00:39 +000040 V1_0::ErrorStatus expectedPrepareStatus=V1_0::ErrorStatus::NONE,
41 V1_0::ErrorStatus expectedExecStatus=V1_0::ErrorStatus::NONE)
surmeh0149b9e102018-05-17 14:11:25 +010042{
telsoa01ce3e84a2018-08-31 09:31:35 +010043 std::unique_ptr<ArmnnDriver> driver = std::make_unique<ArmnnDriver>(DriverOptions(computeDevice));
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010044 HalPolicy::Model model{};
surmeh0149b9e102018-05-17 14:11:25 +010045
46 hidl_vec<uint32_t> modelInputIds;
47 modelInputIds.resize(inputs.size()+1);
48 for (uint32_t i = 0; i<inputs.size(); ++i)
49 {
50 modelInputIds[i] = i;
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010051 AddInputOperand<HalPolicy>(model, inputs[i]->GetDimensions());
surmeh0149b9e102018-05-17 14:11:25 +010052 }
53 modelInputIds[inputs.size()] = inputs.size(); // add an id for the axis too
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010054 AddIntOperand<HalPolicy>(model, concatAxis);
55 AddOutputOperand<HalPolicy>(model, expectedOutputTensor.GetDimensions());
surmeh0149b9e102018-05-17 14:11:25 +010056
57 // make the concat operation
58 model.operations.resize(1);
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010059 model.operations[0].type = HalPolicy::OperationType::CONCATENATION;
surmeh0149b9e102018-05-17 14:11:25 +010060 model.operations[0].inputs = modelInputIds;
61 model.operations[0].outputs = hidl_vec<uint32_t>{static_cast<uint32_t>(inputs.size()+1)};
62
63 // make the prepared model
Kevin Mayec1e5b82020-02-26 17:00:39 +000064 V1_0::ErrorStatus prepareStatus=V1_0::ErrorStatus::NONE;
Sadik Armagane6e54a82019-05-08 10:18:05 +010065 android::sp<V1_0::IPreparedModel> preparedModel = PrepareModelWithStatus(model,
Aron Virginas-Tar44cfd842019-06-14 15:45:03 +010066 *driver,
67 prepareStatus,
68 expectedPrepareStatus);
surmeh0149b9e102018-05-17 14:11:25 +010069 BOOST_TEST(prepareStatus == expectedPrepareStatus);
Kevin Mayec1e5b82020-02-26 17:00:39 +000070 if (prepareStatus != V1_0::ErrorStatus::NONE)
surmeh0149b9e102018-05-17 14:11:25 +010071 {
72 // prepare failed, we cannot continue
73 return;
74 }
75
76 BOOST_TEST(preparedModel.get() != nullptr);
77 if (preparedModel.get() == nullptr)
78 {
79 // don't spoil other tests if prepare failed
80 return;
81 }
82
83 // construct the request
84 hidl_vec<RequestArgument> inputArguments;
85 hidl_vec<RequestArgument> outputArguments;
86 inputArguments.resize(inputs.size());
87 outputArguments.resize(1);
88
89 // the request's memory pools will follow the same order as
90 // the inputs
91 for (uint32_t i = 0; i<inputs.size(); ++i)
92 {
Sadik Armagan188675f2021-02-12 17:16:42 +000093 V1_0::DataLocation inloc = {};
surmeh0149b9e102018-05-17 14:11:25 +010094 inloc.poolIndex = i;
95 inloc.offset = 0;
96 inloc.length = inputs[i]->GetNumElements() * sizeof(float);
97 RequestArgument input = {};
98 input.location = inloc;
99 input.dimensions = inputs[i]->GetDimensions();
100 inputArguments[i] = input;
101 }
102
103 // and an additional memory pool is needed for the output
104 {
Sadik Armagan188675f2021-02-12 17:16:42 +0000105 V1_0::DataLocation outloc = {};
surmeh0149b9e102018-05-17 14:11:25 +0100106 outloc.poolIndex = inputs.size();
107 outloc.offset = 0;
108 outloc.length = expectedOutputTensor.GetNumElements() * sizeof(float);
109 RequestArgument output = {};
110 output.location = outloc;
111 output.dimensions = expectedOutputTensor.GetDimensions();
112 outputArguments[0] = output;
113 }
114
115 // make the request based on the arguments
Kevin Mayec1e5b82020-02-26 17:00:39 +0000116 V1_0::Request request = {};
surmeh0149b9e102018-05-17 14:11:25 +0100117 request.inputs = inputArguments;
118 request.outputs = outputArguments;
119
120 // set the input data
121 for (uint32_t i = 0; i<inputs.size(); ++i)
122 {
123 AddPoolAndSetData(inputs[i]->GetNumElements(),
124 request,
125 inputs[i]->GetData());
126 }
127
128 // add memory for the output
Ellen Norris-Thompson976ad3e2019-08-21 15:21:14 +0100129 android::sp<IMemory> outMemory = AddPoolAndGetData<float>(expectedOutputTensor.GetNumElements(), request);
surmeh0149b9e102018-05-17 14:11:25 +0100130 float* outdata = static_cast<float*>(static_cast<void*>(outMemory->getPointer()));
131
132 // run the execution
David Monahanc60d0fd2020-05-19 14:58:34 +0100133 ARMNN_ASSERT(preparedModel.get() != nullptr);
surmeh0149b9e102018-05-17 14:11:25 +0100134 auto execStatus = Execute(preparedModel, request, expectedExecStatus);
135 BOOST_TEST(execStatus == expectedExecStatus);
136
Kevin Mayec1e5b82020-02-26 17:00:39 +0000137 if (execStatus == V1_0::ErrorStatus::NONE)
surmeh0149b9e102018-05-17 14:11:25 +0100138 {
139 // check the result if there was no error
140 const float * expectedOutput = expectedOutputTensor.GetData();
141 for (unsigned int i=0; i<expectedOutputTensor.GetNumElements();++i)
142 {
143 BOOST_TEST(outdata[i] == expectedOutput[i]);
144 }
145 }
146}
147
148} // namespace <anonymous>
149
telsoa01ce3e84a2018-08-31 09:31:35 +0100150
151BOOST_DATA_TEST_CASE(SimpleConcatAxis0, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100152{
153 int32_t axis = 0;
154 TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}};
155 TestTensor bIn{armnn::TensorShape{1,1,1,1},{1}};
156 TestTensor cIn{armnn::TensorShape{1,1,1,1},{2}};
157
158 TestTensor expected{armnn::TensorShape{3,1,1,1},{0,1,2}};
159
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100160 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100161}
162
telsoa01ce3e84a2018-08-31 09:31:35 +0100163BOOST_DATA_TEST_CASE(ConcatAxis0_NoInterleave, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100164{
165 int32_t axis = 0;
166 TestTensor aIn{armnn::TensorShape{2,1,2,1},{0, 1,
167 2, 3}};
168 TestTensor bIn{armnn::TensorShape{3,1,2,1},{4, 5,
169 6, 7,
170 8, 9}};
171 TestTensor cIn{armnn::TensorShape{1,1,2,1},{10, 11}};
172
173 TestTensor expected{armnn::TensorShape{6,1,2,1},{0, 1,
174 2, 3,
175 4, 5,
176 6, 7,
177 8, 9,
178 10, 11}};
179
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100180 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100181}
182
telsoa01ce3e84a2018-08-31 09:31:35 +0100183BOOST_DATA_TEST_CASE(SimpleConcatAxis1, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100184{
185 int32_t axis = 1;
186 TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}};
187 TestTensor bIn{armnn::TensorShape{1,1,1,1},{1}};
188 TestTensor cIn{armnn::TensorShape{1,1,1,1},{2}};
189
190 TestTensor expected{armnn::TensorShape{1,3,1,1},{0,1,2}};
191
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100192 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100193}
194
telsoa01ce3e84a2018-08-31 09:31:35 +0100195BOOST_DATA_TEST_CASE(ConcatAxis1_NoInterleave, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100196{
197 int32_t axis = 1;
198 TestTensor aIn{armnn::TensorShape{1,2,2,1},{0, 1,
199 2, 3}};
200 TestTensor bIn{armnn::TensorShape{1,3,2,1},{4, 5,
201 6, 7,
202 8, 9}};
203 TestTensor cIn{armnn::TensorShape{1,1,2,1},{10, 11}};
204
205 TestTensor expected{armnn::TensorShape{1,6,2,1},{0, 1,
206 2, 3,
207 4, 5,
208 6, 7,
209 8, 9,
210 10, 11}};
211
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100212 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100213}
214
telsoa01ce3e84a2018-08-31 09:31:35 +0100215BOOST_DATA_TEST_CASE(SimpleConcatAxis1_DoInterleave, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100216{
217 int32_t axis = 1;
218 TestTensor aIn{armnn::TensorShape{2,2,1,1},{0, 1,
219 2, 3}};
220 TestTensor bIn{armnn::TensorShape{2,3,1,1},{4, 5, 6,
221 7, 8, 9}};
222 TestTensor cIn{armnn::TensorShape{2,1,1,1},{10,
223 11}};
224
225 TestTensor expected{armnn::TensorShape{2,6,1,1},{0, 1, 4, 5, 6, 10,
226 2, 3, 7, 8, 9, 11}};
227
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100228 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100229}
230
telsoa01ce3e84a2018-08-31 09:31:35 +0100231BOOST_DATA_TEST_CASE(SimpleConcatAxis2, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100232{
233 int32_t axis = 2;
234 TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}};
235 TestTensor bIn{armnn::TensorShape{1,1,1,1},{1}};
236 TestTensor cIn{armnn::TensorShape{1,1,1,1},{2}};
237
238 TestTensor expected{armnn::TensorShape{1,1,3,1},{0,1,2}};
239
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100240 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100241}
242
telsoa01ce3e84a2018-08-31 09:31:35 +0100243BOOST_DATA_TEST_CASE(ConcatAxis2_NoInterleave, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100244{
245 int32_t axis = 2;
246 TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1,
247 2, 3}};
248 TestTensor bIn{armnn::TensorShape{1,1,3,2},{4, 5,
249 6, 7,
250 8, 9}};
251 TestTensor cIn{armnn::TensorShape{1,1,1,2},{10, 11}};
252
253 TestTensor expected{armnn::TensorShape{1,1,6,2},{0, 1,
254 2, 3,
255 4, 5,
256 6, 7,
257 8, 9,
258 10, 11}};
259
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100260 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100261}
262
telsoa01ce3e84a2018-08-31 09:31:35 +0100263BOOST_DATA_TEST_CASE(SimpleConcatAxis2_DoInterleave, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100264{
265 int32_t axis = 2;
266 TestTensor aIn{armnn::TensorShape{1,2,2,1},{0, 1,
267 2, 3}};
268 TestTensor bIn{armnn::TensorShape{1,2,3,1},{4, 5, 6,
269 7, 8, 9}};
270 TestTensor cIn{armnn::TensorShape{1,2,1,1},{10,
271 11}};
272
273 TestTensor expected{armnn::TensorShape{1,2,6,1},{0, 1, 4, 5, 6, 10,
274 2, 3, 7, 8, 9, 11}};
275
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100276 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100277}
278
telsoa01ce3e84a2018-08-31 09:31:35 +0100279BOOST_DATA_TEST_CASE(SimpleConcatAxis3, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100280{
281 int32_t axis = 3;
282 TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}};
283 TestTensor bIn{armnn::TensorShape{1,1,1,1},{1}};
284 TestTensor cIn{armnn::TensorShape{1,1,1,1},{2}};
285
286 TestTensor expected{armnn::TensorShape{1,1,1,3},{0,1,2}};
287
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100288 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100289}
290
telsoa01ce3e84a2018-08-31 09:31:35 +0100291BOOST_DATA_TEST_CASE(SimpleConcatAxis3_DoInterleave, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100292{
293 int32_t axis = 3;
294 TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1,
295 2, 3}};
296 TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6,
297 7, 8, 9}};
298 TestTensor cIn{armnn::TensorShape{1,1,2,1},{10,
299 11}};
300
301 TestTensor expected{armnn::TensorShape{1,1,2,6},{0, 1, 4, 5, 6, 10,
302 2, 3, 7, 8, 9, 11}};
303
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100304 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100305}
306
telsoa01ce3e84a2018-08-31 09:31:35 +0100307BOOST_DATA_TEST_CASE(AxisTooBig, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100308{
309 int32_t axis = 4;
310 TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}};
311 TestTensor bIn{armnn::TensorShape{1,1,1,1},{0}};
312
313 // The axis must be within the range of [-rank(values), rank(values))
314 // see: https://www.tensorflow.org/api_docs/python/tf/concat
315 TestTensor uncheckedOutput{armnn::TensorShape{1,1,1,1},{0}};
Kevin Mayec1e5b82020-02-26 17:00:39 +0000316 V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE;
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100317 ConcatTestImpl({&aIn, &bIn}, axis, uncheckedOutput, sample, expectedParserStatus);
surmeh0149b9e102018-05-17 14:11:25 +0100318}
319
telsoa01ce3e84a2018-08-31 09:31:35 +0100320BOOST_DATA_TEST_CASE(AxisTooSmall, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100321{
322 int32_t axis = -5;
323 TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}};
324 TestTensor bIn{armnn::TensorShape{1,1,1,1},{0}};
325
326 // The axis must be within the range of [-rank(values), rank(values))
327 // see: https://www.tensorflow.org/api_docs/python/tf/concat
328 TestTensor uncheckedOutput{armnn::TensorShape{1,1,1,1},{0}};
Kevin Mayec1e5b82020-02-26 17:00:39 +0000329 V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE;
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100330 ConcatTestImpl({&aIn, &bIn}, axis, uncheckedOutput, sample, expectedParserStatus);
surmeh0149b9e102018-05-17 14:11:25 +0100331}
332
telsoa01ce3e84a2018-08-31 09:31:35 +0100333BOOST_DATA_TEST_CASE(TooFewInputs, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100334{
335 int32_t axis = 0;
336 TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}};
337
338 // We need at least two tensors to concatenate
Kevin Mayec1e5b82020-02-26 17:00:39 +0000339 V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE;
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100340 ConcatTestImpl({&aIn}, axis, aIn, sample, expectedParserStatus);
surmeh0149b9e102018-05-17 14:11:25 +0100341}
342
telsoa01ce3e84a2018-08-31 09:31:35 +0100343BOOST_DATA_TEST_CASE(MismatchedInputDimensions, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100344{
345 int32_t axis = 3;
346 TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1,
347 2, 3}};
348 TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6,
349 7, 8, 9}};
350 TestTensor mismatched{armnn::TensorShape{1,1,1,1},{10}};
351
352 TestTensor expected{armnn::TensorShape{1,1,2,6},{0, 1, 4, 5, 6, 10,
353 2, 3, 7, 8, 9, 11}};
354
355 // The input dimensions must be compatible
Kevin Mayec1e5b82020-02-26 17:00:39 +0000356 V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE;
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100357 ConcatTestImpl({&aIn, &bIn, &mismatched}, axis, expected, sample, expectedParserStatus);
surmeh0149b9e102018-05-17 14:11:25 +0100358}
359
telsoa01ce3e84a2018-08-31 09:31:35 +0100360BOOST_DATA_TEST_CASE(MismatchedInputRanks, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100361{
362 int32_t axis = 2;
363 TestTensor aIn{armnn::TensorShape{1,1,2},{0,1}};
364 TestTensor bIn{armnn::TensorShape{1,1},{4}};
365 TestTensor expected{armnn::TensorShape{1,1,3},{0,1,4}};
366
367 // The input dimensions must be compatible
Kevin Mayec1e5b82020-02-26 17:00:39 +0000368 V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE;
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100369 ConcatTestImpl({&aIn, &bIn}, axis, expected, sample, expectedParserStatus);
surmeh0149b9e102018-05-17 14:11:25 +0100370}
371
telsoa01ce3e84a2018-08-31 09:31:35 +0100372BOOST_DATA_TEST_CASE(MismatchedOutputDimensions, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100373{
374 int32_t axis = 3;
375 TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1,
376 2, 3}};
377 TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6,
378 7, 8, 9}};
379 TestTensor cIn{armnn::TensorShape{1,1,2,1},{10,
380 11}};
381
382 TestTensor mismatched{armnn::TensorShape{1,1,6,2},{0, 1, 4, 5, 6, 10,
383 2, 3, 7, 8, 9, 11}};
384
385 // The input and output dimensions must be compatible
Kevin Mayec1e5b82020-02-26 17:00:39 +0000386 V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE;
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100387 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, mismatched, sample, expectedParserStatus);
surmeh0149b9e102018-05-17 14:11:25 +0100388}
389
telsoa01ce3e84a2018-08-31 09:31:35 +0100390BOOST_DATA_TEST_CASE(MismatchedOutputRank, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100391{
392 int32_t axis = 3;
393 TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1,
394 2, 3}};
395 TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6,
396 7, 8, 9}};
397 TestTensor cIn{armnn::TensorShape{1,1,2,1},{10,
398 11}};
399
400 TestTensor mismatched{armnn::TensorShape{6,2},{0, 1, 4, 5, 6, 10,
401 2, 3, 7, 8, 9, 11}};
402
403 // The input and output ranks must match
Kevin Mayec1e5b82020-02-26 17:00:39 +0000404 V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE;
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100405 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, mismatched, sample, expectedParserStatus);
surmeh0149b9e102018-05-17 14:11:25 +0100406}
407
telsoa01ce3e84a2018-08-31 09:31:35 +0100408BOOST_DATA_TEST_CASE(ValidNegativeAxis, COMPUTE_DEVICES)
surmeh0149b9e102018-05-17 14:11:25 +0100409{
410 // this is the same as 3
411 // see: https://www.tensorflow.org/api_docs/python/tf/concat
412 int32_t axis = -1;
413 TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1,
414 2, 3}};
415 TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6,
416 7, 8, 9}};
417 TestTensor cIn{armnn::TensorShape{1,1,2,1},{10,
418 11}};
419
420 TestTensor expected{armnn::TensorShape{1,1,2,6},{0, 1, 4, 5, 6, 10,
421 2, 3, 7, 8, 9, 11}};
422
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100423 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
telsoa01ce3e84a2018-08-31 09:31:35 +0100424}
425
426BOOST_DATA_TEST_CASE(SimpleConcatAxisZero3D, COMPUTE_DEVICES)
427{
428 int32_t axis = 0;
429 TestTensor aIn{armnn::TensorShape{1,1,1},{0}};
430 TestTensor bIn{armnn::TensorShape{1,1,1},{1}};
431 TestTensor cIn{armnn::TensorShape{1,1,1},{2}};
432
433 TestTensor expected{armnn::TensorShape{3,1,1},{0,1,2}};
434
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100435 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
telsoa01ce3e84a2018-08-31 09:31:35 +0100436}
437
438BOOST_DATA_TEST_CASE(SimpleConcatAxisOne3D, COMPUTE_DEVICES)
439{
440 int32_t axis = 1;
441 TestTensor aIn{armnn::TensorShape{1,1,1},{0}};
442 TestTensor bIn{armnn::TensorShape{1,1,1},{1}};
443 TestTensor cIn{armnn::TensorShape{1,1,1},{2}};
444
445 TestTensor expected{armnn::TensorShape{1,3,1},{0,1,2}};
446
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100447 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
telsoa01ce3e84a2018-08-31 09:31:35 +0100448}
449
450BOOST_DATA_TEST_CASE(SimpleConcatAxisTwo3D, COMPUTE_DEVICES)
451{
452 int32_t axis = 2;
453 TestTensor aIn{armnn::TensorShape{1,1,1},{0}};
454 TestTensor bIn{armnn::TensorShape{1,1,1},{1}};
455 TestTensor cIn{armnn::TensorShape{1,1,1},{2}};
456
457 TestTensor expected{armnn::TensorShape{1,1,3},{0,1,2}};
458
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100459 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
telsoa01ce3e84a2018-08-31 09:31:35 +0100460}
461
462BOOST_DATA_TEST_CASE(SimpleConcatAxisZero2D, COMPUTE_DEVICES)
463{
464 int32_t axis = 0;
465 TestTensor aIn{armnn::TensorShape{1,1},{0}};
466 TestTensor bIn{armnn::TensorShape{1,1},{1}};
467 TestTensor cIn{armnn::TensorShape{1,1},{2}};
468
469 TestTensor expected{armnn::TensorShape{3,1},{0,1,2}};
470
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100471 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
telsoa01ce3e84a2018-08-31 09:31:35 +0100472}
473
474BOOST_DATA_TEST_CASE(SimpleConcatAxisOne2D, COMPUTE_DEVICES)
475{
476 int32_t axis = 1;
477 TestTensor aIn{armnn::TensorShape{1,1},{0}};
478 TestTensor bIn{armnn::TensorShape{1,1},{1}};
479 TestTensor cIn{armnn::TensorShape{1,1},{2}};
480
481 TestTensor expected{armnn::TensorShape{1,3},{0,1,2}};
482
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100483 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
telsoa01ce3e84a2018-08-31 09:31:35 +0100484}
485
486BOOST_DATA_TEST_CASE(SimpleConcatAxisZero1D, COMPUTE_DEVICES)
487{
488 int32_t axis = 0;
489 TestTensor aIn{armnn::TensorShape{1},{0}};
490 TestTensor bIn{armnn::TensorShape{1},{1}};
491 TestTensor cIn{armnn::TensorShape{1},{2}};
492
493 TestTensor expected{armnn::TensorShape{3},{0,1,2}};
494
Jim Flynn7b1e41f2019-05-22 18:00:04 +0100495 ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample);
surmeh0149b9e102018-05-17 14:11:25 +0100496}
497
498BOOST_AUTO_TEST_SUITE_END()