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