telsoa01 | c577f2c | 2018-08-31 09:22:23 +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. |
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 | |
Sadik Armagan | a097d2a | 2021-11-24 15:47:28 +0000 | [diff] [blame] | 11 | #include <armnnTestUtils/TensorCopyUtils.hpp> |
Colm Donelan | 0c47974 | 2021-12-10 12:43:54 +0000 | [diff] [blame] | 12 | #include <armnnTestUtils/WorkloadTestUtils.hpp> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 13 | |
Sadik Armagan | a097d2a | 2021-11-24 15:47:28 +0000 | [diff] [blame] | 14 | #include <TensorHelpers.hpp> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 15 | |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 16 | LayerTestResult<float, 4> SimpleConvertFp16ToFp32Test( |
| 17 | armnn::IWorkloadFactory& workloadFactory, |
Keith Davis | f500d6c | 2020-08-31 08:32:55 +0100 | [diff] [blame] | 18 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 19 | const armnn::ITensorHandleFactory& tensorHandleFactory) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 20 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 21 | IgnoreUnused(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 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 27 | std::vector<armnn::Half> input = |
| 28 | { |
| 29 | -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, |
| 30 | 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 |
| 31 | }; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 32 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 33 | std::vector<float> expectedOutput = |
| 34 | { |
| 35 | -37.5f, -15.2f, -8.76f, -2.0f, -1.5f, -1.3f, -0.5f, -0.4f, 0.0f, |
| 36 | 1.0f, 0.4f, 0.5f, 1.3f, 1.5f, 2.0f, 8.76f, 15.2f, 37.5f |
| 37 | }; |
| 38 | |
| 39 | std::vector<float> actualOutput(outputTensorInfo.GetNumElements()); |
Keith Davis | f500d6c | 2020-08-31 08:32:55 +0100 | [diff] [blame] | 40 | |
| 41 | std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo); |
| 42 | std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo); |
| 43 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 44 | armnn::ConvertFp16ToFp32QueueDescriptor data; |
| 45 | armnn::WorkloadInfo info; |
| 46 | AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); |
| 47 | AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); |
| 48 | |
| 49 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateConvertFp16ToFp32(data, info); |
| 50 | |
| 51 | inputHandle->Allocate(); |
| 52 | outputHandle->Allocate(); |
| 53 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 54 | CopyDataToITensorHandle(inputHandle.get(), input.data()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 55 | |
| 56 | workload->Execute(); |
| 57 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 58 | CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 59 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 60 | return LayerTestResult<float, 4>(actualOutput, |
| 61 | expectedOutput, |
| 62 | outputHandle->GetShape(), |
| 63 | outputTensorInfo.GetShape()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 64 | } |