Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "SoftmaxTestImpl.hpp" |
| 7 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 8 | #include <QuantizeHelper.hpp> |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 9 | #include <ResolveType.hpp> |
| 10 | |
| 11 | #include <armnn/ArmNN.hpp> |
| 12 | |
| 13 | #include <backendsCommon/CpuTensorHandle.hpp> |
| 14 | |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 15 | #include <backendsCommon/test/TensorCopyUtils.hpp> |
| 16 | #include <backendsCommon/test/WorkloadTestUtils.hpp> |
| 17 | |
| 18 | #include <test/TensorHelpers.hpp> |
| 19 | |
| 20 | #include <algorithm> |
| 21 | |
| 22 | namespace |
| 23 | { |
| 24 | |
| 25 | struct Simple3dSoftmaxOutputData |
| 26 | { |
| 27 | const std::vector<float> outputData = |
| 28 | { |
| 29 | 0.0964599f, 0.26220518f, 0.0964599f, 0.0964599f, |
| 30 | 0.15903549f, 0.0964599f, 0.0964599f, 0.0964599f |
| 31 | }; |
| 32 | |
| 33 | const armnn::TensorShape inputShape{ 1, 8, 1 }; |
| 34 | |
| 35 | const std::vector<float> inputData = |
| 36 | { |
| 37 | 0.0f, 1.0f, 0.0f, 0.0f, |
| 38 | 0.5f, 0.0f, 0.0f, 0.0f, |
| 39 | }; |
| 40 | }; |
| 41 | |
| 42 | struct Simple4dSoftmaxData |
| 43 | { |
| 44 | const armnn::TensorShape inputShape{ 1, 8, 1, 1 }; |
| 45 | |
| 46 | const std::vector<float> outputData = |
| 47 | { |
| 48 | 0.0964599f, 0.26220518f, 0.0964599f, 0.0964599f, |
| 49 | 0.15903549f, 0.0964599f, 0.0964599f, 0.0964599f |
| 50 | }; |
| 51 | |
| 52 | const std::vector<float> inputData = |
| 53 | { |
| 54 | 0.0f, 1.0f, 0.0f, 0.0f, |
| 55 | 0.5f, 0.0f, 0.0f, 0.0f |
| 56 | }; |
| 57 | }; |
| 58 | |
| 59 | template<armnn::DataType ArmnnType, std::size_t n, typename T = armnn::ResolveType<ArmnnType>> |
| 60 | LayerTestResult<T, n> SimpleSoftmaxBaseTestImpl( |
| 61 | armnn::IWorkloadFactory& workloadFactory, |
| 62 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 63 | float beta, |
| 64 | const armnn::TensorShape& inputShape, |
| 65 | const std::vector<float>& outputData, |
| 66 | const std::vector<float>& inputData, |
| 67 | int axis = 1) |
| 68 | { |
Derek Lamberti | c374ff0 | 2019-12-10 21:57:35 +0000 | [diff] [blame] | 69 | boost::ignore_unused(memoryManager); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 70 | using std::exp; |
| 71 | |
| 72 | const float qScale = 1.f / 256.f; |
| 73 | const int qOffset = 0; |
| 74 | |
| 75 | armnn::TensorInfo inputTensorInfo; |
| 76 | armnn::TensorInfo outputTensorInfo; |
| 77 | |
| 78 | inputTensorInfo = armnn::TensorInfo(inputShape, ArmnnType); |
| 79 | inputTensorInfo.SetQuantizationScale(qScale); |
| 80 | inputTensorInfo.SetQuantizationOffset(qOffset); |
| 81 | |
| 82 | outputTensorInfo = armnn::TensorInfo(inputShape, ArmnnType); |
| 83 | outputTensorInfo.SetQuantizationScale(qScale); |
| 84 | outputTensorInfo.SetQuantizationOffset(qOffset); |
| 85 | |
| 86 | LayerTestResult<T, n> ret(outputTensorInfo); |
| 87 | |
| 88 | // Each row is independently softmax'd. |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 89 | auto input = MakeTensor<T, n>(inputTensorInfo, armnnUtils::QuantizedVector<T>(inputData, qScale, qOffset)); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 90 | |
| 91 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); |
| 92 | std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); |
| 93 | |
| 94 | armnn::SoftmaxQueueDescriptor data; |
| 95 | data.m_Parameters.m_Beta = beta; |
| 96 | data.m_Parameters.m_Axis = axis; |
| 97 | |
| 98 | armnn::WorkloadInfo info; |
| 99 | AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); |
| 100 | AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); |
| 101 | |
| 102 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateSoftmax(data, info); |
| 103 | |
| 104 | inputHandle->Allocate(); |
| 105 | outputHandle->Allocate(); |
| 106 | CopyDataToITensorHandle(inputHandle.get(), input.origin()); |
| 107 | |
| 108 | BOOST_ASSERT(workload); |
| 109 | |
| 110 | ExecuteWorkload(*workload, memoryManager); |
| 111 | |
| 112 | CopyDataFromITensorHandle(ret.output.origin(), outputHandle.get()); |
| 113 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 114 | std::vector<T> expectedOutput = armnnUtils::QuantizedVector<T>(outputData, qScale, qOffset); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 115 | ret.outputExpected = MakeTensor<T, n>(outputTensorInfo, expectedOutput); |
| 116 | |
| 117 | return ret; |
| 118 | } |
| 119 | |
| 120 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 121 | LayerTestResult<T, 2> SimpleSoftmaxTestImpl( |
| 122 | armnn::IWorkloadFactory& workloadFactory, |
| 123 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 124 | float beta) |
| 125 | { |
| 126 | using std::exp; |
| 127 | const armnn::TensorShape inputShape{ 2, 4 }; |
| 128 | |
| 129 | float x0[4] = { exp((0.f - 1.0f) * beta), exp((1.0f - 1.0f) * beta), |
| 130 | exp((0.0f - 1.0f) * beta), exp((0.0f - 1.0f) * beta) }; |
| 131 | float sum0 = x0[0] + x0[1] + x0[2] + x0[3]; |
| 132 | float x1[4] = { exp((0.5f - 0.5f) * beta), exp((0.0f - 0.5f) * beta), |
| 133 | exp((0.0f - 0.5f) * beta), exp((0.0f - 0.5f) * beta) }; |
| 134 | float sum1 = x1[0] + x1[1] + x1[2] + x1[3]; |
| 135 | |
| 136 | const std::vector<float> outputData = { x0[0] / sum0, x0[1] / sum0, x0[2] / sum0, x0[3] / sum0, |
| 137 | x1[0] / sum1, x1[1] / sum1, x1[2] / sum1, x1[3] / sum1 }; |
| 138 | |
| 139 | const std::vector<float> inputData = |
| 140 | { |
| 141 | 0.f, 1.f, 0.f, 0.f, |
| 142 | .5f, 0.f, 0.f, 0.f, |
| 143 | }; |
| 144 | |
| 145 | return SimpleSoftmaxBaseTestImpl<ArmnnType, 2>(workloadFactory, memoryManager, beta, |
| 146 | inputShape, outputData, inputData); |
| 147 | } |
| 148 | |
| 149 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 150 | LayerTestResult<T, 2> SimpleSoftmaxTestImpl( |
| 151 | armnn::IWorkloadFactory& workloadFactory, |
| 152 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 153 | float beta, |
| 154 | int axis) |
| 155 | { |
| 156 | armnn::TensorShape inputShape; |
| 157 | std::vector<float> inputData; |
| 158 | std::vector<float> outputData; |
| 159 | switch (axis) |
| 160 | { |
| 161 | case -2: |
| 162 | case 0: |
| 163 | { |
| 164 | inputShape = {5, 2}; |
| 165 | |
| 166 | inputData = |
| 167 | { |
| 168 | 17.0f, -1.0f, 16.0f, -2.0f, 15.0f, -3.0f, 14.0f, -4.0f, 1.0f, -17.0f |
| 169 | }; |
| 170 | |
| 171 | outputData = |
| 172 | { |
| 173 | 0.643914213228014f, 0.643914213228014f, 0.236882800924671f, 0.236882800924671f, |
| 174 | 0.087144312427294f, |
| 175 | 0.087144312427294f, 0.032058600957022f, 0.032058600957022f, 7.246299848982885e-08f, |
| 176 | 7.246299848982885e-08f |
| 177 | }; |
| 178 | break; |
| 179 | } |
| 180 | case -1: |
| 181 | case 1: |
| 182 | { |
| 183 | inputShape = {2, 5}; |
| 184 | |
| 185 | inputData = |
| 186 | { |
| 187 | 17.0f, 16.0f, 15.0f, 14.0f, 1.0f, -1.0f, -2.0f, -3.0f, -4.0f, -17.0f |
| 188 | }; |
| 189 | |
| 190 | outputData = |
| 191 | { |
| 192 | 0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f, |
| 193 | 7.246299848982885e-08f, |
| 194 | 0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f, |
| 195 | 7.246299848982885e-08f |
| 196 | }; |
| 197 | break; |
| 198 | } |
| 199 | } |
| 200 | return SimpleSoftmaxBaseTestImpl<ArmnnType, 2>(workloadFactory, memoryManager, beta, |
| 201 | inputShape, outputData, inputData, axis); |
| 202 | } |
| 203 | |
| 204 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 205 | LayerTestResult<T, 3> Simple3dSoftmaxTestImpl( |
| 206 | armnn::IWorkloadFactory& workloadFactory, |
| 207 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 208 | float beta, |
| 209 | const armnn::TensorShape& inputShape, |
| 210 | const std::vector<float>& outputData, |
| 211 | const std::vector<float>& inputData, |
| 212 | int axis = 1) |
| 213 | { |
| 214 | return SimpleSoftmaxBaseTestImpl<ArmnnType, 3>(workloadFactory, memoryManager, beta, |
| 215 | inputShape, outputData, inputData, axis); |
| 216 | } |
| 217 | |
| 218 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 219 | LayerTestResult<T, 4> Simple4dSoftmaxTestImpl( |
| 220 | armnn::IWorkloadFactory& workloadFactory, |
| 221 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 222 | float beta, |
| 223 | const armnn::TensorShape& inputShape, |
| 224 | const std::vector<float>& outputData, |
| 225 | const std::vector<float>& inputData, |
| 226 | int axis = 1) |
| 227 | { |
| 228 | |
| 229 | return SimpleSoftmaxBaseTestImpl<ArmnnType, 4>(workloadFactory, memoryManager, beta, |
| 230 | inputShape, outputData, inputData, axis); |
| 231 | } |
| 232 | |
| 233 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 234 | LayerTestResult<T, 2> CompareSoftmaxTestImpl( |
| 235 | armnn::IWorkloadFactory& workloadFactory, |
| 236 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 237 | armnn::IWorkloadFactory& refWorkloadFactory, |
| 238 | float beta) |
| 239 | { |
| 240 | |
| 241 | const int batchSize = 20; |
| 242 | const int channels = 30; |
| 243 | |
| 244 | armnn::TensorInfo inputTensorInfo; |
| 245 | armnn::TensorInfo outputTensorInfo; |
| 246 | |
| 247 | unsigned int inputShape[] = { batchSize, channels }; |
| 248 | |
| 249 | inputTensorInfo = armnn::TensorInfo(2, inputShape, ArmnnType); |
| 250 | outputTensorInfo = armnn::TensorInfo(2, inputShape, ArmnnType); |
| 251 | float qScale = 1.f / 256.f; |
| 252 | int qOffset = 0; |
| 253 | inputTensorInfo.SetQuantizationScale(qScale); |
| 254 | inputTensorInfo.SetQuantizationOffset(qOffset); |
| 255 | outputTensorInfo.SetQuantizationScale(qScale); |
| 256 | outputTensorInfo.SetQuantizationOffset(qOffset); |
| 257 | |
| 258 | |
| 259 | LayerTestResult<T, 2> ret(outputTensorInfo); |
| 260 | auto input = MakeRandomTensor<T, 2>(inputTensorInfo, 0xF00D, 0.0f, 1.0f); |
| 261 | |
| 262 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); |
| 263 | std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); |
| 264 | |
| 265 | armnn::SoftmaxQueueDescriptor data; |
| 266 | data.m_Parameters.m_Beta = beta; |
| 267 | |
| 268 | armnn::WorkloadInfo info; |
| 269 | AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); |
| 270 | AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); |
| 271 | |
| 272 | std::unique_ptr<armnn::ITensorHandle> outputHandleRef = refWorkloadFactory.CreateTensorHandle(outputTensorInfo); |
| 273 | std::unique_ptr<armnn::ITensorHandle> inputHandleRef = refWorkloadFactory.CreateTensorHandle(inputTensorInfo); |
| 274 | |
| 275 | |
| 276 | armnn::SoftmaxQueueDescriptor refData = data; |
| 277 | armnn::WorkloadInfo refInfo = info; |
| 278 | SetWorkloadInput(refData, refInfo, 0, inputTensorInfo, inputHandleRef.get()); |
| 279 | SetWorkloadOutput(refData, refInfo, 0, outputTensorInfo, outputHandleRef.get()); |
| 280 | |
| 281 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateSoftmax(data, info); |
| 282 | std::unique_ptr<armnn::IWorkload> workloadRef = refWorkloadFactory.CreateSoftmax(refData, refInfo); |
| 283 | |
| 284 | outputHandleRef->Allocate(); |
| 285 | inputHandleRef->Allocate(); |
| 286 | |
| 287 | inputHandle->Allocate(); |
| 288 | outputHandle->Allocate(); |
| 289 | |
| 290 | CopyDataToITensorHandle(inputHandle.get(), &input[0][0]); |
| 291 | CopyDataToITensorHandle(inputHandleRef.get(), &input[0][0]); |
| 292 | |
| 293 | ExecuteWorkload(*workload, memoryManager); |
| 294 | |
| 295 | workloadRef->Execute(); |
| 296 | |
| 297 | CopyDataFromITensorHandle(&ret.output[0][0], outputHandle.get()); |
| 298 | CopyDataFromITensorHandle(&ret.outputExpected[0][0], outputHandleRef.get()); |
| 299 | |
| 300 | return ret; |
| 301 | } |
| 302 | |
| 303 | } // anonymous namespace |
| 304 | |
| 305 | LayerTestResult<float,2> SimpleSoftmaxTest( |
| 306 | armnn::IWorkloadFactory& workloadFactory, |
| 307 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 308 | float beta) |
| 309 | { |
| 310 | return SimpleSoftmaxTestImpl<armnn::DataType::Float32>(workloadFactory, memoryManager, beta); |
| 311 | } |
| 312 | |
| 313 | LayerTestResult<float,2> SimpleAxisSoftmaxTest( |
| 314 | armnn::IWorkloadFactory& workloadFactory, |
| 315 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 316 | float beta, |
| 317 | int axis) |
| 318 | { |
| 319 | return SimpleSoftmaxTestImpl<armnn::DataType::Float32>(workloadFactory, memoryManager, beta, axis); |
| 320 | } |
| 321 | |
| 322 | LayerTestResult<float,3> Simple3dSoftmaxTest( |
| 323 | armnn::IWorkloadFactory& workloadFactory, |
| 324 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 325 | float beta) |
| 326 | { |
| 327 | Simple3dSoftmaxOutputData data; |
| 328 | return Simple3dSoftmaxTestImpl<armnn::DataType::Float32>(workloadFactory, memoryManager, beta, |
| 329 | data.inputShape, data.outputData, data.inputData); |
| 330 | } |
| 331 | |
| 332 | LayerTestResult<float,3> Simple3dAxisSoftmaxTest( |
| 333 | armnn::IWorkloadFactory& workloadFactory, |
| 334 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 335 | float beta, |
| 336 | int axis) |
| 337 | { |
| 338 | armnn::TensorShape inputShape; |
| 339 | std::vector<float> inputData; |
| 340 | std::vector<float> outputData; |
| 341 | switch (axis) |
| 342 | { |
| 343 | case -3: |
| 344 | case 0: |
| 345 | { |
| 346 | inputShape = {5, 2, 2}; |
| 347 | |
| 348 | inputData = |
| 349 | { |
| 350 | 17.0f, -1.0f, 17.0f, -1.0f, 16.0f, -2.0f, 16.0f, -2.0f, 15.0f, -3.0f, |
| 351 | |
| 352 | 15.0f, -3.0f, 14.0f, -4.0f, 14.0f, -4.0f, 1.0f, -17.0f, 1.0f, -17.0f |
| 353 | }; |
| 354 | |
| 355 | outputData = |
| 356 | { |
| 357 | 0.643914213228014f, 0.643914213228014f, 0.643914213228014f, 0.643914213228014f, |
| 358 | 0.236882800924671f, |
| 359 | 0.236882800924671f, 0.236882800924671f, 0.236882800924671f, 0.087144312427294f, |
| 360 | 0.087144312427294f, |
| 361 | |
| 362 | 0.087144312427294f, 0.087144312427294f, 0.032058600957022f, 0.032058600957022f, |
| 363 | 0.032058600957022f, |
| 364 | 0.032058600957022f, 7.246299848982885e-08f, 7.246299848982885e-08f, 7.246299848982885e-08f, |
| 365 | 7.246299848982885e-08f |
| 366 | }; |
| 367 | break; |
| 368 | } |
| 369 | case -2: |
| 370 | case 1: |
| 371 | { |
| 372 | inputShape = {2, 5, 2}; |
| 373 | |
| 374 | inputData = |
| 375 | { |
| 376 | 17.0f, -1.0f, 16.0f, -2.0f, 15.0f, -3.0f, 14.0f, -4.0f, 1.0f, -17.0f, |
| 377 | |
| 378 | 17.0f, -1.0f, 16.0f, -2.0f, 15.0f, -3.0f, 14.0f, -4.0f, 1.0f, -17.0f |
| 379 | }; |
| 380 | |
| 381 | outputData = |
| 382 | { |
| 383 | 0.643914213228014f, 0.643914213228014f, 0.236882800924671f, 0.236882800924671f, |
| 384 | 0.087144312427294f, |
| 385 | 0.087144312427294f, 0.032058600957022f, 0.032058600957022f, 7.246299848982885e-08f, |
| 386 | 7.246299848982885e-08f, |
| 387 | |
| 388 | 0.643914213228014f, 0.643914213228014f, 0.236882800924671f, 0.236882800924671f, |
| 389 | 0.087144312427294f, |
| 390 | 0.087144312427294f, 0.032058600957022f, 0.032058600957022f, 7.246299848982885e-08f, |
| 391 | 7.246299848982885e-08f |
| 392 | }; |
| 393 | break; |
| 394 | } |
| 395 | case -1: |
| 396 | case 2: |
| 397 | { |
| 398 | inputShape = {2, 2, 5}; |
| 399 | |
| 400 | inputData = |
| 401 | { |
| 402 | 17.0f, 16.0f, 15.0f, 14.0f, 1.0f, -1.0f, -2.0f, -3.0f, -4.0f, -17.0f, |
| 403 | 17.0f, 16.0f, 15.0f, 14.0f, 1.0f, -1.0f, -2.0f, -3.0f, -4.0f, -17.0f |
| 404 | }; |
| 405 | |
| 406 | outputData = |
| 407 | { |
| 408 | 0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f, |
| 409 | 7.246299848982885e-08f, |
| 410 | 0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f, |
| 411 | 7.246299848982885e-08f, |
| 412 | |
| 413 | 0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f, |
| 414 | 7.246299848982885e-08f, |
| 415 | 0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f, |
| 416 | 7.246299848982885e-08f |
| 417 | }; |
| 418 | break; |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | return Simple3dSoftmaxTestImpl<armnn::DataType::Float32>(workloadFactory, memoryManager, beta, |
| 423 | inputShape, outputData, inputData, axis); |
| 424 | } |
| 425 | |
| 426 | LayerTestResult<float,4> Simple4dSoftmaxTest( |
| 427 | armnn::IWorkloadFactory& workloadFactory, |
| 428 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 429 | float beta) |
| 430 | { |
| 431 | Simple4dSoftmaxData data; |
| 432 | return Simple4dSoftmaxTestImpl<armnn::DataType::Float32>(workloadFactory, memoryManager, beta, data.inputShape, |
| 433 | data.outputData, data.inputData); |
| 434 | } |
| 435 | |
| 436 | LayerTestResult<float,4> Simple4dAxisSoftmaxTest( |
| 437 | armnn::IWorkloadFactory& workloadFactory, |
| 438 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 439 | float beta, |
| 440 | int axis) |
| 441 | { |
| 442 | armnn::TensorShape inputShape; |
| 443 | std::vector<float> inputData; |
| 444 | std::vector<float> outputData; |
| 445 | switch (axis) |
| 446 | { |
| 447 | case -4: |
| 448 | case 0: |
| 449 | { |
| 450 | inputShape = {5, 2, 2, 2}; |
| 451 | |
| 452 | inputData = |
| 453 | { |
| 454 | 17.0f, -1.0f, 17.0f, -1.0f, 17.0f, -1.0f, 17.0f, -1.0f, 16.0f, -2.0f, |
| 455 | 16.0f, -2.0f, 16.0f, -2.0f, 16.0f, -2.0f, 15.0f, -3.0f, 15.0f, -3.0f, |
| 456 | 15.0f, -3.0f, 15.0f, -3.0f, 14.0f, -4.0f, 14.0f, -4.0f, 14.0f, -4.0f, |
| 457 | 14.0f, -4.0f, 1.0f, -17.0f, 1.0f, -17.0f, 1.0f, -17.0f, 1.0f, -17.0f |
| 458 | }; |
| 459 | |
| 460 | outputData = |
| 461 | { |
| 462 | 0.643914213228014f, 0.643914213228014f, 0.643914213228014f, 0.643914213228014f, |
| 463 | 0.643914213228014f, |
| 464 | 0.643914213228014f, 0.643914213228014f, 0.643914213228014f, 0.236882800924671f, |
| 465 | 0.236882800924671f, |
| 466 | 0.236882800924671f, 0.236882800924671f, 0.236882800924671f, 0.236882800924671f, |
| 467 | 0.236882800924671f, |
| 468 | 0.236882800924671f, 0.087144312427294f, 0.087144312427294f, 0.087144312427294f, |
| 469 | 0.087144312427294f, |
| 470 | |
| 471 | 0.087144312427294f, 0.087144312427294f, 0.087144312427294f, 0.087144312427294f, |
| 472 | 0.032058600957022f, |
| 473 | 0.032058600957022f, 0.032058600957022f, 0.032058600957022f, 0.032058600957022f, |
| 474 | 0.032058600957022f, |
| 475 | 0.032058600957022f, 0.032058600957022f, 7.246299848982885e-08f, 7.246299848982885e-08f, |
| 476 | 7.246299848982885e-08f, |
| 477 | 7.246299848982885e-08f, 7.246299848982885e-08f, 7.246299848982885e-08f, |
| 478 | 7.246299848982885e-08f, 7.246299848982885e-08f |
| 479 | }; |
| 480 | break; |
| 481 | } |
| 482 | case -3: |
| 483 | case 1: |
| 484 | { |
| 485 | inputShape = {2, 5, 2, 2}; |
| 486 | |
| 487 | inputData = |
| 488 | { |
| 489 | 17.0f, -1.0f, 17.0f, -1.0f, 16.0f, -2.0f, 16.0f, -2.0f, 15.0f, -3.0f, |
| 490 | 15.0f, -3.0f, 14.0f, -4.0f, 14.0f, -4.0f, 1.0f, -17.0f, 1.0f, -17.0f, |
| 491 | 17.0f, -1.0f, 17.0f, -1.0f, 16.0f, -2.0f, 16.0f, -2.0f, 15.0f, -3.0f, |
| 492 | 15.0f, -3.0f, 14.0f, -4.0f, 14.0f, -4.0f, 1.0f, -17.0f, 1.0f, -17.0f |
| 493 | }; |
| 494 | |
| 495 | outputData = |
| 496 | { |
| 497 | 0.643914213228014f, 0.643914213228014f, 0.643914213228014f, 0.643914213228014f, |
| 498 | 0.236882800924671f, |
| 499 | 0.236882800924671f, 0.236882800924671f, 0.236882800924671f, 0.087144312427294f, |
| 500 | 0.087144312427294f, |
| 501 | 0.087144312427294f, 0.087144312427294f, 0.032058600957022f, 0.032058600957022f, |
| 502 | 0.032058600957022f, |
| 503 | 0.032058600957022f, 7.246299848982885e-08f, 7.246299848982885e-08f, 7.246299848982885e-08f, |
| 504 | 7.246299848982885e-08f, |
| 505 | |
| 506 | |
| 507 | 0.643914213228014f, 0.643914213228014f, 0.643914213228014f, 0.643914213228014f, |
| 508 | 0.236882800924671f, |
| 509 | 0.236882800924671f, 0.236882800924671f, 0.236882800924671f, 0.087144312427294f, |
| 510 | 0.087144312427294f, |
| 511 | 0.087144312427294f, 0.087144312427294f, 0.032058600957022f, 0.032058600957022f, |
| 512 | 0.032058600957022f, |
| 513 | 0.032058600957022f, 7.246299848982885e-08f, 7.246299848982885e-08f, 7.246299848982885e-08f, |
| 514 | 7.246299848982885e-08f |
| 515 | }; |
| 516 | break; |
| 517 | } |
| 518 | case -2: |
| 519 | case 2: |
| 520 | { |
| 521 | inputShape = {2, 2, 5, 2}; |
| 522 | |
| 523 | inputData = |
| 524 | { |
| 525 | 17.0f, -1.0f, 16.0f, -2.0f, 15.0f, -3.0f, 14.0f, -4.0f, 1.0f, -17.0f, |
| 526 | 17.0f, -1.0f, 16.0f, -2.0f, 15.0f, -3.0f, 14.0f, -4.0f, 1.0f, -17.0f, |
| 527 | 17.0f, -1.0f, 16.0f, -2.0f, 15.0f, -3.0f, 14.0f, -4.0f, 1.0f, -17.0f, |
| 528 | 17.0f, -1.0f, 16.0f, -2.0f, 15.0f, -3.0f, 14.0f, -4.0f, 1.0f, -17.0f |
| 529 | }; |
| 530 | |
| 531 | outputData = |
| 532 | { |
| 533 | 0.643914213228014f, 0.643914213228014f, 0.236882800924671f, 0.236882800924671f, |
| 534 | 0.087144312427294f, |
| 535 | 0.087144312427294f, 0.032058600957022f, 0.032058600957022f, 7.246299848982885e-08f, |
| 536 | 7.246299848982885e-08f, |
| 537 | 0.643914213228014f, 0.643914213228014f, 0.236882800924671f, 0.236882800924671f, |
| 538 | 0.087144312427294f, |
| 539 | 0.087144312427294f, 0.032058600957022f, 0.032058600957022f, 7.246299848982885e-08f, |
| 540 | 7.246299848982885e-08f, |
| 541 | |
| 542 | 0.643914213228014f, 0.643914213228014f, 0.236882800924671f, 0.236882800924671f, |
| 543 | 0.087144312427294f, |
| 544 | 0.087144312427294f, 0.032058600957022f, 0.032058600957022f, 7.246299848982885e-08f, |
| 545 | 7.246299848982885e-08f, |
| 546 | 0.643914213228014f, 0.643914213228014f, 0.236882800924671f, 0.236882800924671f, |
| 547 | 0.087144312427294f, |
| 548 | 0.087144312427294f, 0.032058600957022f, 0.032058600957022f, 7.246299848982885e-08f, |
| 549 | 7.246299848982885e-08f |
| 550 | }; |
| 551 | break; |
| 552 | } |
| 553 | case -1: |
| 554 | case 3: |
| 555 | { |
| 556 | inputShape = {2, 2, 2, 5}; |
| 557 | |
| 558 | inputData = |
| 559 | { |
| 560 | 17.0f, 16.0f, 15.0f, 14.0f, 1.0f, -1.0f, -2.0f, -3.0f, -4.0f, -17.0f, |
| 561 | 17.0f, 16.0f, 15.0f, 14.0f, 1.0f, -1.0f, -2.0f, -3.0f, -4.0f, -17.0f, |
| 562 | 17.0f, 16.0f, 15.0f, 14.0f, 1.0f, -1.0f, -2.0f, -3.0f, -4.0f, -17.0f, |
| 563 | 17.0f, 16.0f, 15.0f, 14.0f, 1.0f, -1.0f, -2.0f, -3.0f, -4.0f, -17.0f |
| 564 | }; |
| 565 | |
| 566 | outputData = |
| 567 | { |
| 568 | 0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f, |
| 569 | 7.246299848982885e-08f, |
| 570 | 0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f, |
| 571 | 7.246299848982885e-08f, |
| 572 | 0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f, |
| 573 | 7.246299848982885e-08f, |
| 574 | 0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f, |
| 575 | 7.246299848982885e-08f, |
| 576 | |
| 577 | 0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f, |
| 578 | 7.246299848982885e-08f, |
| 579 | 0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f, |
| 580 | 7.246299848982885e-08f, |
| 581 | 0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f, |
| 582 | 7.246299848982885e-08f, |
| 583 | 0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f, |
| 584 | 7.246299848982885e-08f |
| 585 | }; |
| 586 | break; |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | return Simple4dSoftmaxTestImpl<armnn::DataType::Float32>( |
| 591 | workloadFactory, |
| 592 | memoryManager, |
| 593 | beta, |
| 594 | inputShape, |
| 595 | outputData, |
| 596 | inputData, |
| 597 | axis); |
| 598 | } |
| 599 | |
| 600 | LayerTestResult<uint8_t,2> SimpleSoftmaxUint8Test( |
| 601 | armnn::IWorkloadFactory& workloadFactory, |
| 602 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 603 | float beta) |
| 604 | { |
| 605 | return SimpleSoftmaxTestImpl<armnn::DataType::QuantisedAsymm8>(workloadFactory, memoryManager, beta); |
| 606 | } |
| 607 | |
| 608 | LayerTestResult<uint8_t,3> Simple3dSoftmaxUint8Test( |
| 609 | armnn::IWorkloadFactory& workloadFactory, |
| 610 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 611 | float beta) |
| 612 | { |
| 613 | Simple3dSoftmaxOutputData data; |
| 614 | return Simple3dSoftmaxTestImpl<armnn::DataType::QuantisedAsymm8>( |
| 615 | workloadFactory, |
| 616 | memoryManager, |
| 617 | beta, |
| 618 | data.inputShape, |
| 619 | data.outputData, |
| 620 | data.inputData); |
| 621 | } |
| 622 | |
| 623 | LayerTestResult<uint8_t,4> Simple4dSoftmaxUint8Test( |
| 624 | armnn::IWorkloadFactory& workloadFactory, |
| 625 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 626 | float beta) |
| 627 | { |
| 628 | Simple4dSoftmaxData data; |
| 629 | |
| 630 | return Simple4dSoftmaxTestImpl<armnn::DataType::QuantisedAsymm8>(workloadFactory, memoryManager, beta, |
| 631 | data.inputShape, data.outputData, data.inputData); |
| 632 | } |
| 633 | |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 634 | LayerTestResult<armnn::Half,2> SimpleSoftmaxFloat16Test( |
| 635 | armnn::IWorkloadFactory& workloadFactory, |
| 636 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 637 | float beta) |
| 638 | { |
| 639 | return SimpleSoftmaxTestImpl<armnn::DataType::Float16>(workloadFactory, memoryManager, beta); |
| 640 | } |
| 641 | |
| 642 | LayerTestResult<armnn::Half,3> Simple3dSoftmaxFloat16Test( |
| 643 | armnn::IWorkloadFactory& workloadFactory, |
| 644 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 645 | float beta) |
| 646 | { |
| 647 | Simple3dSoftmaxOutputData data; |
| 648 | return Simple3dSoftmaxTestImpl<armnn::DataType::Float16>(workloadFactory, memoryManager, beta, |
| 649 | data.inputShape, data.outputData, data.inputData); |
| 650 | } |
| 651 | |
| 652 | LayerTestResult<armnn::Half,4> Simple4dSoftmaxFloat16Test( |
| 653 | armnn::IWorkloadFactory& workloadFactory, |
| 654 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 655 | float beta) |
| 656 | { |
| 657 | Simple4dSoftmaxData data; |
| 658 | return Simple4dSoftmaxTestImpl<armnn::DataType::Float16>(workloadFactory, memoryManager, beta, |
| 659 | data.inputShape, data.outputData, data.inputData); |
| 660 | } |
| 661 | |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 662 | LayerTestResult<int16_t,2> SimpleSoftmaxUint16Test( |
| 663 | armnn::IWorkloadFactory& workloadFactory, |
| 664 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 665 | float beta) |
| 666 | { |
| 667 | return SimpleSoftmaxTestImpl<armnn::DataType::QuantisedSymm16>(workloadFactory, memoryManager, beta); |
| 668 | } |
| 669 | |
| 670 | LayerTestResult<int16_t,3> Simple3dSoftmaxUint16Test( |
| 671 | armnn::IWorkloadFactory& workloadFactory, |
| 672 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 673 | float beta) |
| 674 | { |
| 675 | Simple3dSoftmaxOutputData data; |
| 676 | return Simple3dSoftmaxTestImpl<armnn::DataType::QuantisedSymm16>(workloadFactory, memoryManager, beta, |
| 677 | data.inputShape, data.outputData, data.inputData); |
| 678 | } |
| 679 | |
| 680 | LayerTestResult<int16_t,4> Simple4dSoftmaxUint16Test( |
| 681 | armnn::IWorkloadFactory& workloadFactory, |
| 682 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 683 | float beta) |
| 684 | { |
| 685 | Simple4dSoftmaxData data; |
| 686 | |
| 687 | return Simple4dSoftmaxTestImpl<armnn::DataType::QuantisedSymm16>(workloadFactory, memoryManager, beta, |
| 688 | data.inputShape, data.outputData, data.inputData); |
| 689 | } |
| 690 | |
| 691 | LayerTestResult<float,2> CompareSoftmaxTest( |
| 692 | armnn::IWorkloadFactory& workloadFactory, |
| 693 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 694 | armnn::IWorkloadFactory& refWorkloadFactory, |
| 695 | float beta) |
| 696 | { |
| 697 | return CompareSoftmaxTestImpl<armnn::DataType::Float32>( |
| 698 | workloadFactory, memoryManager, refWorkloadFactory, beta); |
| 699 | } |
| 700 | |
| 701 | LayerTestResult<uint8_t,2> CompareSoftmaxUint8Test( |
| 702 | armnn::IWorkloadFactory& workloadFactory, |
| 703 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 704 | armnn::IWorkloadFactory& refWorkloadFactory, |
| 705 | float beta) |
| 706 | { |
| 707 | return CompareSoftmaxTestImpl<armnn::DataType::QuantisedAsymm8>( |
| 708 | workloadFactory, memoryManager, refWorkloadFactory, beta); |
| 709 | } |