ArmNN
 22.05
NeonConvertBf16ToFp32Workload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 
9 
10 #include <BFloat16.hpp>
11 
13 
14 namespace armnn
15 {
16 
18  const WorkloadInfo& info)
20 {
21  this->m_Data.ValidateInputsOutputs("NeonConvertBf16ToFp32Workload", 1, 1);
22  GatherTensorHandlePairs(descriptor, m_TensorHandlePairs);
23 }
24 
26 {
27  ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID("NeonConvertBf16ToFp32Workload_Execute", this->GetGuid());
28 
29  auto convertFunc = [](uint8_t* dst, const uint8_t* src, size_t size)
30  {
31  auto input = reinterpret_cast<const BFloat16*>(src);
32  auto output = reinterpret_cast<float*>(dst);
33  size_t numElements = size/2; // 2 bytes per Bf16
35  };
36 
37  for (const auto& pair : m_TensorHandlePairs)
38  {
39  CopyTensorContentsGeneric(pair.first, pair.second, convertFunc);
40  }
41 }
42 
44 {
45  ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
46  this->m_Data.m_Inputs[slot] = tensorHandle;
47  try
48  {
49  Reconfigure();
50  }
52  {
53  // Cannot reconfigure, revert the slot back and throw the exception.
54  this->m_Data.m_Inputs[slot] = backupHandle;
55  throw e;
56  }
57 }
58 
59 // Replace output tensor handle with the given TensorHandle
61 {
62  ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
63  this->m_Data.m_Inputs[slot] = tensorHandle;
64  try
65  {
66  Reconfigure();
67  }
69  {
70  // Cannot reconfigure, revert the slot back and throw the exception.
71  this->m_Data.m_Inputs[slot] = backupHandle;
72  throw e;
73  }
74 }
75 
76 void NeonConvertBf16ToFp32Workload::Reconfigure()
77 {
78  throw armnn::UnimplementedException("Reconfigure not implemented for this workload");
79 }
80 
81 } //namespace armnn
static void ConvertBFloat16ToFloat32(const void *srcBFloat16Buffer, size_t numElements, float *dstFloat32Buffer)
NeonConvertBf16ToFp32Workload(const ConvertBf16ToFp32QueueDescriptor &descriptor, const WorkloadInfo &info)
arm::pipe::ProfilingGuid GetGuid() const final
Definition: Workload.hpp:59
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Copyright (c) 2021 ARM Limited and Contributors.
void ReplaceOutputTensorHandle(ITensorHandle *tensorHandle, unsigned int slot) override
QueueDescriptor m_Data
Definition: Workload.hpp:81
void ReplaceInputTensorHandle(ITensorHandle *tensorHandle, unsigned int slot) override
Contains information about TensorInfos of a layer.
void CopyTensorContentsGeneric(const ITensorHandle *srcTensor, ITensorHandle *dstTensor, CopyFunc copy)
std::vector< ITensorHandle * > m_Inputs
void GatherTensorHandlePairs(const DescriptorType &descriptor, std::vector< std::pair< SrcTensorHandleType *, DstTensorHandleType *>> &tensorHandlePairs)
#define ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID(name, guid)