ArmNN
 20.05
ClConstantWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. 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,7> 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  };
31  auto it = std::find(begin(supportedTypes), end(supportedTypes), neonOutputInfo.data_type());
32 
33  if (it != end(supportedTypes))
34  {
35  return arm_compute::Status{};
36  }
37  else
38  {
39  return arm_compute::Status{arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported DataType"};
40  }
41 }
42 
44  : BaseWorkload<ConstantQueueDescriptor>(descriptor, info)
45  , m_RanOnce(false)
46 {
47 }
48 
50 {
51  ARMNN_SCOPED_PROFILING_EVENT_CL("ClConstantWorkload_Execute");
52 
53  // The intermediate tensor held by the corresponding layer output handler can be initialised with the given data
54  // on the first inference, then reused for subsequent inferences.
55  // The initialisation cannot happen at workload construction time since the ACL kernel for the next layer may not
56  // have been configured at the time.
57  if (!m_RanOnce)
58  {
59  const ConstantQueueDescriptor& data = this->m_Data;
60 
61  ARMNN_ASSERT(data.m_LayerOutput != nullptr);
62  arm_compute::CLTensor& output = static_cast<ClTensorHandle*>(data.m_Outputs[0])->GetTensor();
63  arm_compute::DataType computeDataType = static_cast<ClTensorHandle*>(data.m_Outputs[0])->GetDataType();
64 
65  switch (computeDataType)
66  {
67  case arm_compute::DataType::F16:
68  {
70  break;
71  }
72  case arm_compute::DataType::F32:
73  {
75  break;
76  }
77  case arm_compute::DataType::QASYMM8:
78  {
80  break;
81  }
82  case arm_compute::DataType::QASYMM8_SIGNED:
83  {
85  break;
86  }
87  case arm_compute::DataType::QSYMM16:
88  {
90  break;
91  }
92  case arm_compute::DataType::QSYMM8:
93  case arm_compute::DataType::QSYMM8_PER_CHANNEL:
94  {
96  break;
97  }
98  default:
99  {
100  ARMNN_ASSERT_MSG(false, "Unknown data type");
101  break;
102  }
103  }
104 
105  m_RanOnce = true;
106  }
107 }
108 
109 } //namespace armnn
void Execute() const override
DataLayout::NHWC false
#define ARMNN_SCOPED_PROFILING_EVENT_CL(name)
const ConstantQueueDescriptor m_Data
Definition: Workload.hpp:46
const ConstCpuTensorHandle * m_LayerOutput
const T * GetConstTensor() const
Copyright (c) 2020 ARM Limited.
DataType
Definition: Types.hpp:32
#define ARMNN_ASSERT_MSG(COND, MSG)
Definition: Assert.hpp:15
arm_compute::Status ClConstantWorkloadValidate(const TensorInfo &output)
Status
enumeration
Definition: Types.hpp:26
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
ClConstantWorkload(const ConstantQueueDescriptor &descriptor, const WorkloadInfo &info)
void CopyArmComputeClTensorData(arm_compute::CLTensor &dstTensor, const T *srcData)
std::vector< ITensorHandle * > m_Outputs
Contains information about inputs and outputs to a layer.
half_float::half Half
Definition: Half.hpp:16