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 |
| 131 | auto execStatus = Execute(preparedModel, request, expectedExecStatus); |
| 132 | BOOST_TEST(execStatus == expectedExecStatus); |
| 133 | |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 134 | if (execStatus == V1_0::ErrorStatus::NONE) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 135 | { |
| 136 | // check the result if there was no error |
| 137 | const float * expectedOutput = expectedOutputTensor.GetData(); |
| 138 | for (unsigned int i=0; i<expectedOutputTensor.GetNumElements();++i) |
| 139 | { |
| 140 | BOOST_TEST(outdata[i] == expectedOutput[i]); |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | } // namespace <anonymous> |
| 146 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 147 | |
| 148 | BOOST_DATA_TEST_CASE(SimpleConcatAxis0, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 149 | { |
| 150 | int32_t axis = 0; |
| 151 | TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}}; |
| 152 | TestTensor bIn{armnn::TensorShape{1,1,1,1},{1}}; |
| 153 | TestTensor cIn{armnn::TensorShape{1,1,1,1},{2}}; |
| 154 | |
| 155 | TestTensor expected{armnn::TensorShape{3,1,1,1},{0,1,2}}; |
| 156 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 157 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 158 | } |
| 159 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 160 | BOOST_DATA_TEST_CASE(ConcatAxis0_NoInterleave, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 161 | { |
| 162 | int32_t axis = 0; |
| 163 | TestTensor aIn{armnn::TensorShape{2,1,2,1},{0, 1, |
| 164 | 2, 3}}; |
| 165 | TestTensor bIn{armnn::TensorShape{3,1,2,1},{4, 5, |
| 166 | 6, 7, |
| 167 | 8, 9}}; |
| 168 | TestTensor cIn{armnn::TensorShape{1,1,2,1},{10, 11}}; |
| 169 | |
| 170 | TestTensor expected{armnn::TensorShape{6,1,2,1},{0, 1, |
| 171 | 2, 3, |
| 172 | 4, 5, |
| 173 | 6, 7, |
| 174 | 8, 9, |
| 175 | 10, 11}}; |
| 176 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 177 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 178 | } |
| 179 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 180 | BOOST_DATA_TEST_CASE(SimpleConcatAxis1, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 181 | { |
| 182 | int32_t axis = 1; |
| 183 | TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}}; |
| 184 | TestTensor bIn{armnn::TensorShape{1,1,1,1},{1}}; |
| 185 | TestTensor cIn{armnn::TensorShape{1,1,1,1},{2}}; |
| 186 | |
| 187 | TestTensor expected{armnn::TensorShape{1,3,1,1},{0,1,2}}; |
| 188 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 189 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 190 | } |
| 191 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 192 | BOOST_DATA_TEST_CASE(ConcatAxis1_NoInterleave, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 193 | { |
| 194 | int32_t axis = 1; |
| 195 | TestTensor aIn{armnn::TensorShape{1,2,2,1},{0, 1, |
| 196 | 2, 3}}; |
| 197 | TestTensor bIn{armnn::TensorShape{1,3,2,1},{4, 5, |
| 198 | 6, 7, |
| 199 | 8, 9}}; |
| 200 | TestTensor cIn{armnn::TensorShape{1,1,2,1},{10, 11}}; |
| 201 | |
| 202 | TestTensor expected{armnn::TensorShape{1,6,2,1},{0, 1, |
| 203 | 2, 3, |
| 204 | 4, 5, |
| 205 | 6, 7, |
| 206 | 8, 9, |
| 207 | 10, 11}}; |
| 208 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 209 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 210 | } |
| 211 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 212 | BOOST_DATA_TEST_CASE(SimpleConcatAxis1_DoInterleave, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 213 | { |
| 214 | int32_t axis = 1; |
| 215 | TestTensor aIn{armnn::TensorShape{2,2,1,1},{0, 1, |
| 216 | 2, 3}}; |
| 217 | TestTensor bIn{armnn::TensorShape{2,3,1,1},{4, 5, 6, |
| 218 | 7, 8, 9}}; |
| 219 | TestTensor cIn{armnn::TensorShape{2,1,1,1},{10, |
| 220 | 11}}; |
| 221 | |
| 222 | TestTensor expected{armnn::TensorShape{2,6,1,1},{0, 1, 4, 5, 6, 10, |
| 223 | 2, 3, 7, 8, 9, 11}}; |
| 224 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 225 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 226 | } |
| 227 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 228 | BOOST_DATA_TEST_CASE(SimpleConcatAxis2, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 229 | { |
| 230 | int32_t axis = 2; |
| 231 | TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}}; |
| 232 | TestTensor bIn{armnn::TensorShape{1,1,1,1},{1}}; |
| 233 | TestTensor cIn{armnn::TensorShape{1,1,1,1},{2}}; |
| 234 | |
| 235 | TestTensor expected{armnn::TensorShape{1,1,3,1},{0,1,2}}; |
| 236 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 237 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 238 | } |
| 239 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 240 | BOOST_DATA_TEST_CASE(ConcatAxis2_NoInterleave, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 241 | { |
| 242 | int32_t axis = 2; |
| 243 | TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1, |
| 244 | 2, 3}}; |
| 245 | TestTensor bIn{armnn::TensorShape{1,1,3,2},{4, 5, |
| 246 | 6, 7, |
| 247 | 8, 9}}; |
| 248 | TestTensor cIn{armnn::TensorShape{1,1,1,2},{10, 11}}; |
| 249 | |
| 250 | TestTensor expected{armnn::TensorShape{1,1,6,2},{0, 1, |
| 251 | 2, 3, |
| 252 | 4, 5, |
| 253 | 6, 7, |
| 254 | 8, 9, |
| 255 | 10, 11}}; |
| 256 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 257 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 258 | } |
| 259 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 260 | BOOST_DATA_TEST_CASE(SimpleConcatAxis2_DoInterleave, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 261 | { |
| 262 | int32_t axis = 2; |
| 263 | TestTensor aIn{armnn::TensorShape{1,2,2,1},{0, 1, |
| 264 | 2, 3}}; |
| 265 | TestTensor bIn{armnn::TensorShape{1,2,3,1},{4, 5, 6, |
| 266 | 7, 8, 9}}; |
| 267 | TestTensor cIn{armnn::TensorShape{1,2,1,1},{10, |
| 268 | 11}}; |
| 269 | |
| 270 | TestTensor expected{armnn::TensorShape{1,2,6,1},{0, 1, 4, 5, 6, 10, |
| 271 | 2, 3, 7, 8, 9, 11}}; |
| 272 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 273 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 274 | } |
| 275 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 276 | BOOST_DATA_TEST_CASE(SimpleConcatAxis3, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 277 | { |
| 278 | int32_t axis = 3; |
| 279 | TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}}; |
| 280 | TestTensor bIn{armnn::TensorShape{1,1,1,1},{1}}; |
| 281 | TestTensor cIn{armnn::TensorShape{1,1,1,1},{2}}; |
| 282 | |
| 283 | TestTensor expected{armnn::TensorShape{1,1,1,3},{0,1,2}}; |
| 284 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 285 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 286 | } |
| 287 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 288 | BOOST_DATA_TEST_CASE(SimpleConcatAxis3_DoInterleave, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 289 | { |
| 290 | int32_t axis = 3; |
| 291 | TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1, |
| 292 | 2, 3}}; |
| 293 | TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6, |
| 294 | 7, 8, 9}}; |
| 295 | TestTensor cIn{armnn::TensorShape{1,1,2,1},{10, |
| 296 | 11}}; |
| 297 | |
| 298 | TestTensor expected{armnn::TensorShape{1,1,2,6},{0, 1, 4, 5, 6, 10, |
| 299 | 2, 3, 7, 8, 9, 11}}; |
| 300 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 301 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 302 | } |
| 303 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 304 | BOOST_DATA_TEST_CASE(AxisTooBig, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 305 | { |
| 306 | int32_t axis = 4; |
| 307 | TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}}; |
| 308 | TestTensor bIn{armnn::TensorShape{1,1,1,1},{0}}; |
| 309 | |
| 310 | // The axis must be within the range of [-rank(values), rank(values)) |
| 311 | // see: https://www.tensorflow.org/api_docs/python/tf/concat |
| 312 | TestTensor uncheckedOutput{armnn::TensorShape{1,1,1,1},{0}}; |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 313 | V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE; |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 314 | ConcatTestImpl({&aIn, &bIn}, axis, uncheckedOutput, sample, expectedParserStatus); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 315 | } |
| 316 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 317 | BOOST_DATA_TEST_CASE(AxisTooSmall, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 318 | { |
| 319 | int32_t axis = -5; |
| 320 | TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}}; |
| 321 | TestTensor bIn{armnn::TensorShape{1,1,1,1},{0}}; |
| 322 | |
| 323 | // The axis must be within the range of [-rank(values), rank(values)) |
| 324 | // see: https://www.tensorflow.org/api_docs/python/tf/concat |
| 325 | TestTensor uncheckedOutput{armnn::TensorShape{1,1,1,1},{0}}; |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 326 | V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE; |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 327 | ConcatTestImpl({&aIn, &bIn}, axis, uncheckedOutput, sample, expectedParserStatus); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 328 | } |
| 329 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 330 | BOOST_DATA_TEST_CASE(TooFewInputs, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 331 | { |
| 332 | int32_t axis = 0; |
| 333 | TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}}; |
| 334 | |
| 335 | // We need at least two tensors to concatenate |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 336 | V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE; |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 337 | ConcatTestImpl({&aIn}, axis, aIn, sample, expectedParserStatus); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 338 | } |
| 339 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 340 | BOOST_DATA_TEST_CASE(MismatchedInputDimensions, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 341 | { |
| 342 | int32_t axis = 3; |
| 343 | TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1, |
| 344 | 2, 3}}; |
| 345 | TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6, |
| 346 | 7, 8, 9}}; |
| 347 | TestTensor mismatched{armnn::TensorShape{1,1,1,1},{10}}; |
| 348 | |
| 349 | TestTensor expected{armnn::TensorShape{1,1,2,6},{0, 1, 4, 5, 6, 10, |
| 350 | 2, 3, 7, 8, 9, 11}}; |
| 351 | |
| 352 | // The input dimensions must be compatible |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 353 | V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE; |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 354 | ConcatTestImpl({&aIn, &bIn, &mismatched}, axis, expected, sample, expectedParserStatus); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 355 | } |
| 356 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 357 | BOOST_DATA_TEST_CASE(MismatchedInputRanks, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 358 | { |
| 359 | int32_t axis = 2; |
| 360 | TestTensor aIn{armnn::TensorShape{1,1,2},{0,1}}; |
| 361 | TestTensor bIn{armnn::TensorShape{1,1},{4}}; |
| 362 | TestTensor expected{armnn::TensorShape{1,1,3},{0,1,4}}; |
| 363 | |
| 364 | // The input dimensions must be compatible |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 365 | V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE; |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 366 | ConcatTestImpl({&aIn, &bIn}, axis, expected, sample, expectedParserStatus); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 367 | } |
| 368 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 369 | BOOST_DATA_TEST_CASE(MismatchedOutputDimensions, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 370 | { |
| 371 | int32_t axis = 3; |
| 372 | TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1, |
| 373 | 2, 3}}; |
| 374 | TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6, |
| 375 | 7, 8, 9}}; |
| 376 | TestTensor cIn{armnn::TensorShape{1,1,2,1},{10, |
| 377 | 11}}; |
| 378 | |
| 379 | TestTensor mismatched{armnn::TensorShape{1,1,6,2},{0, 1, 4, 5, 6, 10, |
| 380 | 2, 3, 7, 8, 9, 11}}; |
| 381 | |
| 382 | // The input and output dimensions must be compatible |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 383 | V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE; |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 384 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, mismatched, sample, expectedParserStatus); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 385 | } |
| 386 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 387 | BOOST_DATA_TEST_CASE(MismatchedOutputRank, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 388 | { |
| 389 | int32_t axis = 3; |
| 390 | TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1, |
| 391 | 2, 3}}; |
| 392 | TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6, |
| 393 | 7, 8, 9}}; |
| 394 | TestTensor cIn{armnn::TensorShape{1,1,2,1},{10, |
| 395 | 11}}; |
| 396 | |
| 397 | TestTensor mismatched{armnn::TensorShape{6,2},{0, 1, 4, 5, 6, 10, |
| 398 | 2, 3, 7, 8, 9, 11}}; |
| 399 | |
| 400 | // The input and output ranks must match |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 401 | V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE; |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 402 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, mismatched, sample, expectedParserStatus); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 403 | } |
| 404 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 405 | BOOST_DATA_TEST_CASE(ValidNegativeAxis, COMPUTE_DEVICES) |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 406 | { |
| 407 | // this is the same as 3 |
| 408 | // see: https://www.tensorflow.org/api_docs/python/tf/concat |
| 409 | int32_t axis = -1; |
| 410 | TestTensor aIn{armnn::TensorShape{1,1,2,2},{0, 1, |
| 411 | 2, 3}}; |
| 412 | TestTensor bIn{armnn::TensorShape{1,1,2,3},{4, 5, 6, |
| 413 | 7, 8, 9}}; |
| 414 | TestTensor cIn{armnn::TensorShape{1,1,2,1},{10, |
| 415 | 11}}; |
| 416 | |
| 417 | TestTensor expected{armnn::TensorShape{1,1,2,6},{0, 1, 4, 5, 6, 10, |
| 418 | 2, 3, 7, 8, 9, 11}}; |
| 419 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 420 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | BOOST_DATA_TEST_CASE(SimpleConcatAxisZero3D, COMPUTE_DEVICES) |
| 424 | { |
| 425 | int32_t axis = 0; |
| 426 | TestTensor aIn{armnn::TensorShape{1,1,1},{0}}; |
| 427 | TestTensor bIn{armnn::TensorShape{1,1,1},{1}}; |
| 428 | TestTensor cIn{armnn::TensorShape{1,1,1},{2}}; |
| 429 | |
| 430 | TestTensor expected{armnn::TensorShape{3,1,1},{0,1,2}}; |
| 431 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 432 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | BOOST_DATA_TEST_CASE(SimpleConcatAxisOne3D, COMPUTE_DEVICES) |
| 436 | { |
| 437 | int32_t axis = 1; |
| 438 | TestTensor aIn{armnn::TensorShape{1,1,1},{0}}; |
| 439 | TestTensor bIn{armnn::TensorShape{1,1,1},{1}}; |
| 440 | TestTensor cIn{armnn::TensorShape{1,1,1},{2}}; |
| 441 | |
| 442 | TestTensor expected{armnn::TensorShape{1,3,1},{0,1,2}}; |
| 443 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 444 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | BOOST_DATA_TEST_CASE(SimpleConcatAxisTwo3D, COMPUTE_DEVICES) |
| 448 | { |
| 449 | int32_t axis = 2; |
| 450 | TestTensor aIn{armnn::TensorShape{1,1,1},{0}}; |
| 451 | TestTensor bIn{armnn::TensorShape{1,1,1},{1}}; |
| 452 | TestTensor cIn{armnn::TensorShape{1,1,1},{2}}; |
| 453 | |
| 454 | TestTensor expected{armnn::TensorShape{1,1,3},{0,1,2}}; |
| 455 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 456 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | BOOST_DATA_TEST_CASE(SimpleConcatAxisZero2D, COMPUTE_DEVICES) |
| 460 | { |
| 461 | int32_t axis = 0; |
| 462 | TestTensor aIn{armnn::TensorShape{1,1},{0}}; |
| 463 | TestTensor bIn{armnn::TensorShape{1,1},{1}}; |
| 464 | TestTensor cIn{armnn::TensorShape{1,1},{2}}; |
| 465 | |
| 466 | TestTensor expected{armnn::TensorShape{3,1},{0,1,2}}; |
| 467 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 468 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | BOOST_DATA_TEST_CASE(SimpleConcatAxisOne2D, COMPUTE_DEVICES) |
| 472 | { |
| 473 | int32_t axis = 1; |
| 474 | TestTensor aIn{armnn::TensorShape{1,1},{0}}; |
| 475 | TestTensor bIn{armnn::TensorShape{1,1},{1}}; |
| 476 | TestTensor cIn{armnn::TensorShape{1,1},{2}}; |
| 477 | |
| 478 | TestTensor expected{armnn::TensorShape{1,3},{0,1,2}}; |
| 479 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 480 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | BOOST_DATA_TEST_CASE(SimpleConcatAxisZero1D, COMPUTE_DEVICES) |
| 484 | { |
| 485 | int32_t axis = 0; |
| 486 | TestTensor aIn{armnn::TensorShape{1},{0}}; |
| 487 | TestTensor bIn{armnn::TensorShape{1},{1}}; |
| 488 | TestTensor cIn{armnn::TensorShape{1},{2}}; |
| 489 | |
| 490 | TestTensor expected{armnn::TensorShape{3},{0,1,2}}; |
| 491 | |
Jim Flynn | 7b1e41f | 2019-05-22 18:00:04 +0100 | [diff] [blame] | 492 | ConcatTestImpl({&aIn, &bIn, &cIn}, axis, expected, sample); |
surmeh01 | 49b9e10 | 2018-05-17 14:11:25 +0100 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | BOOST_AUTO_TEST_SUITE_END() |