Laurent Carlier | 749294b | 2020-06-01 09:03:17 +0100 | [diff] [blame] | 1 | // |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 5 | |
| 6 | #include "WorkloadTestUtils.hpp" |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 7 | |
| 8 | #include <armnn/Exceptions.hpp> |
| 9 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 10 | #include <backendsCommon/CpuTensorHandle.hpp> |
| 11 | #include <backendsCommon/Workload.hpp> |
| 12 | |
| 13 | #include <reference/workloads/RefWorkloads.hpp> |
| 14 | #include <reference/RefWorkloadFactory.hpp> |
| 15 | |
| 16 | #include <boost/test/unit_test.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace armnn; |
| 19 | |
| 20 | BOOST_AUTO_TEST_SUITE(WorkloadInfoValidation) |
| 21 | |
Mike Kelly | 1ced464 | 2020-03-04 18:01:13 +0000 | [diff] [blame] | 22 | BOOST_AUTO_TEST_CASE(BatchNormalizationQueueDescriptor_Validate_DifferentQuantizationData) |
| 23 | { |
| 24 | TensorShape inputShape { 1, 3, 2, 2 }; |
| 25 | TensorShape outputShape { 1, 3, 2, 2 }; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 26 | |
Mike Kelly | 1ced464 | 2020-03-04 18:01:13 +0000 | [diff] [blame] | 27 | TensorInfo inputTensorInfo(inputShape, armnn::DataType::QAsymmU8, .1f, 125); |
| 28 | TensorInfo outputTensorInfo(outputShape, armnn::DataType::QAsymmU8, .2f, 120); |
| 29 | |
| 30 | BatchNormalizationQueueDescriptor invalidData; |
| 31 | WorkloadInfo invalidInfo; |
| 32 | |
| 33 | unsigned int sameShape[] = { 10 }; |
| 34 | TensorInfo sameInfo = armnn::TensorInfo(1, sameShape, armnn::DataType::QAsymmU8); |
| 35 | ScopedCpuTensorHandle sameTensor(sameInfo); |
| 36 | |
| 37 | AddInputToWorkload(invalidData, invalidInfo, inputTensorInfo, nullptr); |
| 38 | AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr); |
| 39 | |
| 40 | invalidData.m_Mean = &sameTensor; |
| 41 | invalidData.m_Variance = &sameTensor; |
| 42 | invalidData.m_Beta= &sameTensor; |
| 43 | invalidData.m_Gamma = &sameTensor; |
| 44 | |
| 45 | BOOST_CHECK_NO_THROW(RefBatchNormalizationWorkload(invalidData, invalidInfo)); |
| 46 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 47 | |
| 48 | BOOST_AUTO_TEST_CASE(QueueDescriptor_Validate_WrongNumOfInputsOutputs) |
| 49 | { |
| 50 | InputQueueDescriptor invalidData; |
| 51 | WorkloadInfo invalidInfo; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 52 | //Invalid argument exception is expected, because no inputs and no outputs were defined. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 53 | BOOST_CHECK_THROW(RefWorkloadFactory().CreateInput(invalidData, invalidInfo), armnn::InvalidArgumentException); |
| 54 | } |
| 55 | |
| 56 | BOOST_AUTO_TEST_CASE(RefPooling2dFloat32Workload_Validate_WrongDimTensor) |
| 57 | { |
| 58 | armnn::TensorInfo inputTensorInfo; |
| 59 | armnn::TensorInfo outputTensorInfo; |
| 60 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 61 | unsigned int inputShape[] = {2, 3, 4}; // <- Invalid - input tensor has to be 4D. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 62 | unsigned int outputShape[] = {2, 3, 4, 5}; |
| 63 | |
| 64 | outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32); |
| 65 | inputTensorInfo = armnn::TensorInfo(3, inputShape, armnn::DataType::Float32); |
| 66 | |
| 67 | Pooling2dQueueDescriptor invalidData; |
| 68 | WorkloadInfo invalidInfo; |
| 69 | |
| 70 | AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr); |
| 71 | AddInputToWorkload(invalidData, invalidInfo, inputTensorInfo, nullptr); |
| 72 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 73 | // Invalid argument exception is expected, input tensor has to be 4D. |
Teresa Charlin | a3b2047 | 2019-06-06 11:12:32 +0100 | [diff] [blame] | 74 | BOOST_CHECK_THROW(RefPooling2dWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | BOOST_AUTO_TEST_CASE(SoftmaxQueueDescriptor_Validate_WrongInputHeight) |
| 78 | { |
| 79 | unsigned int inputHeight = 1; |
| 80 | unsigned int inputWidth = 1; |
| 81 | unsigned int inputChannels = 4; |
| 82 | unsigned int inputNum = 2; |
| 83 | |
| 84 | unsigned int outputChannels = inputChannels; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 85 | unsigned int outputHeight = inputHeight + 1; //Makes data invalid - Softmax expects height and width to be 1. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 86 | unsigned int outputWidth = inputWidth; |
| 87 | unsigned int outputNum = inputNum; |
| 88 | |
| 89 | armnn::TensorInfo inputTensorInfo; |
| 90 | armnn::TensorInfo outputTensorInfo; |
| 91 | |
| 92 | unsigned int inputShape[] = { inputNum, inputChannels, inputHeight, inputWidth }; |
| 93 | unsigned int outputShape[] = { outputNum, outputChannels, outputHeight, outputWidth }; |
| 94 | |
| 95 | inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32); |
| 96 | outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32); |
| 97 | |
| 98 | SoftmaxQueueDescriptor invalidData; |
| 99 | WorkloadInfo invalidInfo; |
| 100 | |
| 101 | AddInputToWorkload(invalidData, invalidInfo, inputTensorInfo, nullptr); |
| 102 | AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr); |
| 103 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 104 | //Invalid argument exception is expected, because height != 1. |
nikraj01 | a121de3 | 2019-05-29 10:51:05 +0100 | [diff] [blame] | 105 | BOOST_CHECK_THROW(RefSoftmaxWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | BOOST_AUTO_TEST_CASE(FullyConnectedQueueDescriptor_Validate_RequiredDataMissing) |
| 109 | { |
| 110 | unsigned int inputWidth = 1; |
| 111 | unsigned int inputHeight = 1; |
| 112 | unsigned int inputChannels = 5; |
| 113 | unsigned int inputNum = 2; |
| 114 | |
| 115 | unsigned int outputWidth = 1; |
| 116 | unsigned int outputHeight = 1; |
| 117 | unsigned int outputChannels = 3; |
| 118 | unsigned int outputNum = 2; |
| 119 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 120 | // Define the tensor descriptors. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 121 | armnn::TensorInfo inputTensorInfo; |
| 122 | armnn::TensorInfo outputTensorInfo; |
| 123 | armnn::TensorInfo weightsDesc; |
| 124 | armnn::TensorInfo biasesDesc; |
| 125 | |
| 126 | unsigned int inputShape[] = { inputNum, inputChannels, inputHeight, inputWidth }; |
| 127 | unsigned int outputShape[] = { outputNum, outputChannels, outputHeight, outputWidth }; |
| 128 | unsigned int weightsShape[] = { 1, 1, inputChannels, outputChannels }; |
| 129 | unsigned int biasShape[] = { 1, outputChannels, outputHeight, outputWidth }; |
| 130 | |
| 131 | inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32); |
| 132 | outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32); |
| 133 | weightsDesc = armnn::TensorInfo(4, weightsShape, armnn::DataType::Float32); |
| 134 | biasesDesc = armnn::TensorInfo(4, biasShape, armnn::DataType::Float32); |
| 135 | |
| 136 | FullyConnectedQueueDescriptor invalidData; |
| 137 | WorkloadInfo invalidInfo; |
| 138 | |
| 139 | ScopedCpuTensorHandle weightTensor(weightsDesc); |
| 140 | ScopedCpuTensorHandle biasTensor(biasesDesc); |
| 141 | |
| 142 | AddInputToWorkload(invalidData, invalidInfo, inputTensorInfo, nullptr); |
| 143 | AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr); |
| 144 | invalidData.m_Weight = &weightTensor; |
| 145 | invalidData.m_Bias = &biasTensor; |
| 146 | invalidData.m_Parameters.m_BiasEnabled = true; |
| 147 | invalidData.m_Parameters.m_TransposeWeightMatrix = false; |
| 148 | |
| 149 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 150 | //Invalid argument exception is expected, because not all required fields have been provided. |
| 151 | //In particular inputsData[0], outputsData[0] and weightsData can not be null. |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 152 | BOOST_CHECK_THROW(RefFullyConnectedWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | |
| 156 | BOOST_AUTO_TEST_CASE(NormalizationQueueDescriptor_Validate_WrongInputHeight) |
| 157 | { |
| 158 | constexpr unsigned int inputNum = 5; |
| 159 | constexpr unsigned int inputHeight = 32; |
| 160 | constexpr unsigned int inputWidth = 24; |
| 161 | constexpr unsigned int inputChannels = 3; |
| 162 | |
| 163 | constexpr unsigned int outputNum = inputNum; |
| 164 | constexpr unsigned int outputChannels = inputChannels; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 165 | constexpr unsigned int outputHeight = inputHeight + 1; //Makes data invalid - normalization requires. |
| 166 | //Input and output to have the same dimensions. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 167 | constexpr unsigned int outputWidth = inputWidth; |
| 168 | |
| 169 | |
| 170 | armnn::TensorInfo inputTensorInfo; |
| 171 | armnn::TensorInfo outputTensorInfo; |
| 172 | |
| 173 | unsigned int inputShape[] = {inputNum, inputChannels, inputHeight, inputWidth}; |
| 174 | unsigned int outputShape[] = {outputNum, outputChannels, outputHeight, outputWidth}; |
| 175 | |
| 176 | inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32); |
| 177 | outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32); |
| 178 | |
| 179 | |
| 180 | armnn::NormalizationAlgorithmMethod normMethod = armnn::NormalizationAlgorithmMethod::LocalBrightness; |
| 181 | armnn::NormalizationAlgorithmChannel normChannel = armnn::NormalizationAlgorithmChannel::Across; |
| 182 | float alpha = 1.f; |
| 183 | float beta = 1.f; |
| 184 | float kappa = 1.f; |
| 185 | uint32_t normSize = 5; |
| 186 | |
| 187 | NormalizationQueueDescriptor invalidData; |
| 188 | WorkloadInfo invalidInfo; |
| 189 | |
| 190 | AddInputToWorkload(invalidData, invalidInfo, inputTensorInfo, nullptr); |
| 191 | AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr); |
| 192 | invalidData.m_Parameters.m_NormChannelType = normChannel; |
| 193 | invalidData.m_Parameters.m_NormMethodType = normMethod; |
| 194 | invalidData.m_Parameters.m_NormSize = normSize; |
| 195 | invalidData.m_Parameters.m_Alpha = alpha; |
| 196 | invalidData.m_Parameters.m_Beta = beta; |
| 197 | invalidData.m_Parameters.m_K = kappa; |
| 198 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 199 | //Invalid argument exception is expected, because input height != output height. |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 200 | BOOST_CHECK_THROW(RefNormalizationWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | BOOST_AUTO_TEST_CASE(SplitterQueueDescriptor_Validate_WrongWindow) |
| 204 | { |
| 205 | constexpr unsigned int inputNum = 1; |
| 206 | constexpr unsigned int inputHeight = 32; |
| 207 | constexpr unsigned int inputWidth = 24; |
| 208 | constexpr unsigned int inputChannels = 3; |
| 209 | |
| 210 | constexpr unsigned int outputNum = inputNum; |
| 211 | constexpr unsigned int outputChannels = inputChannels; |
| 212 | constexpr unsigned int outputHeight = 18; |
| 213 | constexpr unsigned int outputWidth = inputWidth; |
| 214 | |
| 215 | |
| 216 | armnn::TensorInfo inputTensorInfo; |
| 217 | armnn::TensorInfo outputTensorInfo; |
| 218 | |
| 219 | unsigned int inputShape[] = {inputNum, inputChannels, inputHeight, inputWidth}; |
| 220 | unsigned int outputShape[] = {outputNum, outputChannels, outputHeight, outputWidth}; |
| 221 | |
| 222 | inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32); |
| 223 | outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32); |
| 224 | |
| 225 | SplitterQueueDescriptor invalidData; |
| 226 | WorkloadInfo invalidInfo; |
| 227 | |
| 228 | AddInputToWorkload(invalidData, invalidInfo, inputTensorInfo, nullptr); |
| 229 | AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr); |
| 230 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 231 | // Invalid, since it has only 3 dimensions while the input tensor is 4d. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 232 | std::vector<unsigned int> wOrigin = {0, 0, 0}; |
| 233 | armnn::SplitterQueueDescriptor::ViewOrigin window(wOrigin); |
| 234 | invalidData.m_ViewOrigins.push_back(window); |
| 235 | |
| 236 | BOOST_TEST_INFO("Invalid argument exception is expected, because split window dimensionality does not " |
| 237 | "match input."); |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 238 | BOOST_CHECK_THROW(RefSplitterWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 239 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 240 | // Invalid, since window extends past the boundary of input tensor. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 241 | std::vector<unsigned int> wOrigin3 = {0, 0, 15, 0}; |
| 242 | armnn::SplitterQueueDescriptor::ViewOrigin window3(wOrigin3); |
| 243 | invalidData.m_ViewOrigins[0] = window3; |
| 244 | BOOST_TEST_INFO("Invalid argument exception is expected (wOrigin3[2]+ outputHeight > inputHeight"); |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 245 | BOOST_CHECK_THROW(RefSplitterWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 246 | |
| 247 | |
| 248 | std::vector<unsigned int> wOrigin4 = {0, 0, 0, 0}; |
| 249 | armnn::SplitterQueueDescriptor::ViewOrigin window4(wOrigin4); |
| 250 | invalidData.m_ViewOrigins[0] = window4; |
| 251 | |
| 252 | std::vector<unsigned int> wOrigin5 = {1, 16, 20, 2}; |
| 253 | armnn::SplitterQueueDescriptor::ViewOrigin window5(wOrigin4); |
| 254 | invalidData.m_ViewOrigins.push_back(window5); |
| 255 | |
| 256 | BOOST_TEST_INFO("Invalid exception due to number of split windows not matching number of outputs."); |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 257 | BOOST_CHECK_THROW(RefSplitterWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 261 | BOOST_AUTO_TEST_CASE(ConcatQueueDescriptor_Validate_WrongWindow) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 262 | { |
| 263 | constexpr unsigned int inputNum = 1; |
| 264 | constexpr unsigned int inputChannels = 3; |
| 265 | constexpr unsigned int inputHeight = 32; |
| 266 | constexpr unsigned int inputWidth = 24; |
| 267 | |
| 268 | constexpr unsigned int outputNum = 1; |
| 269 | constexpr unsigned int outputChannels = 3; |
| 270 | constexpr unsigned int outputHeight = 32; |
| 271 | constexpr unsigned int outputWidth = 24; |
| 272 | |
| 273 | |
| 274 | armnn::TensorInfo inputTensorInfo; |
| 275 | armnn::TensorInfo outputTensorInfo; |
| 276 | |
| 277 | unsigned int inputShape[] = {inputNum, inputChannels, inputHeight, inputWidth}; |
| 278 | unsigned int outputShape[] = {outputNum, outputChannels, outputHeight, outputWidth}; |
| 279 | |
| 280 | inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32); |
| 281 | outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32); |
| 282 | |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 283 | ConcatQueueDescriptor invalidData; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 284 | WorkloadInfo invalidInfo; |
| 285 | |
| 286 | AddInputToWorkload(invalidData, invalidInfo, inputTensorInfo, nullptr); |
| 287 | AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr); |
| 288 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 289 | // Invalid, since it has only 3 dimensions while the input tensor is 4d. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 290 | std::vector<unsigned int> wOrigin = {0, 0, 0}; |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 291 | armnn::ConcatQueueDescriptor::ViewOrigin window(wOrigin); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 292 | invalidData.m_ViewOrigins.push_back(window); |
| 293 | |
| 294 | BOOST_TEST_INFO("Invalid argument exception is expected, because merge window dimensionality does not " |
| 295 | "match input."); |
Jim Flynn | 4ed34ed | 2019-05-17 15:32:17 +0100 | [diff] [blame] | 296 | BOOST_CHECK_THROW(RefConcatWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 297 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 298 | // Invalid, since window extends past the boundary of output tensor. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 299 | std::vector<unsigned int> wOrigin3 = {0, 0, 15, 0}; |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 300 | armnn::ConcatQueueDescriptor::ViewOrigin window3(wOrigin3); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 301 | invalidData.m_ViewOrigins[0] = window3; |
| 302 | BOOST_TEST_INFO("Invalid argument exception is expected (wOrigin3[2]+ inputHeight > outputHeight"); |
Jim Flynn | 4ed34ed | 2019-05-17 15:32:17 +0100 | [diff] [blame] | 303 | BOOST_CHECK_THROW(RefConcatWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 304 | |
| 305 | |
| 306 | std::vector<unsigned int> wOrigin4 = {0, 0, 0, 0}; |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 307 | armnn::ConcatQueueDescriptor::ViewOrigin window4(wOrigin4); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 308 | invalidData.m_ViewOrigins[0] = window4; |
| 309 | |
| 310 | std::vector<unsigned int> wOrigin5 = {1, 16, 20, 2}; |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 311 | armnn::ConcatQueueDescriptor::ViewOrigin window5(wOrigin4); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 312 | invalidData.m_ViewOrigins.push_back(window5); |
| 313 | |
| 314 | BOOST_TEST_INFO("Invalid exception due to number of merge windows not matching number of inputs."); |
Jim Flynn | 4ed34ed | 2019-05-17 15:32:17 +0100 | [diff] [blame] | 315 | BOOST_CHECK_THROW(RefConcatWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | BOOST_AUTO_TEST_CASE(AdditionQueueDescriptor_Validate_InputNumbers) |
| 319 | { |
| 320 | armnn::TensorInfo input1TensorInfo; |
| 321 | armnn::TensorInfo input2TensorInfo; |
| 322 | armnn::TensorInfo input3TensorInfo; |
| 323 | armnn::TensorInfo outputTensorInfo; |
| 324 | |
| 325 | unsigned int shape[] = {1, 1, 1, 1}; |
| 326 | |
| 327 | input1TensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32); |
| 328 | input2TensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32); |
| 329 | input3TensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32); |
| 330 | outputTensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32); |
| 331 | |
| 332 | AdditionQueueDescriptor invalidData; |
| 333 | WorkloadInfo invalidInfo; |
| 334 | |
| 335 | AddInputToWorkload(invalidData, invalidInfo, input1TensorInfo, nullptr); |
| 336 | AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr); |
| 337 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 338 | // Too few inputs. |
Finn Williams | cbd2c23 | 2020-06-22 15:58:32 +0100 | [diff] [blame] | 339 | BOOST_CHECK_THROW(RefAdditionWorkload<>(invalidData, invalidInfo), armnn::InvalidArgumentException); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 340 | |
| 341 | AddInputToWorkload(invalidData, invalidInfo, input2TensorInfo, nullptr); |
| 342 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 343 | // Correct. |
Finn Williams | cbd2c23 | 2020-06-22 15:58:32 +0100 | [diff] [blame] | 344 | BOOST_CHECK_NO_THROW(RefAdditionWorkload<>(invalidData, invalidInfo)); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 345 | |
| 346 | AddInputToWorkload(invalidData, invalidInfo, input3TensorInfo, nullptr); |
| 347 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 348 | // Too many inputs. |
Finn Williams | cbd2c23 | 2020-06-22 15:58:32 +0100 | [diff] [blame] | 349 | BOOST_CHECK_THROW(RefAdditionWorkload<>(invalidData, invalidInfo), armnn::InvalidArgumentException); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | BOOST_AUTO_TEST_CASE(AdditionQueueDescriptor_Validate_InputShapes) |
| 353 | { |
| 354 | armnn::TensorInfo input1TensorInfo; |
| 355 | armnn::TensorInfo input2TensorInfo; |
| 356 | armnn::TensorInfo outputTensorInfo; |
| 357 | |
| 358 | unsigned int shape1[] = {1, 1, 2, 1}; |
| 359 | unsigned int shape2[] = {1, 1, 3, 2}; |
| 360 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 361 | // Incompatible shapes even with broadcasting. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 362 | { |
| 363 | input1TensorInfo = armnn::TensorInfo(4, shape1, armnn::DataType::Float32); |
| 364 | input2TensorInfo = armnn::TensorInfo(4, shape2, armnn::DataType::Float32); |
| 365 | outputTensorInfo = armnn::TensorInfo(4, shape1, armnn::DataType::Float32); |
| 366 | |
| 367 | AdditionQueueDescriptor invalidData; |
| 368 | WorkloadInfo invalidInfo; |
| 369 | |
| 370 | AddInputToWorkload(invalidData, invalidInfo, input1TensorInfo, nullptr); |
| 371 | AddInputToWorkload(invalidData, invalidInfo, input2TensorInfo, nullptr); |
| 372 | AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr); |
| 373 | |
Finn Williams | cbd2c23 | 2020-06-22 15:58:32 +0100 | [diff] [blame] | 374 | BOOST_CHECK_THROW(RefAdditionWorkload<>(invalidData, invalidInfo), armnn::InvalidArgumentException); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 375 | } |
| 376 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 377 | // Output size not compatible with input sizes. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 378 | { |
| 379 | input1TensorInfo = armnn::TensorInfo(4, shape1, armnn::DataType::Float32); |
| 380 | input2TensorInfo = armnn::TensorInfo(4, shape1, armnn::DataType::Float32); |
| 381 | outputTensorInfo = armnn::TensorInfo(4, shape2, armnn::DataType::Float32); |
| 382 | |
| 383 | AdditionQueueDescriptor invalidData; |
| 384 | WorkloadInfo invalidInfo; |
| 385 | |
| 386 | AddInputToWorkload(invalidData, invalidInfo, input1TensorInfo, nullptr); |
| 387 | AddInputToWorkload(invalidData, invalidInfo, input2TensorInfo, nullptr); |
| 388 | AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr); |
| 389 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 390 | // Output differs. |
Finn Williams | cbd2c23 | 2020-06-22 15:58:32 +0100 | [diff] [blame] | 391 | BOOST_CHECK_THROW(RefAdditionWorkload<>(invalidData, invalidInfo), armnn::InvalidArgumentException); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | |
| 395 | BOOST_AUTO_TEST_CASE(MultiplicationQueueDescriptor_Validate_InputTensorDimensionMismatch) |
| 396 | { |
| 397 | armnn::TensorInfo input0TensorInfo; |
| 398 | armnn::TensorInfo input1TensorInfo; |
| 399 | armnn::TensorInfo outputTensorInfo; |
| 400 | |
| 401 | constexpr unsigned int input0Shape[] = { 2, 2, 4, 4 }; |
| 402 | constexpr std::size_t dimensionCount = std::extent<decltype(input0Shape)>::value; |
| 403 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 404 | // Checks dimension consistency for input tensors. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 405 | for (unsigned int dimIndex = 0; dimIndex < dimensionCount; ++dimIndex) |
| 406 | { |
| 407 | unsigned int input1Shape[dimensionCount]; |
| 408 | for (unsigned int i = 0; i < dimensionCount; ++i) |
| 409 | { |
| 410 | input1Shape[i] = input0Shape[i]; |
| 411 | } |
| 412 | |
| 413 | ++input1Shape[dimIndex]; |
| 414 | |
| 415 | input0TensorInfo = armnn::TensorInfo(dimensionCount, input0Shape, armnn::DataType::Float32); |
| 416 | input1TensorInfo = armnn::TensorInfo(dimensionCount, input1Shape, armnn::DataType::Float32); |
| 417 | outputTensorInfo = armnn::TensorInfo(dimensionCount, input0Shape, armnn::DataType::Float32); |
| 418 | |
| 419 | MultiplicationQueueDescriptor invalidData; |
| 420 | WorkloadInfo invalidInfo; |
| 421 | |
| 422 | AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr); |
| 423 | AddInputToWorkload(invalidData, invalidInfo, input0TensorInfo, nullptr); |
| 424 | AddInputToWorkload(invalidData, invalidInfo, input1TensorInfo, nullptr); |
| 425 | |
Finn Williams | cbd2c23 | 2020-06-22 15:58:32 +0100 | [diff] [blame] | 426 | BOOST_CHECK_THROW(RefMultiplicationWorkload<>(invalidData, invalidInfo), armnn::InvalidArgumentException); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 427 | } |
| 428 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 429 | // Checks dimension consistency for input and output tensors. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 430 | for (unsigned int dimIndex = 0; dimIndex < dimensionCount; ++dimIndex) |
| 431 | { |
| 432 | unsigned int outputShape[dimensionCount]; |
| 433 | for (unsigned int i = 0; i < dimensionCount; ++i) |
| 434 | { |
| 435 | outputShape[i] = input0Shape[i]; |
| 436 | } |
| 437 | |
| 438 | ++outputShape[dimIndex]; |
| 439 | |
| 440 | input0TensorInfo = armnn::TensorInfo(dimensionCount, input0Shape, armnn::DataType::Float32); |
| 441 | input1TensorInfo = armnn::TensorInfo(dimensionCount, input0Shape, armnn::DataType::Float32); |
| 442 | outputTensorInfo = armnn::TensorInfo(dimensionCount, outputShape, armnn::DataType::Float32); |
| 443 | |
| 444 | MultiplicationQueueDescriptor invalidData; |
| 445 | WorkloadInfo invalidInfo; |
| 446 | |
| 447 | AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr); |
| 448 | AddInputToWorkload(invalidData, invalidInfo, input0TensorInfo, nullptr); |
| 449 | AddInputToWorkload(invalidData, invalidInfo, input1TensorInfo, nullptr); |
| 450 | |
Finn Williams | cbd2c23 | 2020-06-22 15:58:32 +0100 | [diff] [blame] | 451 | BOOST_CHECK_THROW(RefMultiplicationWorkload<>(invalidData, invalidInfo), armnn::InvalidArgumentException); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | |
| 455 | BOOST_AUTO_TEST_CASE(ReshapeQueueDescriptor_Validate_MismatchingNumElements) |
| 456 | { |
| 457 | armnn::TensorInfo inputTensorInfo; |
| 458 | armnn::TensorInfo outputTensorInfo; |
| 459 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 460 | // The input and output shapes should have the same number of elements, but these don't. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 461 | unsigned int inputShape[] = { 1, 1, 2, 3 }; |
| 462 | unsigned int outputShape[] = { 1, 1, 1, 2 }; |
| 463 | |
| 464 | inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32); |
| 465 | outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32); |
| 466 | |
| 467 | ReshapeQueueDescriptor invalidData; |
| 468 | WorkloadInfo invalidInfo; |
| 469 | |
| 470 | AddInputToWorkload(invalidData, invalidInfo, inputTensorInfo, nullptr); |
| 471 | AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr); |
| 472 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 473 | // InvalidArgumentException is expected, because the number of elements don't match. |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 474 | BOOST_CHECK_THROW(RefReshapeWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 475 | } |
| 476 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 477 | |
| 478 | BOOST_AUTO_TEST_CASE(LstmQueueDescriptor_Validate) |
| 479 | { |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 480 | armnn::DataType dataType = armnn::DataType::Float32; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 481 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 482 | float qScale = 0.0f; |
| 483 | int32_t qOffset = 0; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 484 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 485 | unsigned int batchSize = 2; |
| 486 | unsigned int outputSize = 3; |
| 487 | unsigned int inputSize = 5; |
| 488 | unsigned numUnits = 4; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 489 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 490 | armnn::TensorInfo inputTensorInfo({batchSize , inputSize}, dataType, qScale, qOffset ); |
| 491 | armnn::TensorInfo outputStateInTensorInfo({batchSize , outputSize}, dataType, qScale, qOffset); |
| 492 | armnn::TensorInfo cellStateInTensorInfo({batchSize , numUnits}, dataType, qScale, qOffset); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 493 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 494 | // Scratch buffer size with CIFG [batchSize, numUnits * 4] |
| 495 | armnn::TensorInfo scratchBufferTensorInfo({batchSize, numUnits * 4}, dataType, qScale, qOffset); |
| 496 | armnn::TensorInfo cellStateOutTensorInfo({batchSize, numUnits}, dataType, qScale, qOffset); |
| 497 | armnn::TensorInfo outputStateOutTensorInfo({batchSize, outputSize}, dataType, qScale, qOffset); |
| 498 | armnn::TensorInfo outputTensorInfo({batchSize, outputSize}, dataType, qScale, qOffset); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 499 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 500 | armnn::TensorInfo tensorInfo3({outputSize}, dataType, qScale, qOffset); |
| 501 | armnn::TensorInfo tensorInfo4({numUnits}, dataType, qScale, qOffset); |
| 502 | armnn::TensorInfo tensorInfo4x5({numUnits, inputSize}, dataType, qScale, qOffset); |
| 503 | armnn::TensorInfo tensorInfo4x3({numUnits, outputSize}, dataType, qScale, qOffset); |
| 504 | armnn::TensorInfo tensorInfo3x4({outputSize, numUnits}, dataType, qScale, qOffset); |
| 505 | |
| 506 | LstmQueueDescriptor data; |
| 507 | WorkloadInfo info; |
| 508 | |
| 509 | AddInputToWorkload(data, info, inputTensorInfo, nullptr); |
| 510 | AddInputToWorkload(data, info, outputStateInTensorInfo, nullptr); |
| 511 | AddInputToWorkload(data, info, cellStateInTensorInfo, nullptr); |
| 512 | |
| 513 | AddOutputToWorkload(data, info, scratchBufferTensorInfo, nullptr); |
| 514 | AddOutputToWorkload(data, info, outputStateOutTensorInfo, nullptr); |
| 515 | AddOutputToWorkload(data, info, cellStateOutTensorInfo, nullptr); |
| 516 | // AddOutputToWorkload(data, info, outputTensorInfo, nullptr); is left out |
| 517 | |
| 518 | armnn::ScopedCpuTensorHandle inputToInputWeightsTensor(tensorInfo4x5); |
| 519 | armnn::ScopedCpuTensorHandle inputToForgetWeightsTensor(tensorInfo4x5); |
| 520 | armnn::ScopedCpuTensorHandle inputToCellWeightsTensor(tensorInfo4x5); |
| 521 | armnn::ScopedCpuTensorHandle inputToOutputWeightsTensor(tensorInfo4x5); |
| 522 | armnn::ScopedCpuTensorHandle recurrentToForgetWeightsTensor(tensorInfo4x3); |
| 523 | armnn::ScopedCpuTensorHandle recurrentToInputWeightsTensor(tensorInfo4x3); |
| 524 | armnn::ScopedCpuTensorHandle recurrentToCellWeightsTensor(tensorInfo4x3); |
| 525 | armnn::ScopedCpuTensorHandle recurrentToOutputWeightsTensor(tensorInfo4x3); |
| 526 | armnn::ScopedCpuTensorHandle cellToInputWeightsTensor(tensorInfo4); |
| 527 | armnn::ScopedCpuTensorHandle inputGateBiasTensor(tensorInfo4); |
| 528 | armnn::ScopedCpuTensorHandle forgetGateBiasTensor(tensorInfo4); |
| 529 | armnn::ScopedCpuTensorHandle cellBiasTensor(tensorInfo4); |
| 530 | armnn::ScopedCpuTensorHandle outputGateBiasTensor(tensorInfo4); |
| 531 | armnn::ScopedCpuTensorHandle cellToForgetWeightsTensor(tensorInfo4); |
| 532 | armnn::ScopedCpuTensorHandle cellToOutputWeightsTensor(tensorInfo4); |
| 533 | armnn::ScopedCpuTensorHandle projectionWeightsTensor(tensorInfo3x4); |
| 534 | armnn::ScopedCpuTensorHandle projectionBiasTensor(tensorInfo3); |
| 535 | armnn::ScopedCpuTensorHandle inputLayerNormWeightsTensor(tensorInfo4); |
| 536 | armnn::ScopedCpuTensorHandle forgetLayerNormWeightsTensor(tensorInfo4); |
| 537 | armnn::ScopedCpuTensorHandle cellLayerNormWeightsTensor(tensorInfo4); |
| 538 | armnn::ScopedCpuTensorHandle outputLayerNormWeightsTensor(tensorInfo4); |
| 539 | |
| 540 | data.m_InputToInputWeights = &inputToInputWeightsTensor; |
| 541 | data.m_InputToForgetWeights = &inputToForgetWeightsTensor; |
| 542 | data.m_InputToCellWeights = &inputToCellWeightsTensor; |
| 543 | data.m_InputToOutputWeights = &inputToOutputWeightsTensor; |
| 544 | data.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor; |
| 545 | data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor; |
| 546 | data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor; |
| 547 | data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor; |
| 548 | data.m_CellToInputWeights = &cellToInputWeightsTensor; |
| 549 | data.m_InputGateBias = &inputGateBiasTensor; |
| 550 | data.m_ForgetGateBias = &forgetGateBiasTensor; |
| 551 | data.m_CellBias = &cellBiasTensor; |
| 552 | data.m_OutputGateBias = &outputGateBiasTensor; |
| 553 | data.m_CellToForgetWeights = &cellToForgetWeightsTensor; |
| 554 | data.m_CellToOutputWeights = &cellToOutputWeightsTensor; |
| 555 | data.m_ProjectionWeights = &projectionWeightsTensor; |
| 556 | data.m_ProjectionBias = &projectionBiasTensor; |
| 557 | |
| 558 | data.m_InputLayerNormWeights = &inputLayerNormWeightsTensor; |
| 559 | data.m_ForgetLayerNormWeights = &forgetLayerNormWeightsTensor; |
| 560 | data.m_CellLayerNormWeights = &cellLayerNormWeightsTensor; |
| 561 | data.m_OutputLayerNormWeights = &outputLayerNormWeightsTensor; |
| 562 | |
| 563 | // Flags to set test configuration |
| 564 | data.m_Parameters.m_ActivationFunc = 4; |
| 565 | data.m_Parameters.m_CifgEnabled = false; |
| 566 | data.m_Parameters.m_PeepholeEnabled = true; |
| 567 | data.m_Parameters.m_ProjectionEnabled = true; |
| 568 | data.m_Parameters.m_LayerNormEnabled = true; |
| 569 | |
| 570 | // check wrong number of outputs |
| 571 | BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException); |
| 572 | AddOutputToWorkload(data, info, outputTensorInfo, nullptr); |
| 573 | |
| 574 | // check wrong cifg parameter configuration |
| 575 | data.m_Parameters.m_CifgEnabled = true; |
| 576 | armnn::TensorInfo scratchBufferTensorInfo2({batchSize, numUnits * 3}, dataType, qScale, qOffset); |
| 577 | SetWorkloadOutput(data, info, 0, scratchBufferTensorInfo2, nullptr); |
| 578 | BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException); |
| 579 | data.m_Parameters.m_CifgEnabled = false; |
| 580 | SetWorkloadOutput(data, info, 0, scratchBufferTensorInfo, nullptr); |
| 581 | |
| 582 | // check wrong inputGateBias configuration |
| 583 | data.m_InputGateBias = nullptr; |
| 584 | BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException); |
| 585 | data.m_InputGateBias = &inputGateBiasTensor; |
| 586 | |
| 587 | // check inconsistant projection parameters |
| 588 | data.m_Parameters.m_ProjectionEnabled = false; |
| 589 | BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException); |
| 590 | data.m_Parameters.m_ProjectionEnabled = true; |
| 591 | data.m_ProjectionWeights = nullptr; |
| 592 | BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException); |
| 593 | data.m_ProjectionWeights = &projectionWeightsTensor; |
| 594 | |
| 595 | // check missing input layer normalisation weights |
| 596 | data.m_InputLayerNormWeights = nullptr; |
| 597 | BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException); |
| 598 | data.m_InputLayerNormWeights = &inputLayerNormWeightsTensor; |
| 599 | |
| 600 | // layer norm disabled but normalisation weights are present |
| 601 | data.m_Parameters.m_LayerNormEnabled = false; |
| 602 | BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException); |
| 603 | data.m_Parameters.m_LayerNormEnabled = true; |
| 604 | |
| 605 | // check invalid outputTensor shape |
| 606 | armnn::TensorInfo incorrectOutputTensorInfo({batchSize, outputSize + 1}, dataType, qScale, qOffset); |
| 607 | SetWorkloadOutput(data, info, 3, incorrectOutputTensorInfo, nullptr); |
| 608 | BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException); |
| 609 | SetWorkloadOutput(data, info, 3, outputTensorInfo, nullptr); |
| 610 | |
janeil01 | 17d8d85 | 2019-11-15 15:00:16 +0000 | [diff] [blame] | 611 | // check invalid cell clipping parameters |
| 612 | data.m_Parameters.m_ClippingThresCell = -1.0f; |
| 613 | BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException); |
| 614 | data.m_Parameters.m_ClippingThresCell = 0.0f; |
| 615 | |
| 616 | // check invalid projection clipping parameters |
| 617 | data.m_Parameters.m_ClippingThresProj = -1.0f; |
| 618 | BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException); |
| 619 | data.m_Parameters.m_ClippingThresProj = 0.0f; |
| 620 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 621 | // check correct configuration |
| 622 | BOOST_CHECK_NO_THROW(data.Validate(info)); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 623 | } |
| 624 | |
Aron Virginas-Tar | d905307 | 2019-10-30 16:03:19 +0000 | [diff] [blame] | 625 | BOOST_AUTO_TEST_CASE(BiasPerAxisQuantization_Validate) |
| 626 | { |
| 627 | constexpr unsigned int nInput = 1u; |
| 628 | constexpr unsigned int cInput = 3u; |
| 629 | constexpr unsigned int hInput = 3u; |
| 630 | constexpr unsigned int wInput = 3u; |
| 631 | |
| 632 | constexpr unsigned int nOutput = nInput; |
| 633 | constexpr unsigned int cOutput = cInput; |
| 634 | constexpr unsigned int hOutput = 1u; |
| 635 | constexpr unsigned int wOutput = 1u; |
| 636 | |
| 637 | const TensorShape inputShape { nInput, cInput, hInput, wInput }; |
| 638 | const TensorShape outputShape{ nOutput, cOutput, hOutput, wOutput }; |
| 639 | const TensorShape weightShape{ cOutput, cInput, hInput, wInput }; |
| 640 | const TensorShape biasShape { cOutput }; |
| 641 | |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 642 | constexpr DataType inputType = DataType::QAsymmU8; |
Derek Lamberti | d466a54 | 2020-01-22 15:37:29 +0000 | [diff] [blame] | 643 | constexpr DataType weightType = DataType::QSymmS8; |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 644 | constexpr DataType biasType = DataType::Signed32; |
Aron Virginas-Tar | d905307 | 2019-10-30 16:03:19 +0000 | [diff] [blame] | 645 | |
| 646 | constexpr float perTensorScale = 1.5f; |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 647 | const TensorInfo inputInfo (inputShape, inputType, perTensorScale); |
| 648 | const TensorInfo outputInfo(outputShape, inputType, perTensorScale); |
Aron Virginas-Tar | d905307 | 2019-10-30 16:03:19 +0000 | [diff] [blame] | 649 | |
| 650 | const std::vector<float> weightPerAxisScales = { 2.50f, 3.50f }; |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 651 | const TensorInfo weightInfo(weightShape, weightType, weightPerAxisScales, 0); |
Aron Virginas-Tar | d905307 | 2019-10-30 16:03:19 +0000 | [diff] [blame] | 652 | |
| 653 | Convolution2dQueueDescriptor queueDescriptor; |
| 654 | queueDescriptor.m_Parameters.m_BiasEnabled = true; |
| 655 | |
| 656 | WorkloadInfo workloadInfo; |
| 657 | AddInputToWorkload(queueDescriptor, workloadInfo, inputInfo, nullptr); |
| 658 | AddOutputToWorkload(queueDescriptor, workloadInfo, outputInfo, nullptr); |
| 659 | |
| 660 | ScopedCpuTensorHandle weightTensor(weightInfo); |
| 661 | queueDescriptor.m_Weight = &weightTensor; |
| 662 | |
| 663 | // Test 1: correct per-axis quantization values |
| 664 | const std::vector<float> biasPerAxisScales1 = { 3.75f, 5.25f }; |
| 665 | const TensorInfo biasInfo1(biasShape, biasType, biasPerAxisScales1, 0); |
| 666 | |
| 667 | ScopedCpuTensorHandle biasHandle1(biasInfo1); |
| 668 | queueDescriptor.m_Bias = &biasHandle1; |
| 669 | |
| 670 | BOOST_CHECK_NO_THROW(queueDescriptor.Validate(workloadInfo)); |
| 671 | |
| 672 | // Test 2: wrong per-axis quantization values |
| 673 | const std::vector<float> biasPerAxisScales2 = { 4.00f, 5.00f }; |
| 674 | const TensorInfo biasInfo2(biasShape, biasType, biasPerAxisScales2, 0); |
| 675 | |
| 676 | ScopedCpuTensorHandle biasHandle2(biasInfo2); |
| 677 | queueDescriptor.m_Bias = &biasHandle2; |
| 678 | |
| 679 | BOOST_CHECK_THROW(queueDescriptor.Validate(workloadInfo), InvalidArgumentException); |
| 680 | |
| 681 | // Test 3: mismatched number of quantization scales |
| 682 | const std::vector<float> biasPerAxisScales3 = { 3.75f, 5.25f, 5.25f }; |
| 683 | const TensorInfo biasInfo3(biasShape, biasType, biasPerAxisScales3, 0); |
| 684 | |
| 685 | ScopedCpuTensorHandle biasHandle3(biasInfo3); |
| 686 | queueDescriptor.m_Bias = &biasHandle3; |
| 687 | |
| 688 | BOOST_CHECK_THROW(queueDescriptor.Validate(workloadInfo), InvalidArgumentException); |
| 689 | } |
| 690 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 691 | BOOST_AUTO_TEST_SUITE_END() |