telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
Teresa Charlin | 588cbdf | 2022-01-19 15:55:37 +0000 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | |
Nattapat Chaimanowong | 55b1cda | 2018-10-10 14:51:27 +0100 | [diff] [blame] | 6 | #include "ClConstantWorkload.hpp" |
arovir01 | 616e775 | 2018-10-01 17:08:59 +0100 | [diff] [blame] | 7 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 8 | #include <Half.hpp> |
| 9 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
| 10 | #include <cl/ClTensorHandle.hpp> |
Colm Donelan | 0c47974 | 2021-12-10 12:43:54 +0000 | [diff] [blame] | 11 | #include <armnn/backends/TensorHandle.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 12 | |
Matthew Bentham | 14e4669 | 2018-09-20 15:35:30 +0100 | [diff] [blame] | 13 | #include "ClWorkloadUtils.hpp" |
| 14 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 15 | namespace armnn |
| 16 | { |
| 17 | |
Mike Kelly | 0886ac4 | 2020-04-27 09:55:40 +0100 | [diff] [blame] | 18 | arm_compute::Status ClConstantWorkloadValidate(const TensorInfo& output) |
| 19 | { |
| 20 | const arm_compute::TensorInfo neonOutputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(output); |
| 21 | |
Teresa Charlin | 9ad2e5b | 2020-04-10 22:34:48 +0100 | [diff] [blame] | 22 | std::array<arm_compute::DataType,8> supportedTypes = { |
Mike Kelly | 0886ac4 | 2020-04-27 09:55:40 +0100 | [diff] [blame] | 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, |
Teresa Charlin | 9ad2e5b | 2020-04-10 22:34:48 +0100 | [diff] [blame] | 29 | arm_compute::DataType::QSYMM8_PER_CHANNEL, |
| 30 | arm_compute::DataType::S32 |
Mike Kelly | 0886ac4 | 2020-04-27 09:55:40 +0100 | [diff] [blame] | 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 | |
Sadik Armagan | e944475 | 2020-12-02 11:28:58 +0000 | [diff] [blame] | 44 | ClConstantWorkload::ClConstantWorkload(const ConstantQueueDescriptor& descriptor, |
| 45 | const WorkloadInfo& info, |
| 46 | const arm_compute::CLCompileContext&) |
Teresa Charlin | 588cbdf | 2022-01-19 15:55:37 +0000 | [diff] [blame] | 47 | : ClBaseWorkload<ConstantQueueDescriptor>(descriptor, info) |
Nattapat Chaimanowong | 55b1cda | 2018-10-10 14:51:27 +0100 | [diff] [blame] | 48 | , m_RanOnce(false) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 49 | { |
Nattapat Chaimanowong | 55b1cda | 2018-10-10 14:51:27 +0100 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void ClConstantWorkload::Execute() const |
| 53 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 54 | ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClConstantWorkload_Execute", this->GetGuid()); |
Nattapat Chaimanowong | 55b1cda | 2018-10-10 14:51:27 +0100 | [diff] [blame] | 55 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 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 | |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 64 | ARMNN_ASSERT(data.m_LayerOutput != nullptr); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 65 | arm_compute::CLTensor& output = static_cast<ClTensorHandle*>(data.m_Outputs[0])->GetTensor(); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 66 | arm_compute::DataType computeDataType = static_cast<ClTensorHandle*>(data.m_Outputs[0])->GetDataType(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 67 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 68 | switch (computeDataType) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 69 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 70 | case arm_compute::DataType::F16: |
| 71 | { |
Matthew Bentham | ca6616c | 2018-09-21 15:16:53 +0100 | [diff] [blame] | 72 | CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<Half>()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 73 | break; |
| 74 | } |
| 75 | case arm_compute::DataType::F32: |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 76 | { |
Matthew Bentham | ca6616c | 2018-09-21 15:16:53 +0100 | [diff] [blame] | 77 | CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<float>()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 78 | break; |
| 79 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 80 | case arm_compute::DataType::QASYMM8: |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 81 | { |
Matthew Bentham | ca6616c | 2018-09-21 15:16:53 +0100 | [diff] [blame] | 82 | CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<uint8_t>()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 83 | break; |
| 84 | } |
Mike Kelly | 0886ac4 | 2020-04-27 09:55:40 +0100 | [diff] [blame] | 85 | 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 Charlin | 9ad2e5b | 2020-04-10 22:34:48 +0100 | [diff] [blame] | 101 | case arm_compute::DataType::S32: |
| 102 | { |
| 103 | CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<int32_t>()); |
| 104 | break; |
| 105 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 106 | default: |
| 107 | { |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 108 | ARMNN_ASSERT_MSG(false, "Unknown data type"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 109 | break; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | m_RanOnce = true; |
| 114 | } |
| 115 | } |
| 116 | |
Matthew Bentham | 14e4669 | 2018-09-20 15:35:30 +0100 | [diff] [blame] | 117 | } //namespace armnn |