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