ArmNN
 24.08
ClConstantWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017-2018,2020-2024 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "ClConstantWorkload.hpp"
7 
8 #include <Half.hpp>
10 #include <cl/ClTensorHandle.hpp>
12 
13 #include "ClWorkloadUtils.hpp"
14 
15 namespace armnn
16 {
17 
19 {
20  const arm_compute::TensorInfo neonOutputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(output);
21 
22  std::array<arm_compute::DataType,8> supportedTypes = {
23  arm_compute::DataType::F16,
24  arm_compute::DataType::F32,
25  arm_compute::DataType::QASYMM8,
26  arm_compute::DataType::QASYMM8_SIGNED,
27  arm_compute::DataType::QSYMM16,
28  arm_compute::DataType::QSYMM8,
29  arm_compute::DataType::QSYMM8_PER_CHANNEL,
30  arm_compute::DataType::S32
31  };
32  auto it = std::find(begin(supportedTypes), end(supportedTypes), neonOutputInfo.data_type());
33 
34  if (it != end(supportedTypes))
35  {
36  return arm_compute::Status{};
37  }
38  else
39  {
40  return arm_compute::Status{arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported DataType"};
41  }
42 }
43 
45  const WorkloadInfo& info,
46  const arm_compute::CLCompileContext&)
48  , m_RanOnce(false)
49 {
50 }
51 
53 {
54  ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClConstantWorkload_Execute");
55 
56  // The intermediate tensor held by the corresponding layer output handler can be initialised with the given data
57  // on the first inference, then reused for subsequent inferences.
58  // The initialisation cannot happen at workload construction time since the ACL kernel for the next layer may not
59  // have been configured at the time.
60  if (!m_RanOnce)
61  {
62  const ConstantQueueDescriptor& data = this->m_Data;
63 
64  ARMNN_THROW_INVALIDARG_MSG_IF_FALSE(data.m_LayerOutput, "Output tensor handle is null.");
65  arm_compute::CLTensor& output = static_cast<ClTensorHandle*>(data.m_Outputs[0])->GetTensor();
66  arm_compute::DataType computeDataType = static_cast<ClTensorHandle*>(data.m_Outputs[0])->GetDataType();
67 
68  switch (computeDataType)
69  {
70  case arm_compute::DataType::F16:
71  {
73  break;
74  }
75  case arm_compute::DataType::F32:
76  {
78  break;
79  }
80  case arm_compute::DataType::QASYMM8:
81  {
83  break;
84  }
85  case arm_compute::DataType::QASYMM8_SIGNED:
86  {
88  break;
89  }
90  case arm_compute::DataType::QSYMM16:
91  {
93  break;
94  }
95  case arm_compute::DataType::QSYMM8:
96  case arm_compute::DataType::QSYMM8_PER_CHANNEL:
97  {
99  break;
100  }
101  case arm_compute::DataType::S32:
102  {
103  CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<int32_t>());
104  break;
105  }
106  default:
107  {
108  throw InvalidArgumentException("Unknown data type.");
109  }
110  }
111 
112  m_RanOnce = true;
113  }
114 }
115 
116 } //namespace armnn
ClConstantWorkload.hpp
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::ClBaseWorkload
Definition: ClBaseWorkload.hpp:13
armnn::Half
half_float::half Half
Definition: Half.hpp:22
armnn::CopyArmComputeClTensorData
void CopyArmComputeClTensorData(arm_compute::CLTensor &dstTensor, const T *srcData)
Definition: ClWorkloadUtils.hpp:64
armnn::ClConstantWorkload::Execute
void Execute() const override
Definition: ClConstantWorkload.cpp:52
armnn::ConstantQueueDescriptor
Definition: WorkloadData.hpp:368
armnn::ConstTensorHandle::GetConstTensor
const T * GetConstTensor() const
Definition: TensorHandle.hpp:28
armnn::ClConstantWorkloadValidate
arm_compute::Status ClConstantWorkloadValidate(const TensorInfo &output)
Definition: ClConstantWorkload.cpp:18
ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID
#define ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
Definition: ClWorkloadUtils.hpp:36
armnn::ClTensorHandle
Definition: ClTensorHandle.hpp:28
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
armnn::DataType
DataType
Definition: Types.hpp:48
ClWorkloadUtils.hpp
armnn::InvalidArgumentException
Definition: Exceptions.hpp:80
armnn::BoostLogSeverityMapping::info
@ info
armnn::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
armnn::ClConstantWorkload::ClConstantWorkload
ClConstantWorkload(const ConstantQueueDescriptor &descriptor, const WorkloadInfo &info, const arm_compute::CLCompileContext &clCompileContext)
Definition: ClConstantWorkload.cpp:44
armnn::ConstantQueueDescriptor::m_LayerOutput
const ConstTensorHandle * m_LayerOutput
Definition: WorkloadData.hpp:375
Half.hpp
TensorHandle.hpp
armnn::Status
Status
Definition: Types.hpp:42
ClTensorHandle.hpp
armnn::BaseWorkload< ConstantQueueDescriptor >::m_Data
ConstantQueueDescriptor m_Data
Definition: Workload.hpp:89
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
ArmComputeTensorUtils.hpp
ARMNN_THROW_INVALIDARG_MSG_IF_FALSE
#define ARMNN_THROW_INVALIDARG_MSG_IF_FALSE(_cond, _str)
Definition: Exceptions.hpp:210