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 | |
| 8 | #include <backendsCommon/test/DataTypeUtils.hpp> |
| 9 | #include <backendsCommon/test/TensorCopyUtils.hpp> |
| 10 | #include <backendsCommon/test/WorkloadTestUtils.hpp> |
| 11 | |
| 12 | #include <test/TensorHelpers.hpp> |
| 13 | |
| 14 | template<armnn::DataType ArmnnType, typename T> |
| 15 | LayerTestResult<T, 4> SimpleFillTest( |
| 16 | armnn::IWorkloadFactory& workloadFactory, |
| 17 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 18 | { |
| 19 | IgnoreUnused(memoryManager); |
| 20 | armnn::TensorInfo inputTensorInfo({4}, ArmnnType); |
| 21 | inputTensorInfo.SetQuantizationScale(0.0f); |
| 22 | |
| 23 | armnn::TensorInfo outputTensorInfo({2, 2, 3, 2}, ArmnnType); |
| 24 | outputTensorInfo.SetQuantizationScale(0.0f); |
| 25 | |
| 26 | auto input = MakeTensor<T, 1>(inputTensorInfo, ConvertToDataType<ArmnnType>( |
| 27 | {2, 2, 3, 2}, |
| 28 | inputTensorInfo)); |
| 29 | |
| 30 | LayerTestResult<T, 4> ret(outputTensorInfo); |
| 31 | ret.outputExpected = MakeTensor<T, 4>(outputTensorInfo, ConvertToDataType<ArmnnType>( |
| 32 | { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, |
| 33 | 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f }, |
| 34 | outputTensorInfo)); |
| 35 | |
| 36 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); |
| 37 | std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); |
| 38 | |
| 39 | armnn::FillQueueDescriptor data; |
| 40 | data.m_Parameters.m_Value = 1.0f; |
| 41 | armnn::WorkloadInfo info; |
| 42 | AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); |
| 43 | AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); |
| 44 | |
| 45 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateFill(data, info); |
| 46 | |
| 47 | inputHandle->Allocate(); |
| 48 | outputHandle->Allocate(); |
| 49 | |
| 50 | CopyDataToITensorHandle(inputHandle.get(), &input[0]); |
| 51 | |
| 52 | workload->Execute(); |
| 53 | |
| 54 | CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get()); |
| 55 | |
| 56 | return ret; |
| 57 | } |
| 58 | |
| 59 | // |
| 60 | // Explicit template specializations |
| 61 | // |
| 62 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float32>, 4> |
| 63 | SimpleFillTest<armnn::DataType::Float32>( |
| 64 | armnn::IWorkloadFactory& workloadFactory, |
| 65 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); |
| 66 | |
| 67 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float16>, 4> |
| 68 | SimpleFillTest<armnn::DataType::Float16>( |
| 69 | armnn::IWorkloadFactory& workloadFactory, |
| 70 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); |