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