Ryan OShea | f4bfa6a | 2020-06-10 11:33:37 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "FillTestImpl.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> |
Ryan OShea | f4bfa6a | 2020-06-10 11:33:37 +0100 | [diff] [blame] | 11 | |
Sadik Armagan | a097d2a | 2021-11-24 15:47:28 +0000 | [diff] [blame] | 12 | #include <TensorHelpers.hpp> |
Ryan OShea | f4bfa6a | 2020-06-10 11:33:37 +0100 | [diff] [blame] | 13 | |
| 14 | template<armnn::DataType ArmnnType, typename T> |
| 15 | LayerTestResult<T, 4> SimpleFillTest( |
| 16 | armnn::IWorkloadFactory& workloadFactory, |
Finn Williams | 8702007 | 2020-08-26 16:19:15 +0100 | [diff] [blame] | 17 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
Sadik Armagan | 89de3b4 | 2020-08-28 10:38:53 +0100 | [diff] [blame] | 18 | const armnn::ITensorHandleFactory& tensorHandleFactory) |
Ryan OShea | f4bfa6a | 2020-06-10 11:33:37 +0100 | [diff] [blame] | 19 | { |
| 20 | IgnoreUnused(memoryManager); |
Teresa Charlin | 4b10fef | 2020-07-29 09:36:41 +0100 | [diff] [blame] | 21 | armnn::TensorInfo inputTensorInfo({4}, armnn::DataType::Signed32); |
Ryan OShea | f4bfa6a | 2020-06-10 11:33:37 +0100 | [diff] [blame] | 22 | armnn::TensorInfo outputTensorInfo({2, 2, 3, 2}, ArmnnType); |
Ryan OShea | f4bfa6a | 2020-06-10 11:33:37 +0100 | [diff] [blame] | 23 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 24 | std::vector<int32_t> input = ConvertToDataType<armnn::DataType::Signed32>( { 2, 2, 3, 2 }, inputTensorInfo); |
Ryan OShea | f4bfa6a | 2020-06-10 11:33:37 +0100 | [diff] [blame] | 25 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 26 | std::vector<T> actualOutput(outputTensorInfo.GetNumElements()); |
| 27 | std::vector<T> expectedOutput = ConvertToDataType<ArmnnType>( |
| 28 | { |
| 29 | 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, |
| 30 | 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f |
| 31 | }, |
| 32 | outputTensorInfo); |
Ryan OShea | f4bfa6a | 2020-06-10 11:33:37 +0100 | [diff] [blame] | 33 | |
Sadik Armagan | 89de3b4 | 2020-08-28 10:38:53 +0100 | [diff] [blame] | 34 | std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo); |
| 35 | std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo); |
Ryan OShea | f4bfa6a | 2020-06-10 11:33:37 +0100 | [diff] [blame] | 36 | |
| 37 | armnn::FillQueueDescriptor data; |
| 38 | data.m_Parameters.m_Value = 1.0f; |
| 39 | armnn::WorkloadInfo info; |
| 40 | AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); |
| 41 | AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); |
| 42 | |
| 43 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateFill(data, info); |
| 44 | |
| 45 | inputHandle->Allocate(); |
| 46 | outputHandle->Allocate(); |
| 47 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 48 | CopyDataToITensorHandle(inputHandle.get(), input.data()); |
Ryan OShea | f4bfa6a | 2020-06-10 11:33:37 +0100 | [diff] [blame] | 49 | |
| 50 | workload->Execute(); |
| 51 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 52 | CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get()); |
Ryan OShea | f4bfa6a | 2020-06-10 11:33:37 +0100 | [diff] [blame] | 53 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 54 | return LayerTestResult<T, 4>(actualOutput, |
| 55 | expectedOutput, |
| 56 | outputHandle->GetShape(), |
| 57 | outputTensorInfo.GetShape()); |
Ryan OShea | f4bfa6a | 2020-06-10 11:33:37 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | // |
| 61 | // Explicit template specializations |
| 62 | // |
| 63 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float32>, 4> |
| 64 | SimpleFillTest<armnn::DataType::Float32>( |
| 65 | armnn::IWorkloadFactory& workloadFactory, |
Finn Williams | 8702007 | 2020-08-26 16:19:15 +0100 | [diff] [blame] | 66 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
Sadik Armagan | 89de3b4 | 2020-08-28 10:38:53 +0100 | [diff] [blame] | 67 | const armnn::ITensorHandleFactory& tensorHandleFactory); |
Ryan OShea | f4bfa6a | 2020-06-10 11:33:37 +0100 | [diff] [blame] | 68 | |
| 69 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float16>, 4> |
| 70 | SimpleFillTest<armnn::DataType::Float16>( |
| 71 | armnn::IWorkloadFactory& workloadFactory, |
Finn Williams | 8702007 | 2020-08-26 16:19:15 +0100 | [diff] [blame] | 72 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
Sadik Armagan | 89de3b4 | 2020-08-28 10:38:53 +0100 | [diff] [blame] | 73 | const armnn::ITensorHandleFactory& tensorHandleFactory); |
Sadik Armagan | 66aecb0 | 2020-06-24 11:42:20 +0100 | [diff] [blame] | 74 | |
| 75 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Signed32>, 4> |
| 76 | SimpleFillTest<armnn::DataType::Signed32>( |
| 77 | armnn::IWorkloadFactory& workloadFactory, |
Finn Williams | 8702007 | 2020-08-26 16:19:15 +0100 | [diff] [blame] | 78 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
Sadik Armagan | 89de3b4 | 2020-08-28 10:38:53 +0100 | [diff] [blame] | 79 | const armnn::ITensorHandleFactory& tensorHandleFactory); |