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 | |
| 22 | NeonConstantWorkload::NeonConstantWorkload(const ConstantQueueDescriptor& descriptor, |
| 23 | const WorkloadInfo& info) |
| 24 | : BaseWorkload<ConstantQueueDescriptor>(descriptor, info) |
| 25 | , m_RanOnce(false) |
| 26 | { |
| 27 | } |
| 28 | |
| 29 | void NeonConstantWorkload::Execute() const |
| 30 | { |
| 31 | ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonConstantWorkload_Execute"); |
| 32 | |
| 33 | using namespace armcomputetensorutils; |
| 34 | |
| 35 | // The intermediate tensor held by the corresponding layer output handler can be initialised with the |
| 36 | // given data on the first inference, then reused for subsequent inferences. |
| 37 | // The initialisation cannot happen at workload construction time since the ACL kernel for the next layer |
| 38 | // may not have been configured at the time. |
| 39 | if (!m_RanOnce) |
| 40 | { |
| 41 | const ConstantQueueDescriptor& data = this->m_Data; |
| 42 | |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 43 | ARMNN_ASSERT(data.m_LayerOutput != nullptr); |
Nattapat Chaimanowong | 233b3d6 | 2018-10-12 12:02:18 +0100 | [diff] [blame] | 44 | arm_compute::ITensor& output = |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 45 | PolymorphicDowncast<NeonTensorHandle*>(data.m_Outputs[0])->GetTensor(); |
Nattapat Chaimanowong | 233b3d6 | 2018-10-12 12:02:18 +0100 | [diff] [blame] | 46 | arm_compute::DataType computeDataType = |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 47 | PolymorphicDowncast<NeonTensorHandle*>(data.m_Outputs[0])->GetDataType(); |
Nattapat Chaimanowong | 233b3d6 | 2018-10-12 12:02:18 +0100 | [diff] [blame] | 48 | |
| 49 | switch (computeDataType) |
| 50 | { |
Narumol Prangnawarat | 250d392 | 2020-03-30 16:11:04 +0100 | [diff] [blame] | 51 | case arm_compute::DataType::BFLOAT16: |
| 52 | { |
| 53 | CopyArmComputeITensorData(data.m_LayerOutput->GetConstTensor<BFloat16>(), output); |
| 54 | break; |
| 55 | } |
Nattapat Chaimanowong | 233b3d6 | 2018-10-12 12:02:18 +0100 | [diff] [blame] | 56 | case arm_compute::DataType::F16: |
| 57 | { |
| 58 | CopyArmComputeITensorData(data.m_LayerOutput->GetConstTensor<Half>(), output); |
| 59 | break; |
| 60 | } |
| 61 | case arm_compute::DataType::F32: |
| 62 | { |
| 63 | CopyArmComputeITensorData(data.m_LayerOutput->GetConstTensor<float>(), output); |
| 64 | break; |
| 65 | } |
| 66 | case arm_compute::DataType::QASYMM8: |
| 67 | { |
| 68 | CopyArmComputeITensorData(data.m_LayerOutput->GetConstTensor<uint8_t>(), output); |
| 69 | break; |
| 70 | } |
| 71 | default: |
| 72 | { |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 73 | ARMNN_ASSERT_MSG(false, "Unknown data type"); |
Nattapat Chaimanowong | 233b3d6 | 2018-10-12 12:02:18 +0100 | [diff] [blame] | 74 | break; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | m_RanOnce = true; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | } //namespace armnn |