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