ArmNN
 24.08
RefCastWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2021-2024 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "RefCastWorkload.hpp"
7 #include "RefWorkloadUtils.hpp"
9 #include <ResolveType.hpp>
10 #include "Encoders.hpp"
11 #include "Decoders.hpp"
12 
13 namespace
14 {
16  const uint32_t numElements, const armnn::DataType OutputDataType)
17  {
18  for (unsigned int i = 0; i < numElements; ++i)
19  {
20  switch (OutputDataType)
21  {
25  out.Set(in.Get());
26  break;
27  default:
28  out.Set(std::floor(in.Get()));
29  break;
30  }
31  ++in;
32  ++out;
33  }
34  }
35 
36 
37  // Cast Float to Int64
39  const uint32_t numElements, const armnn::DataType)
40  {
41  for (unsigned int i = 0; i < numElements; ++i)
42  {
43  out.Set(in.Get());
44  ++in;
45  ++out;
46  }
47  }
48 
49  // Cast Int64 To Float
51  const uint32_t numElements, const armnn::DataType)
52  {
53  for (unsigned int i = 0; i < numElements; ++i)
54  {
55  out.Set(static_cast<float>(in.Get()));
56  ++in;
57  ++out;
58  }
59  }
60 }
61 
62 
63 namespace armnn
64 {
65 
67 {
69 }
70 
72 {
73  WorkingMemDescriptor* workingMemDescriptor = static_cast<WorkingMemDescriptor*>(executionData.m_Data);
74  Execute(workingMemDescriptor->m_Inputs, workingMemDescriptor->m_Outputs);
75 }
76 
77 void RefCastWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const
78 {
79  ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID("RefCastWorkload_Execute");
80 
81  TensorInfo inputTensorInfo(GetTensorInfo(inputs[0]));
82  TensorInfo outputTensorInfo(GetTensorInfo(outputs[0]));
83 
84  // Quantization info should set to default values.
85  if (inputTensorInfo.IsQuantized())
86  {
87  inputTensorInfo.SetQuantizationScale(1.0f);
88  inputTensorInfo.SetQuantizationOffset(0);
89  }
90  if (outputTensorInfo.IsQuantized())
91  {
92  outputTensorInfo.SetQuantizationScale(1.0f);
93  outputTensorInfo.SetQuantizationOffset(0);
94  }
95 
96  if(inputTensorInfo.GetDataType() == DataType::Signed64)
97  {
98  Cast(*MakeDecoder<double_t>(inputTensorInfo, inputs[0]->Map()),
99  *MakeEncoder<float>(outputTensorInfo, outputs[0]->Map()),
100  inputTensorInfo.GetNumElements(),
101  outputTensorInfo.GetDataType());
102  }
103  else if(outputTensorInfo.GetDataType() == DataType::Signed64)
104  {
105  Cast(*MakeDecoder<float>(inputTensorInfo, inputs[0]->Map()),
106  *MakeEncoder<double_t>(outputTensorInfo, outputs[0]->Map()),
107  inputTensorInfo.GetNumElements(),
108  outputTensorInfo.GetDataType());
109  }
110  else
111  {
112  Cast(*MakeDecoder<float>(inputTensorInfo, inputs[0]->Map()),
113  *MakeEncoder<float>(outputTensorInfo, outputs[0]->Map()),
114  inputTensorInfo.GetNumElements(),
115  outputTensorInfo.GetDataType());
116  }
117 }
118 
119 } //namespace armnn
armnn::Decoder< float >
armnn::Encoder::Set
virtual void Set(IType right)=0
armnn::experimental::ExecutionData::m_Data
void * m_Data
Definition: ExecutionData.hpp:16
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::DataType::Float32
@ Float32
ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID
#define ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
Definition: RefWorkloadUtils.hpp:22
ResolveType.hpp
armnn::DataType::BFloat16
@ BFloat16
RefCastWorkload.hpp
armnn::Encoder< float >
armnn::DataType::Float16
@ Float16
armnn::DataType
DataType
Definition: Types.hpp:48
armnn::RefCastWorkload::ExecuteAsync
void ExecuteAsync(ExecutionData &executionData) override
Definition: RefCastWorkload.cpp:71
armnn::GetTensorInfo
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
float32 helpers
Definition: RefWorkloadUtils.hpp:33
armnn::RefCastWorkload::Execute
void Execute() const override
Definition: RefCastWorkload.cpp:66
armnn::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
armnn::Decoder::Get
virtual IType Get() const =0
armnn::LayerType::Cast
@ Cast
RefWorkloadUtils.hpp
armnn::BaseWorkload< CastQueueDescriptor >::m_Data
CastQueueDescriptor m_Data
Definition: Workload.hpp:89
Decoders.hpp
armnn::LayerType::Map
@ Map
FloatingPointConverter.hpp
armnn::experimental::WorkingMemDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkingMemDescriptor.hpp:20
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::experimental::WorkingMemDescriptor
Definition: WorkingMemDescriptor.hpp:18
armnn::DataType::Signed64
@ Signed64
Encoders.hpp
armnn::experimental::WorkingMemDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkingMemDescriptor.hpp:21
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26
armnn::experimental::ExecutionData
Definition: ExecutionData.hpp:14