ArmNN
 24.11
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,9> 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  arm_compute::DataType::S64
32  };
33  auto it = std::find(begin(supportedTypes), end(supportedTypes), neonOutputInfo.data_type());
34 
35  if (it != end(supportedTypes))
36  {
37  return arm_compute::Status{};
38  }
39  else
40  {
41  return arm_compute::Status{arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported DataType"};
42  }
43 }
44 
46  const WorkloadInfo& info,
47  const arm_compute::CLCompileContext&)
49  , m_RanOnce(false)
50 {
51 }
52 
54 {
55  ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClConstantWorkload_Execute");
56 
57  // The intermediate tensor held by the corresponding layer output handler can be initialised with the given data
58  // on the first inference, then reused for subsequent inferences.
59  // The initialisation cannot happen at workload construction time since the ACL kernel for the next layer may not
60  // have been configured at the time.
61  if (!m_RanOnce)
62  {
63  const ConstantQueueDescriptor& data = this->m_Data;
64 
65  ARMNN_THROW_INVALIDARG_MSG_IF_FALSE(data.m_LayerOutput, "Output tensor handle is null.");
66  arm_compute::CLTensor& output = static_cast<ClTensorHandle*>(data.m_Outputs[0])->GetTensor();
67  arm_compute::DataType computeDataType = static_cast<ClTensorHandle*>(data.m_Outputs[0])->GetDataType();
68 
69  switch (computeDataType)
70  {
71  case arm_compute::DataType::F16:
72  {
74  break;
75  }
76  case arm_compute::DataType::F32:
77  {
79  break;
80  }
81  case arm_compute::DataType::QASYMM8:
82  {
84  break;
85  }
86  case arm_compute::DataType::QASYMM8_SIGNED:
87  {
89  break;
90  }
91  case arm_compute::DataType::QSYMM16:
92  {
94  break;
95  }
96  case arm_compute::DataType::QSYMM8:
97  case arm_compute::DataType::QSYMM8_PER_CHANNEL:
98  {
100  break;
101  }
102  case arm_compute::DataType::S32:
103  {
104  CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<int32_t>());
105  break;
106  }
107  case arm_compute::DataType::S64:
108  {
109  CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<int64_t>());
110  break;
111  }
112  default:
113  {
114  throw InvalidArgumentException("Unknown data type.");
115  }
116  }
117 
118  m_RanOnce = true;
119  }
120 }
121 
122 } //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::ClConstantWorkload::Execute
void Execute() const override
Definition: ClConstantWorkload.cpp:53
armnn::CopyArmComputeClTensorData
void CopyArmComputeClTensorData(arm_compute::CLTensor &dstTensor, const T *srcData)
Definition: ClWorkloadUtils.hpp:64
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:45
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