Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 1 | // |
Teresa Charlin | fbf0e5b | 2020-08-17 01:01:06 +0100 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "FloorTestImpl.hpp" |
| 7 | |
Sadik Armagan | a097d2a | 2021-11-24 15:47:28 +0000 | [diff] [blame] | 8 | #include <DataTypeUtils.hpp> |
| 9 | #include <armnnTestUtils/TensorCopyUtils.hpp> |
Colm Donelan | 0c47974 | 2021-12-10 12:43:54 +0000 | [diff] [blame] | 10 | #include <armnnTestUtils/WorkloadTestUtils.hpp> |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 11 | |
Sadik Armagan | a097d2a | 2021-11-24 15:47:28 +0000 | [diff] [blame] | 12 | #include <TensorHelpers.hpp> |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 13 | |
| 14 | template<armnn::DataType ArmnnType, typename T> |
| 15 | LayerTestResult<T, 4> SimpleFloorTest( |
| 16 | armnn::IWorkloadFactory& workloadFactory, |
Finn Williams | 7faf9a8 | 2020-08-27 10:37:36 +0100 | [diff] [blame] | 17 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 18 | const armnn::ITensorHandleFactory& tensorHandleFactory) |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 19 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 20 | IgnoreUnused(memoryManager); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 21 | armnn::TensorInfo inputTensorInfo({1, 3, 2, 3}, ArmnnType); |
| 22 | inputTensorInfo.SetQuantizationScale(0.1f); |
| 23 | |
| 24 | armnn::TensorInfo outputTensorInfo(inputTensorInfo); |
| 25 | outputTensorInfo.SetQuantizationScale(0.1f); |
| 26 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 27 | std::vector<T> input = ConvertToDataType<ArmnnType>( |
| 28 | { |
| 29 | -37.5f, -15.2f, -8.76f, -2.0f, -1.5f, -1.3f, -0.5f, -0.4f, 0.0f, |
| 30 | 1.0f, 0.4f, 0.5f, 1.3f, 1.5f, 2.0f, 8.76f, 15.2f, 37.5f |
| 31 | }, |
| 32 | inputTensorInfo); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 33 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 34 | std::vector<T> actualOutput(outputTensorInfo.GetNumElements()); |
| 35 | std::vector<T> expectedOutput = ConvertToDataType<ArmnnType>( |
| 36 | { |
| 37 | -38.0f, -16.0f, -9.0f, -2.0f, -2.0f, -2.0f, -1.0f, -1.0f, 0.0f, |
| 38 | 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 2.0f, 8.0f, 15.0f, 37.0f |
| 39 | }, |
| 40 | outputTensorInfo); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 41 | |
Finn Williams | 7faf9a8 | 2020-08-27 10:37:36 +0100 | [diff] [blame] | 42 | std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo); |
| 43 | std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 44 | |
| 45 | armnn::FloorQueueDescriptor data; |
| 46 | armnn::WorkloadInfo info; |
| 47 | AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); |
| 48 | AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); |
| 49 | |
| 50 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateFloor(data, info); |
| 51 | |
| 52 | inputHandle->Allocate(); |
| 53 | outputHandle->Allocate(); |
| 54 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 55 | CopyDataToITensorHandle(inputHandle.get(), input.data()); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 56 | |
| 57 | workload->Execute(); |
| 58 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 59 | CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get()); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 60 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 61 | return LayerTestResult<T, 4>(actualOutput, |
| 62 | expectedOutput, |
| 63 | outputHandle->GetShape(), |
| 64 | outputTensorInfo.GetShape()); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | // |
| 68 | // Explicit template specializations |
| 69 | // |
| 70 | |
| 71 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float32>, 4> |
| 72 | SimpleFloorTest<armnn::DataType::Float32>( |
| 73 | armnn::IWorkloadFactory& workloadFactory, |
Finn Williams | 7faf9a8 | 2020-08-27 10:37:36 +0100 | [diff] [blame] | 74 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 75 | const armnn::ITensorHandleFactory& tensorHandleFactory); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 76 | |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 77 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float16>, 4> |
| 78 | SimpleFloorTest<armnn::DataType::Float16>( |
| 79 | armnn::IWorkloadFactory& workloadFactory, |
Finn Williams | 7faf9a8 | 2020-08-27 10:37:36 +0100 | [diff] [blame] | 80 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 81 | const armnn::ITensorHandleFactory& tensorHandleFactory); |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 82 | |
| 83 | |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 84 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QSymmS16>, 4> |
| 85 | SimpleFloorTest<armnn::DataType::QSymmS16>( |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 86 | armnn::IWorkloadFactory& workloadFactory, |
Finn Williams | 7faf9a8 | 2020-08-27 10:37:36 +0100 | [diff] [blame] | 87 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 88 | const armnn::ITensorHandleFactory& tensorHandleFactory); |