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