ArmNN
 24.02
NeonConvertFp16ToFp32Workload Class Reference

#include <NeonConvertFp16ToFp32Workload.hpp>

Inheritance diagram for NeonConvertFp16ToFp32Workload:
[legend]
Collaboration diagram for NeonConvertFp16ToFp32Workload:
[legend]

Public Member Functions

 NeonConvertFp16ToFp32Workload (const ConvertFp16ToFp32QueueDescriptor &descriptor, const WorkloadInfo &info)
 
virtual void Execute () const override
 
void ReplaceInputTensorHandle (ITensorHandle *tensorHandle, unsigned int slot) override
 
void ReplaceOutputTensorHandle (ITensorHandle *tensorHandle, unsigned int slot) override
 
- Public Member Functions inherited from MultiTypedWorkload< QueueDescriptor, InputDataType, OutputDataType >
 MultiTypedWorkload (const QueueDescriptor &descriptor, const WorkloadInfo &info)
 
- Public Member Functions inherited from BaseWorkload< QueueDescriptor >
 BaseWorkload (const QueueDescriptor &descriptor, const WorkloadInfo &info)
 
virtual const std::string & GetName () const override
 
void ExecuteAsync (ExecutionData &executionData) override
 
void PostAllocationConfigure () override
 
const QueueDescriptorGetData () const
 
arm::pipe::ProfilingGuid GetGuid () const final
 
virtual bool SupportsTensorHandleReplacement () const override
 
- Public Member Functions inherited from IWorkload
virtual ~IWorkload ()
 
virtual void RegisterDebugCallback (const DebugCallbackFunction &)
 
virtual armnn::Optional< armnn::MemoryRequirementsGetMemoryRequirements ()
 

Additional Inherited Members

- Protected Attributes inherited from BaseWorkload< QueueDescriptor >
QueueDescriptor m_Data
 
const arm::pipe::ProfilingGuid m_Guid
 
const std::string m_Name
 

Detailed Description

Definition at line 20 of file NeonConvertFp16ToFp32Workload.hpp.

Constructor & Destructor Documentation

◆ NeonConvertFp16ToFp32Workload()

Definition at line 29 of file NeonConvertFp16ToFp32Workload.cpp.

31  : Float16ToFloat32Workload<ConvertFp16ToFp32QueueDescriptor>(descriptor, info)
32 {
33  this->m_Data.ValidateInputsOutputs("NeonConvertFp16ToFp32Workload", 1, 1);
34 
35  arm_compute::ITensor& input = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
36  arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
37 
38  if (arm_compute::NECast::validate(input.info(), output.info(), g_AclConvertPolicy))
39  {
40  // Use NECast if supported (needs hardware support for FP16)
41  m_Cast.reset(new arm_compute::NECast());
42  m_Cast->configure(&input, &output, g_AclConvertPolicy);
43  }
44  else
45  {
46  // Else use software implementation using Half.hpp
47  GatherTensorHandlePairs(descriptor, m_TensorHandlePairs);
48  }
49 }

References armnn::GatherTensorHandlePairs(), armnn::info, BaseWorkload< QueueDescriptor >::m_Data, QueueDescriptor::m_Inputs, QueueDescriptor::m_Outputs, and QueueDescriptor::ValidateInputsOutputs().

Member Function Documentation

◆ Execute()

void Execute ( ) const
overridevirtual

Implements IWorkload.

Definition at line 51 of file NeonConvertFp16ToFp32Workload.cpp.

52 {
53  ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID("NeonConvertFp16ToFp32Workload_Execute");
54 
55  if (m_Cast)
56  {
57  // Use NECast if supported and initialised
58  m_Cast->run();
59  }
60  else
61  {
62  // Else use softare implementation using Half.hpp
63  auto convertFunc = [](uint8_t* dst, const uint8_t* src, size_t size)
64  {
65  auto input = reinterpret_cast<const Half*>(src);
66  auto output = reinterpret_cast<float*>(dst);
67  size_t numElements = size/2; // 2 bytes per fp16
69  };
70 
71  for (const auto& pair : m_TensorHandlePairs)
72  {
73  CopyTensorContentsGeneric(pair.first, pair.second, convertFunc);
74  }
75  }
76 }

References ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID, FloatingPointConverter::ConvertFloat16To32(), and armnn::CopyTensorContentsGeneric().

◆ ReplaceInputTensorHandle()

void ReplaceInputTensorHandle ( ITensorHandle tensorHandle,
unsigned int  slot 
)
overridevirtual

Reimplemented from BaseWorkload< QueueDescriptor >.

Definition at line 78 of file NeonConvertFp16ToFp32Workload.cpp.

79 {
80  ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
81  this->m_Data.m_Inputs[slot] = tensorHandle;
82  try
83  {
84  Reconfigure();
85  }
87  {
88  // Cannot reconfigure, revert the slot back and throw the exception.
89  this->m_Data.m_Inputs[slot] = backupHandle;
90  throw e;
91  }
92 }

References BaseWorkload< QueueDescriptor >::m_Data, and QueueDescriptor::m_Inputs.

◆ ReplaceOutputTensorHandle()

void ReplaceOutputTensorHandle ( ITensorHandle tensorHandle,
unsigned int  slot 
)
overridevirtual

Reimplemented from BaseWorkload< QueueDescriptor >.

Definition at line 95 of file NeonConvertFp16ToFp32Workload.cpp.

96 {
97  ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
98  this->m_Data.m_Inputs[slot] = tensorHandle;
99  try
100  {
101  Reconfigure();
102  }
104  {
105  // Cannot reconfigure, revert the slot back and throw the exception.
106  this->m_Data.m_Inputs[slot] = backupHandle;
107  throw e;
108  }
109 }

References BaseWorkload< QueueDescriptor >::m_Data, and QueueDescriptor::m_Inputs.


The documentation for this class was generated from the following files:
armnn::QueueDescriptor::ValidateInputsOutputs
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Definition: WorkloadData.cpp:446
armnn::Half
half_float::half Half
Definition: Half.hpp:22
armnnUtils::FloatingPointConverter::ConvertFloat16To32
static void ConvertFloat16To32(const void *srcFloat16Buffer, size_t numElements, float *dstFloat32Buffer)
Definition: FloatingPointConverter.cpp:43
armnn::GatherTensorHandlePairs
void GatherTensorHandlePairs(const DescriptorType &descriptor, std::vector< std::pair< SrcTensorHandleType *, DstTensorHandleType * >> &tensorHandlePairs)
Definition: WorkloadUtils.hpp:204
armnn::CopyTensorContentsGeneric
void CopyTensorContentsGeneric(const ITensorHandle *srcTensor, ITensorHandle *dstTensor, CopyFunc copy)
Definition: WorkloadUtils.hpp:46
armnn::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
armnn::BaseWorkload::m_Data
QueueDescriptor m_Data
Definition: Workload.hpp:89
armnn::UnimplementedException
Definition: Exceptions.hpp:98
ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID
#define ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
Definition: NeonWorkloadUtils.hpp:32
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26