surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | 93e4898 | 2018-09-05 13:05:09 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 4 | // |
| 5 | #include "DriverTestHelpers.hpp" |
| 6 | #include "TestTensor.hpp" |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 7 | #include <boost/array.hpp> |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 8 | #include <boost/test/unit_test.hpp> |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 9 | #include <boost/test/data/test_case.hpp> |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 10 | #include <log/log.h> |
| 11 | |
| 12 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 13 | BOOST_AUTO_TEST_SUITE(ConcatTests) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 14 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 15 | using namespace android::hardware; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 16 | using namespace driverTestHelpers; |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 17 | using namespace armnn_driver; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 18 | |
| 19 | namespace |
| 20 | { |
| 21 | |
Kevin May | edc5ffa | 2019-05-22 12:02:53 +0100 | [diff] [blame] | 22 | #ifndef ARMCOMPUTECL_ENABLED |
| 23 | static const boost::array<armnn::Compute, 1> COMPUTE_DEVICES = {{ armnn::Compute::CpuRef }}; |
| 24 | #else |
| 25 | static const boost::array<armnn::Compute, 2> COMPUTE_DEVICES = {{ armnn::Compute::CpuRef, armnn::Compute::GpuAcc }}; |
| 26 | #endif |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 27 | |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 28 | void |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 29 | ConcatTestImpl(const std::vector<const TestTensor*> & inputs, |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 30 | int32_t concatAxis, |
| 31 | const TestTensor & expectedOutputTensor, |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 32 | armnn::Compute computeDevice, |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 33 | ErrorStatus expectedPrepareStatus=ErrorStatus::NONE, |
| 34 | ErrorStatus expectedExecStatus=ErrorStatus::NONE) |
| 35 | { |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 36 | std::unique_ptr<ArmnnDriver> driver = std::make_unique<ArmnnDriver>(DriverOptions(computeDevice)); |
Matteo Martincigh | 8b287c2 | 2018-09-07 09:25:10 +0100 | [diff] [blame] | 37 | V1_0::Model model{}; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 38 | |
| 39 | hidl_vec<uint32_t> modelInputIds; |
| 40 | modelInputIds.resize(inputs.size()+1); |
| 41 | for (uint32_t i = 0; i<inputs.size(); ++i) |
| 42 | { |
| 43 | modelInputIds[i] = i; |
| 44 | AddInputOperand(model, inputs[i]->GetDimensions()); |
| 45 | } |
| 46 | modelInputIds[inputs.size()] = inputs.size(); // add an id for the axis too |
| 47 | AddIntOperand(model, concatAxis); |
| 48 | AddOutputOperand(model, expectedOutputTensor.GetDimensions()); |
| 49 | |
| 50 | // make the concat operation |
| 51 | model.operations.resize(1); |
Matteo Martincigh | 8b287c2 | 2018-09-07 09:25:10 +0100 | [diff] [blame] | 52 | model.operations[0].type = V1_0::OperationType::CONCATENATION; |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 53 | model.operations[0].inputs = modelInputIds; |
| 54 | model.operations[0].outputs = hidl_vec<uint32_t>{static_cast<uint32_t>(inputs.size()+1)}; |
| 55 | |
| 56 | // make the prepared model |
| 57 | ErrorStatus prepareStatus=ErrorStatus::NONE; |
Sadik Armagan | e6e54a8 | 2019-05-08 10:18:05 +0100 | [diff] [blame] | 58 | android::sp<V1_0::IPreparedModel> preparedModel = PrepareModelWithStatus(model, |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 59 | *driver, |
| 60 | prepareStatus, |
| 61 | expectedPrepareStatus); |
| 62 | BOOST_TEST(prepareStatus == expectedPrepareStatus); |
| 63 | if (prepareStatus != ErrorStatus::NONE) |
| 64 | { |
| 65 | // prepare failed, we cannot continue |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | BOOST_TEST(preparedModel.get() != nullptr); |
| 70 | if (preparedModel.get() == nullptr) |
| 71 | { |
| 72 | // don't spoil other tests if prepare failed |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | // construct the request |
| 77 | hidl_vec<RequestArgument> inputArguments; |
| 78 | hidl_vec<RequestArgument> outputArguments; |
| 79 | inputArguments.resize(inputs.size()); |
| 80 | outputArguments.resize(1); |
| 81 | |
| 82 | // the request's memory pools will follow the same order as |
| 83 | // the inputs |
| 84 | for (uint32_t i = 0; i<inputs.size(); ++i) |
| 85 | { |
| 86 | DataLocation inloc = {}; |
| 87 | inloc.poolIndex = i; |
| 88 | inloc.offset = 0; |
| 89 | inloc.length = inputs[i]->GetNumElements() * sizeof(float); |
| 90 | RequestArgument input = {}; |
| 91 | input.location = inloc; |
| 92 | input.dimensions = inputs[i]->GetDimensions(); |
| 93 | inputArguments[i] = input; |
| 94 | } |
| 95 | |
| 96 | // and an additional memory pool is needed for the output |
| 97 | { |
| 98 | DataLocation outloc = {}; |
| 99 | outloc.poolIndex = inputs.size(); |
| 100 | outloc.offset = 0; |
| 101 | outloc.length = expectedOutputTensor.GetNumElements() * sizeof(float); |
| 102 | RequestArgument output = {}; |
| 103 | output.location = outloc; |
| 104 | output.dimensions = expectedOutputTensor.GetDimensions(); |
| 105 | outputArguments[0] = output; |
| 106 | } |
| 107 | |
| 108 | // make the request based on the arguments |
| 109 | Request request = {}; |
| 110 | request.inputs = inputArguments; |
| 111 | request.outputs = outputArguments; |
| 112 | |
| 113 | // set the input data |
| 114 | for (uint32_t i = 0; i<inputs.size(); ++i) |
| 115 | { |
| 116 | AddPoolAndSetData(inputs[i]->GetNumElements(), |
| 117 | request, |
| 118 | inputs[i]->GetData()); |
| 119 | } |
| 120 | |
| 121 | // add memory for the output |
| 122 | android::sp<IMemory> outMemory = AddPoolAndGetData(expectedOutputTensor.GetNumElements(), request); |
| 123 | float* outdata = static_cast<float*>(static_cast<void*>(outMemory->getPointer())); |
| 124 | |
| 125 | // run the execution |
| 126 | auto execStatus = Execute(preparedModel, request, expectedExecStatus); |
| 127 | BOOST_TEST(execStatus == expectedExecStatus); |
| 128 | |
| 129 | if (execStatus == ErrorStatus::NONE) |
| 130 | { |
| 131 | // check the result if there was no error |
| 132 | const float * expectedOutput = expectedOutputTensor.GetData(); |
| 133 | for (unsigned int i=0; i<expectedOutputTensor.GetNumElements();++i) |
| 134 | { |
| 135 | BOOST_TEST(outdata[i] == expectedOutput[i]); |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | } // namespace <anonymous> |
| 141 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 142 | |
| 143 | BOOST_DATA_TEST_CASE(SimpleConcatAxis0, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 144 | { |
| 145 | int32_t axis = 0; |
| 146 | TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}}; |
| 147 | TestTensor bIn{armnn::TensorShape{1,1,1,1},{1}}; |
| 148 | TestTensor cIn{armnn::TensorShape{1,1,1,1},{2}}; |
| 149 | |
| 150 | TestTensor expected{armnn::TensorShape{3,1,1,1},{0,1,2}}; |
| 151 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 152 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 153 | } |
| 154 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 155 | BOOST_DATA_TEST_CASE(ConcatAxis0_NoInterleave, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 156 | { |
| 157 | int32_t axis = 0; |
| 158 | TestTensor aIn{armnn::TensorShape{2,1,2,1},{0, 1, |
| 159 | 2, 3}}; |
| 160 | TestTensor bIn{armnn::TensorShape{3,1,2,1},{4, 5, |
| 161 | 6, 7, |
| 162 | 8, 9}}; |
| 163 | TestTensor cIn{armnn::TensorShape{1,1,2,1},{10, 11}}; |
| 164 | |
| 165 | TestTensor expected{armnn::TensorShape{6,1,2,1},{0, 1, |
| 166 | 2, 3, |
| 167 | 4, 5, |
| 168 | 6, 7, |
| 169 | 8, 9, |
| 170 | 10, 11}}; |
| 171 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 172 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 173 | } |
| 174 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 175 | BOOST_DATA_TEST_CASE(SimpleConcatAxis1, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 176 | { |
| 177 | int32_t axis = 1; |
| 178 | TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}}; |
| 179 | TestTensor bIn{armnn::TensorShape{1,1,1,1},{1}}; |
| 180 | TestTensor cIn{armnn::TensorShape{1,1,1,1},{2}}; |
| 181 | |
| 182 | TestTensor expected{armnn::TensorShape{1,3,1,1},{0,1,2}}; |
| 183 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 184 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 185 | } |
| 186 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 187 | BOOST_DATA_TEST_CASE(ConcatAxis1_NoInterleave, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 188 | { |
| 189 | int32_t axis = 1; |
| 190 | TestTensor aIn{armnn::TensorShape{1,2,2,1},{0, 1, |
| 191 | 2, 3}}; |
| 192 | TestTensor bIn{armnn::TensorShape{1,3,2,1},{4, 5, |
| 193 | 6, 7, |
| 194 | 8, 9}}; |
| 195 | TestTensor cIn{armnn::TensorShape{1,1,2,1},{10, 11}}; |
| 196 | |
| 197 | TestTensor expected{armnn::TensorShape{1,6,2,1},{0, 1, |
| 198 | 2, 3, |
| 199 | 4, 5, |
| 200 | 6, 7, |
| 201 | 8, 9, |
| 202 | 10, 11}}; |
| 203 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 204 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 205 | } |
| 206 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 207 | BOOST_DATA_TEST_CASE(SimpleConcatAxis1_DoInterleave, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 208 | { |
| 209 | int32_t axis = 1; |
| 210 | TestTensor aIn{armnn::TensorShape{2,2,1,1},{0, 1, |
| 211 | 2, 3}}; |
| 212 | TestTensor bIn{armnn::TensorShape{2,3,1,1},{4, 5, 6, |
| 213 | 7, 8, 9}}; |
| 214 | TestTensor cIn{armnn::TensorShape{2,1,1,1},{10, |
| 215 | 11}}; |
| 216 | |
| 217 | TestTensor expected{armnn::TensorShape{2,6,1,1},{0, 1, 4, 5, 6, 10, |
| 218 | 2, 3, 7, 8, 9, 11}}; |
| 219 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 220 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 221 | } |
| 222 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 223 | BOOST_DATA_TEST_CASE(SimpleConcatAxis2, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 224 | { |
| 225 | int32_t axis = 2; |
| 226 | TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}}; |
| 227 | TestTensor bIn{armnn::TensorShape{1,1,1,1},{1}}; |
| 228 | TestTensor cIn{armnn::TensorShape{1,1,1,1},{2}}; |
| 229 | |
| 230 | TestTensor expected{armnn::TensorShape{1,1,3,1},{0,1,2}}; |
| 231 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 232 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 233 | } |
| 234 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 235 | BOOST_DATA_TEST_CASE(ConcatAxis2_NoInterleave, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 236 | { |
| 237 | int32_t axis = 2; |
| 238 | TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1, |
| 239 | 2, 3}}; |
| 240 | TestTensor bIn{armnn::TensorShape{1,1,3,2},{4, 5, |
| 241 | 6, 7, |
| 242 | 8, 9}}; |
| 243 | TestTensor cIn{armnn::TensorShape{1,1,1,2},{10, 11}}; |
| 244 | |
| 245 | TestTensor expected{armnn::TensorShape{1,1,6,2},{0, 1, |
| 246 | 2, 3, |
| 247 | 4, 5, |
| 248 | 6, 7, |
| 249 | 8, 9, |
| 250 | 10, 11}}; |
| 251 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 252 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 253 | } |
| 254 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 255 | BOOST_DATA_TEST_CASE(SimpleConcatAxis2_DoInterleave, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 256 | { |
| 257 | int32_t axis = 2; |
| 258 | TestTensor aIn{armnn::TensorShape{1,2,2,1},{0, 1, |
| 259 | 2, 3}}; |
| 260 | TestTensor bIn{armnn::TensorShape{1,2,3,1},{4, 5, 6, |
| 261 | 7, 8, 9}}; |
| 262 | TestTensor cIn{armnn::TensorShape{1,2,1,1},{10, |
| 263 | 11}}; |
| 264 | |
| 265 | TestTensor expected{armnn::TensorShape{1,2,6,1},{0, 1, 4, 5, 6, 10, |
| 266 | 2, 3, 7, 8, 9, 11}}; |
| 267 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 268 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 269 | } |
| 270 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 271 | BOOST_DATA_TEST_CASE(SimpleConcatAxis3, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 272 | { |
| 273 | int32_t axis = 3; |
| 274 | TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}}; |
| 275 | TestTensor bIn{armnn::TensorShape{1,1,1,1},{1}}; |
| 276 | TestTensor cIn{armnn::TensorShape{1,1,1,1},{2}}; |
| 277 | |
| 278 | TestTensor expected{armnn::TensorShape{1,1,1,3},{0,1,2}}; |
| 279 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 280 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 281 | } |
| 282 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 283 | BOOST_DATA_TEST_CASE(SimpleConcatAxis3_DoInterleave, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 284 | { |
| 285 | int32_t axis = 3; |
| 286 | TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1, |
| 287 | 2, 3}}; |
| 288 | TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6, |
| 289 | 7, 8, 9}}; |
| 290 | TestTensor cIn{armnn::TensorShape{1,1,2,1},{10, |
| 291 | 11}}; |
| 292 | |
| 293 | TestTensor expected{armnn::TensorShape{1,1,2,6},{0, 1, 4, 5, 6, 10, |
| 294 | 2, 3, 7, 8, 9, 11}}; |
| 295 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 296 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 297 | } |
| 298 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 299 | BOOST_DATA_TEST_CASE(AxisTooBig, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 300 | { |
| 301 | int32_t axis = 4; |
| 302 | TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}}; |
| 303 | TestTensor bIn{armnn::TensorShape{1,1,1,1},{0}}; |
| 304 | |
| 305 | // The axis must be within the range of [-rank(values), rank(values)) |
| 306 | // see: https://www.tensorflow.org/api_docs/python/tf/concat |
| 307 | TestTensor uncheckedOutput{armnn::TensorShape{1,1,1,1},{0}}; |
| 308 | ErrorStatus expectedParserStatus = ErrorStatus::GENERAL_FAILURE; |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 309 | ConcatTestImpl({&aIn, &bIn}, axis, uncheckedOutput, sample, expectedParserStatus); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 310 | } |
| 311 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 312 | BOOST_DATA_TEST_CASE(AxisTooSmall, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 313 | { |
| 314 | int32_t axis = -5; |
| 315 | TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}}; |
| 316 | TestTensor bIn{armnn::TensorShape{1,1,1,1},{0}}; |
| 317 | |
| 318 | // The axis must be within the range of [-rank(values), rank(values)) |
| 319 | // see: https://www.tensorflow.org/api_docs/python/tf/concat |
| 320 | TestTensor uncheckedOutput{armnn::TensorShape{1,1,1,1},{0}}; |
| 321 | ErrorStatus expectedParserStatus = ErrorStatus::GENERAL_FAILURE; |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 322 | ConcatTestImpl({&aIn, &bIn}, axis, uncheckedOutput, sample, expectedParserStatus); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 323 | } |
| 324 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 325 | BOOST_DATA_TEST_CASE(TooFewInputs, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 326 | { |
| 327 | int32_t axis = 0; |
| 328 | TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}}; |
| 329 | |
| 330 | // We need at least two tensors to concatenate |
| 331 | ErrorStatus expectedParserStatus = ErrorStatus::GENERAL_FAILURE; |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 332 | ConcatTestImpl({&aIn}, axis, aIn, sample, expectedParserStatus); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 333 | } |
| 334 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 335 | BOOST_DATA_TEST_CASE(MismatchedInputDimensions, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 336 | { |
| 337 | int32_t axis = 3; |
| 338 | TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1, |
| 339 | 2, 3}}; |
| 340 | TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6, |
| 341 | 7, 8, 9}}; |
| 342 | TestTensor mismatched{armnn::TensorShape{1,1,1,1},{10}}; |
| 343 | |
| 344 | TestTensor expected{armnn::TensorShape{1,1,2,6},{0, 1, 4, 5, 6, 10, |
| 345 | 2, 3, 7, 8, 9, 11}}; |
| 346 | |
| 347 | // The input dimensions must be compatible |
| 348 | ErrorStatus expectedParserStatus = ErrorStatus::GENERAL_FAILURE; |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 349 | ConcatTestImpl({&aIn, &bIn, &mismatched}, axis, expected, sample, expectedParserStatus); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 350 | } |
| 351 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 352 | BOOST_DATA_TEST_CASE(MismatchedInputRanks, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 353 | { |
| 354 | int32_t axis = 2; |
| 355 | TestTensor aIn{armnn::TensorShape{1,1,2},{0,1}}; |
| 356 | TestTensor bIn{armnn::TensorShape{1,1},{4}}; |
| 357 | TestTensor expected{armnn::TensorShape{1,1,3},{0,1,4}}; |
| 358 | |
| 359 | // The input dimensions must be compatible |
| 360 | ErrorStatus expectedParserStatus = ErrorStatus::GENERAL_FAILURE; |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 361 | ConcatTestImpl({&aIn, &bIn}, axis, expected, sample, expectedParserStatus); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 362 | } |
| 363 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 364 | BOOST_DATA_TEST_CASE(MismatchedOutputDimensions, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 365 | { |
| 366 | int32_t axis = 3; |
| 367 | TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1, |
| 368 | 2, 3}}; |
| 369 | TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6, |
| 370 | 7, 8, 9}}; |
| 371 | TestTensor cIn{armnn::TensorShape{1,1,2,1},{10, |
| 372 | 11}}; |
| 373 | |
| 374 | TestTensor mismatched{armnn::TensorShape{1,1,6,2},{0, 1, 4, 5, 6, 10, |
| 375 | 2, 3, 7, 8, 9, 11}}; |
| 376 | |
| 377 | // The input and output dimensions must be compatible |
| 378 | ErrorStatus expectedParserStatus = ErrorStatus::GENERAL_FAILURE; |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 379 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, mismatched, sample, expectedParserStatus); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 380 | } |
| 381 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 382 | BOOST_DATA_TEST_CASE(MismatchedOutputRank, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 383 | { |
| 384 | int32_t axis = 3; |
| 385 | TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1, |
| 386 | 2, 3}}; |
| 387 | TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6, |
| 388 | 7, 8, 9}}; |
| 389 | TestTensor cIn{armnn::TensorShape{1,1,2,1},{10, |
| 390 | 11}}; |
| 391 | |
| 392 | TestTensor mismatched{armnn::TensorShape{6,2},{0, 1, 4, 5, 6, 10, |
| 393 | 2, 3, 7, 8, 9, 11}}; |
| 394 | |
| 395 | // The input and output ranks must match |
| 396 | ErrorStatus expectedParserStatus = ErrorStatus::GENERAL_FAILURE; |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 397 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, mismatched, sample, expectedParserStatus); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 398 | } |
| 399 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 400 | BOOST_DATA_TEST_CASE(ValidNegativeAxis, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 401 | { |
| 402 | // this is the same as 3 |
| 403 | // see: https://www.tensorflow.org/api_docs/python/tf/concat |
| 404 | int32_t axis = -1; |
| 405 | TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1, |
| 406 | 2, 3}}; |
| 407 | TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6, |
| 408 | 7, 8, 9}}; |
| 409 | TestTensor cIn{armnn::TensorShape{1,1,2,1},{10, |
| 410 | 11}}; |
| 411 | |
| 412 | TestTensor expected{armnn::TensorShape{1,1,2,6},{0, 1, 4, 5, 6, 10, |
| 413 | 2, 3, 7, 8, 9, 11}}; |
| 414 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 415 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | BOOST_DATA_TEST_CASE(SimpleConcatAxisZero3D, COMPUTE_DEVICES) |
| 419 | { |
| 420 | int32_t axis = 0; |
| 421 | TestTensor aIn{armnn::TensorShape{1,1,1},{0}}; |
| 422 | TestTensor bIn{armnn::TensorShape{1,1,1},{1}}; |
| 423 | TestTensor cIn{armnn::TensorShape{1,1,1},{2}}; |
| 424 | |
| 425 | TestTensor expected{armnn::TensorShape{3,1,1},{0,1,2}}; |
| 426 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 427 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | BOOST_DATA_TEST_CASE(SimpleConcatAxisOne3D, COMPUTE_DEVICES) |
| 431 | { |
| 432 | int32_t axis = 1; |
| 433 | TestTensor aIn{armnn::TensorShape{1,1,1},{0}}; |
| 434 | TestTensor bIn{armnn::TensorShape{1,1,1},{1}}; |
| 435 | TestTensor cIn{armnn::TensorShape{1,1,1},{2}}; |
| 436 | |
| 437 | TestTensor expected{armnn::TensorShape{1,3,1},{0,1,2}}; |
| 438 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 439 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | BOOST_DATA_TEST_CASE(SimpleConcatAxisTwo3D, COMPUTE_DEVICES) |
| 443 | { |
| 444 | int32_t axis = 2; |
| 445 | TestTensor aIn{armnn::TensorShape{1,1,1},{0}}; |
| 446 | TestTensor bIn{armnn::TensorShape{1,1,1},{1}}; |
| 447 | TestTensor cIn{armnn::TensorShape{1,1,1},{2}}; |
| 448 | |
| 449 | TestTensor expected{armnn::TensorShape{1,1,3},{0,1,2}}; |
| 450 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 451 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | BOOST_DATA_TEST_CASE(SimpleConcatAxisZero2D, COMPUTE_DEVICES) |
| 455 | { |
| 456 | int32_t axis = 0; |
| 457 | TestTensor aIn{armnn::TensorShape{1,1},{0}}; |
| 458 | TestTensor bIn{armnn::TensorShape{1,1},{1}}; |
| 459 | TestTensor cIn{armnn::TensorShape{1,1},{2}}; |
| 460 | |
| 461 | TestTensor expected{armnn::TensorShape{3,1},{0,1,2}}; |
| 462 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 463 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | BOOST_DATA_TEST_CASE(SimpleConcatAxisOne2D, COMPUTE_DEVICES) |
| 467 | { |
| 468 | int32_t axis = 1; |
| 469 | TestTensor aIn{armnn::TensorShape{1,1},{0}}; |
| 470 | TestTensor bIn{armnn::TensorShape{1,1},{1}}; |
| 471 | TestTensor cIn{armnn::TensorShape{1,1},{2}}; |
| 472 | |
| 473 | TestTensor expected{armnn::TensorShape{1,3},{0,1,2}}; |
| 474 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 475 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | BOOST_DATA_TEST_CASE(SimpleConcatAxisZero1D, COMPUTE_DEVICES) |
| 479 | { |
| 480 | int32_t axis = 0; |
| 481 | TestTensor aIn{armnn::TensorShape{1},{0}}; |
| 482 | TestTensor bIn{armnn::TensorShape{1},{1}}; |
| 483 | TestTensor cIn{armnn::TensorShape{1},{2}}; |
| 484 | |
| 485 | TestTensor expected{armnn::TensorShape{3},{0,1,2}}; |
| 486 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame^] | 487 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | BOOST_AUTO_TEST_SUITE_END() |