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