telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1 | // |
| 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 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 4 | // |
| 5 | |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 6 | #include "ConvertFp16ToFp32TestImpl.hpp" |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 7 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 8 | #include <Half.hpp> |
| 9 | |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 10 | #include <armnn/ArmNN.hpp> |
| 11 | |
| 12 | #include <backendsCommon/test/TensorCopyUtils.hpp> |
| 13 | #include <backendsCommon/test/WorkloadTestUtils.hpp> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 14 | |
| 15 | #include <test/TensorHelpers.hpp> |
| 16 | |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 17 | LayerTestResult<float, 4> SimpleConvertFp16ToFp32Test( |
| 18 | armnn::IWorkloadFactory& workloadFactory, |
| 19 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 20 | { |
Derek Lamberti | c374ff0 | 2019-12-10 21:57:35 +0000 | [diff] [blame^] | 21 | boost::ignore_unused(memoryManager); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 22 | using namespace half_float::literal; |
| 23 | |
| 24 | const armnn::TensorInfo inputTensorInfo({1, 3, 2, 3}, armnn::DataType::Float16); |
| 25 | const armnn::TensorInfo outputTensorInfo({1, 3, 2, 3}, armnn::DataType::Float32); |
| 26 | |
| 27 | auto input = MakeTensor<armnn::Half, 4>(inputTensorInfo, |
| 28 | { -37.5_h, -15.2_h, -8.76_h, -2.0_h, -1.5_h, -1.3_h, -0.5_h, -0.4_h, 0.0_h, |
| 29 | 1.0_h, 0.4_h, 0.5_h, 1.3_h, 1.5_h, 2.0_h, 8.76_h, 15.2_h, 37.5_h }); |
| 30 | |
| 31 | LayerTestResult<float, 4> ret(outputTensorInfo); |
| 32 | ret.outputExpected = MakeTensor<float, 4>(outputTensorInfo, |
| 33 | { -37.5f, -15.2f, -8.76f, -2.0f, -1.5f, -1.3f, -0.5f, -0.4f, 0.0f, |
| 34 | 1.0f, 0.4f, 0.5f, 1.3f, 1.5f, 2.0f, 8.76f, 15.2f, 37.5f }); |
| 35 | |
| 36 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); |
| 37 | std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); |
| 38 | |
| 39 | armnn::ConvertFp16ToFp32QueueDescriptor data; |
| 40 | armnn::WorkloadInfo info; |
| 41 | AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); |
| 42 | AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); |
| 43 | |
| 44 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateConvertFp16ToFp32(data, info); |
| 45 | |
| 46 | inputHandle->Allocate(); |
| 47 | outputHandle->Allocate(); |
| 48 | |
| 49 | CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]); |
| 50 | |
| 51 | workload->Execute(); |
| 52 | |
| 53 | CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get()); |
| 54 | |
| 55 | return ret; |
| 56 | } |