blob: 40fbce6f4e8b6ee3b518e6839dac6967d3970442 [file] [log] [blame]
mathad01b392e982021-04-07 12:07:30 +01001//
Mike Kelly7cbe7812023-07-25 17:37:33 +01002// Copyright © 2021-2023 Arm Ltd and Contributors. All rights reserved.
mathad01b392e982021-04-07 12:07:30 +01003// SPDX-License-Identifier: MIT
4//
5
6#include "RefCastWorkload.hpp"
7#include "RefWorkloadUtils.hpp"
8#include <armnnUtils/FloatingPointConverter.hpp>
9#include <ResolveType.hpp>
10#include "Encoders.hpp"
11#include "Decoders.hpp"
12
13namespace
14{
15 void Cast(armnn::Decoder<float>& in, armnn::Encoder<float>& out, const uint32_t numElements )
16 {
17 for (unsigned int i = 0; i < numElements; i++)
18 {
19 out.Set(in.Get());
20 ++in;
21 ++out;
22 }
23 }
24}
25
26namespace armnn
27{
28
Sadik Armagan2241d182021-04-23 15:20:07 +010029void RefCastWorkload::Execute() const
30{
31 Execute(m_Data.m_Inputs, m_Data.m_Outputs);
32}
mathad01b392e982021-04-07 12:07:30 +010033
Matthew Sloyan2d213a72022-06-30 17:13:04 +010034void RefCastWorkload::ExecuteAsync(ExecutionData& executionData)
Sadik Armagan2241d182021-04-23 15:20:07 +010035{
Matthew Sloyan2d213a72022-06-30 17:13:04 +010036 WorkingMemDescriptor* workingMemDescriptor = static_cast<WorkingMemDescriptor*>(executionData.m_Data);
37 Execute(workingMemDescriptor->m_Inputs, workingMemDescriptor->m_Outputs);
Sadik Armagan2241d182021-04-23 15:20:07 +010038}
39
40void RefCastWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const
41{
Mike Kelly7cbe7812023-07-25 17:37:33 +010042 ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID("RefCastWorkload_Execute");
Sadik Armagan2241d182021-04-23 15:20:07 +010043
44 TensorInfo inputTensorInfo(GetTensorInfo(inputs[0]));
45 TensorInfo outputTensorInfo(GetTensorInfo(outputs[0]));
46
47 // Quantization info should set to default values.
48 if (inputTensorInfo.IsQuantized())
49 {
50 inputTensorInfo.SetQuantizationScale(1.0f);
51 inputTensorInfo.SetQuantizationOffset(0);
mathad01b392e982021-04-07 12:07:30 +010052 }
Sadik Armagan2241d182021-04-23 15:20:07 +010053 if (outputTensorInfo.IsQuantized())
54 {
55 outputTensorInfo.SetQuantizationScale(1.0f);
56 outputTensorInfo.SetQuantizationOffset(0);
57 }
58
59 Cast(*MakeDecoder<float>(inputTensorInfo, inputs[0]->Map()),
60 *MakeEncoder<float>(outputTensorInfo, outputs[0]->Map()),
61 inputTensorInfo.GetNumElements());
62}
mathad01b392e982021-04-07 12:07:30 +010063
64} //namespace armnn