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