Nattapat Chaimanowong | 233b3d6 | 2018-10-12 12:02:18 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "NeonConstantWorkload.hpp" |
| 7 | |
| 8 | #include <arm_compute/core/Types.h> |
Narumol Prangnawarat | 250d392 | 2020-03-30 16:11:04 +0100 | [diff] [blame] | 9 | #include <BFloat16.hpp> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 10 | #include <Half.hpp> |
| 11 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 12 | #include <armnn/utility/PolymorphicDowncast.hpp> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 13 | #include <neon/NeonTensorHandle.hpp> |
| 14 | #include <backendsCommon/CpuTensorHandle.hpp> |
| 15 | #include <backendsCommon/Workload.hpp> |
Nattapat Chaimanowong | 233b3d6 | 2018-10-12 12:02:18 +0100 | [diff] [blame] | 16 | |
| 17 | #include <boost/cast.hpp> |
| 18 | |
| 19 | namespace armnn |
| 20 | { |
| 21 | |
Mike Kelly | 0886ac4 | 2020-04-27 09:55:40 +0100 | [diff] [blame] | 22 | arm_compute::Status NeonConstantWorkloadValidate(const TensorInfo& output) |
| 23 | { |
| 24 | const arm_compute::TensorInfo neonOutputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(output); |
| 25 | |
Teresa Charlin | f540eb8 | 2020-04-10 19:24:55 +0100 | [diff] [blame] | 26 | std::array<arm_compute::DataType,9> supportedTypes = { |
Mike Kelly | 0886ac4 | 2020-04-27 09:55:40 +0100 | [diff] [blame] | 27 | arm_compute::DataType::BFLOAT16, |
| 28 | arm_compute::DataType::F16, |
| 29 | arm_compute::DataType::F32, |
| 30 | arm_compute::DataType::QASYMM8, |
| 31 | arm_compute::DataType::QASYMM8_SIGNED, |
| 32 | arm_compute::DataType::QSYMM16, |
| 33 | arm_compute::DataType::QSYMM8, |
Teresa Charlin | f540eb8 | 2020-04-10 19:24:55 +0100 | [diff] [blame] | 34 | arm_compute::DataType::QSYMM8_PER_CHANNEL, |
| 35 | arm_compute::DataType::S32 |
Mike Kelly | 0886ac4 | 2020-04-27 09:55:40 +0100 | [diff] [blame] | 36 | }; |
| 37 | auto it = std::find(begin(supportedTypes), end(supportedTypes), neonOutputInfo.data_type()); |
| 38 | |
| 39 | if (it != end(supportedTypes)) |
| 40 | { |
| 41 | return arm_compute::Status{}; |
| 42 | } |
| 43 | else |
| 44 | { |
| 45 | return arm_compute::Status{arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported DataType"}; |
| 46 | } |
| 47 | } |
| 48 | |
Nattapat Chaimanowong | 233b3d6 | 2018-10-12 12:02:18 +0100 | [diff] [blame] | 49 | NeonConstantWorkload::NeonConstantWorkload(const ConstantQueueDescriptor& descriptor, |
| 50 | const WorkloadInfo& info) |
| 51 | : BaseWorkload<ConstantQueueDescriptor>(descriptor, info) |
| 52 | , m_RanOnce(false) |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | void NeonConstantWorkload::Execute() const |
| 57 | { |
| 58 | ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonConstantWorkload_Execute"); |
| 59 | |
| 60 | using namespace armcomputetensorutils; |
| 61 | |
| 62 | // The intermediate tensor held by the corresponding layer output handler can be initialised with the |
| 63 | // given data on the first inference, then reused for subsequent inferences. |
| 64 | // The initialisation cannot happen at workload construction time since the ACL kernel for the next layer |
| 65 | // may not have been configured at the time. |
| 66 | if (!m_RanOnce) |
| 67 | { |
| 68 | const ConstantQueueDescriptor& data = this->m_Data; |
| 69 | |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 70 | ARMNN_ASSERT(data.m_LayerOutput != nullptr); |
Nattapat Chaimanowong | 233b3d6 | 2018-10-12 12:02:18 +0100 | [diff] [blame] | 71 | arm_compute::ITensor& output = |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 72 | PolymorphicDowncast<NeonTensorHandle*>(data.m_Outputs[0])->GetTensor(); |
Nattapat Chaimanowong | 233b3d6 | 2018-10-12 12:02:18 +0100 | [diff] [blame] | 73 | arm_compute::DataType computeDataType = |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 74 | PolymorphicDowncast<NeonTensorHandle*>(data.m_Outputs[0])->GetDataType(); |
Nattapat Chaimanowong | 233b3d6 | 2018-10-12 12:02:18 +0100 | [diff] [blame] | 75 | |
| 76 | switch (computeDataType) |
| 77 | { |
Narumol Prangnawarat | 250d392 | 2020-03-30 16:11:04 +0100 | [diff] [blame] | 78 | case arm_compute::DataType::BFLOAT16: |
| 79 | { |
| 80 | CopyArmComputeITensorData(data.m_LayerOutput->GetConstTensor<BFloat16>(), output); |
| 81 | break; |
| 82 | } |
Nattapat Chaimanowong | 233b3d6 | 2018-10-12 12:02:18 +0100 | [diff] [blame] | 83 | case arm_compute::DataType::F16: |
| 84 | { |
| 85 | CopyArmComputeITensorData(data.m_LayerOutput->GetConstTensor<Half>(), output); |
| 86 | break; |
| 87 | } |
| 88 | case arm_compute::DataType::F32: |
| 89 | { |
| 90 | CopyArmComputeITensorData(data.m_LayerOutput->GetConstTensor<float>(), output); |
| 91 | break; |
| 92 | } |
| 93 | case arm_compute::DataType::QASYMM8: |
| 94 | { |
| 95 | CopyArmComputeITensorData(data.m_LayerOutput->GetConstTensor<uint8_t>(), output); |
| 96 | break; |
| 97 | } |
Mike Kelly | 0886ac4 | 2020-04-27 09:55:40 +0100 | [diff] [blame] | 98 | case arm_compute::DataType::QASYMM8_SIGNED: |
| 99 | { |
| 100 | CopyArmComputeITensorData(data.m_LayerOutput->GetConstTensor<int8_t>(), output); |
| 101 | break; |
| 102 | } |
| 103 | case arm_compute::DataType::QSYMM16: |
| 104 | { |
| 105 | CopyArmComputeITensorData(data.m_LayerOutput->GetConstTensor<int16_t>(), output); |
| 106 | break; |
| 107 | } |
| 108 | case arm_compute::DataType::QSYMM8: |
| 109 | case arm_compute::DataType::QSYMM8_PER_CHANNEL: |
| 110 | { |
| 111 | CopyArmComputeITensorData(data.m_LayerOutput->GetConstTensor<int8_t>(), output); |
| 112 | break; |
| 113 | } |
Teresa Charlin | f540eb8 | 2020-04-10 19:24:55 +0100 | [diff] [blame] | 114 | case arm_compute::DataType::S32: |
| 115 | { |
| 116 | CopyArmComputeITensorData(data.m_LayerOutput->GetConstTensor<int32_t>(), output); |
| 117 | break; |
| 118 | } |
Nattapat Chaimanowong | 233b3d6 | 2018-10-12 12:02:18 +0100 | [diff] [blame] | 119 | default: |
| 120 | { |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 121 | ARMNN_ASSERT_MSG(false, "Unknown data type"); |
Nattapat Chaimanowong | 233b3d6 | 2018-10-12 12:02:18 +0100 | [diff] [blame] | 122 | break; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | m_RanOnce = true; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | } //namespace armnn |