blob: bbf6476c0ade2056141ccfab4f24869956e6fa68 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
Mike Kelly7cbe7812023-07-25 17:37:33 +01002// Copyright © 2017-2018,2020-2023 Arm Ltd and Contributors. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5
Nattapat Chaimanowong55b1cda2018-10-10 14:51:27 +01006#include "ClConstantWorkload.hpp"
arovir01616e7752018-10-01 17:08:59 +01007
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +00008#include <Half.hpp>
9#include <aclCommon/ArmComputeTensorUtils.hpp>
10#include <cl/ClTensorHandle.hpp>
Colm Donelan0c479742021-12-10 12:43:54 +000011#include <armnn/backends/TensorHandle.hpp>
telsoa014fcda012018-03-09 14:13:49 +000012
Matthew Bentham14e46692018-09-20 15:35:30 +010013#include "ClWorkloadUtils.hpp"
14
telsoa014fcda012018-03-09 14:13:49 +000015namespace armnn
16{
17
Mike Kelly0886ac42020-04-27 09:55:40 +010018arm_compute::Status ClConstantWorkloadValidate(const TensorInfo& output)
19{
20 const arm_compute::TensorInfo neonOutputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(output);
21
Teresa Charlin9ad2e5b2020-04-10 22:34:48 +010022 std::array<arm_compute::DataType,8> supportedTypes = {
Mike Kelly0886ac42020-04-27 09:55:40 +010023 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,
Teresa Charlin9ad2e5b2020-04-10 22:34:48 +010029 arm_compute::DataType::QSYMM8_PER_CHANNEL,
30 arm_compute::DataType::S32
Mike Kelly0886ac42020-04-27 09:55:40 +010031 };
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
Sadik Armagane9444752020-12-02 11:28:58 +000044ClConstantWorkload::ClConstantWorkload(const ConstantQueueDescriptor& descriptor,
45 const WorkloadInfo& info,
46 const arm_compute::CLCompileContext&)
Teresa Charlin588cbdf2022-01-19 15:55:37 +000047 : ClBaseWorkload<ConstantQueueDescriptor>(descriptor, info)
Nattapat Chaimanowong55b1cda2018-10-10 14:51:27 +010048 , m_RanOnce(false)
telsoa014fcda012018-03-09 14:13:49 +000049{
Nattapat Chaimanowong55b1cda2018-10-10 14:51:27 +010050}
51
52void ClConstantWorkload::Execute() const
53{
Mike Kelly7cbe7812023-07-25 17:37:33 +010054 ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClConstantWorkload_Execute");
Nattapat Chaimanowong55b1cda2018-10-10 14:51:27 +010055
telsoa014fcda012018-03-09 14:13:49 +000056 // 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
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +010064 ARMNN_ASSERT(data.m_LayerOutput != nullptr);
telsoa014fcda012018-03-09 14:13:49 +000065 arm_compute::CLTensor& output = static_cast<ClTensorHandle*>(data.m_Outputs[0])->GetTensor();
telsoa01c577f2c2018-08-31 09:22:23 +010066 arm_compute::DataType computeDataType = static_cast<ClTensorHandle*>(data.m_Outputs[0])->GetDataType();
telsoa014fcda012018-03-09 14:13:49 +000067
telsoa01c577f2c2018-08-31 09:22:23 +010068 switch (computeDataType)
telsoa014fcda012018-03-09 14:13:49 +000069 {
telsoa01c577f2c2018-08-31 09:22:23 +010070 case arm_compute::DataType::F16:
71 {
Matthew Benthamca6616c2018-09-21 15:16:53 +010072 CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<Half>());
telsoa01c577f2c2018-08-31 09:22:23 +010073 break;
74 }
75 case arm_compute::DataType::F32:
telsoa014fcda012018-03-09 14:13:49 +000076 {
Matthew Benthamca6616c2018-09-21 15:16:53 +010077 CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<float>());
telsoa014fcda012018-03-09 14:13:49 +000078 break;
79 }
telsoa01c577f2c2018-08-31 09:22:23 +010080 case arm_compute::DataType::QASYMM8:
telsoa014fcda012018-03-09 14:13:49 +000081 {
Matthew Benthamca6616c2018-09-21 15:16:53 +010082 CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<uint8_t>());
telsoa014fcda012018-03-09 14:13:49 +000083 break;
84 }
Mike Kelly0886ac42020-04-27 09:55:40 +010085 case arm_compute::DataType::QASYMM8_SIGNED:
86 {
87 CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<int8_t>());
88 break;
89 }
90 case arm_compute::DataType::QSYMM16:
91 {
92 CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<int16_t>());
93 break;
94 }
95 case arm_compute::DataType::QSYMM8:
96 case arm_compute::DataType::QSYMM8_PER_CHANNEL:
97 {
98 CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<int8_t>());
99 break;
100 }
Teresa Charlin9ad2e5b2020-04-10 22:34:48 +0100101 case arm_compute::DataType::S32:
102 {
103 CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<int32_t>());
104 break;
105 }
telsoa014fcda012018-03-09 14:13:49 +0000106 default:
107 {
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100108 ARMNN_ASSERT_MSG(false, "Unknown data type");
telsoa014fcda012018-03-09 14:13:49 +0000109 break;
110 }
111 }
112
113 m_RanOnce = true;
114 }
115}
116
Matthew Bentham14e46692018-09-20 15:35:30 +0100117} //namespace armnn