telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. 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 | |
| 6 | #pragma once |
| 7 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 8 | #include <arm_compute/core/Types.h> |
David Beck | 711fa31 | 2018-09-24 10:46:38 +0100 | [diff] [blame] | 9 | #include <backends/aclCommon/ArmComputeTensorUtils.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 10 | #include <backends/CpuTensorHandle.hpp> |
| 11 | #include <backends/NeonTensorHandle.hpp> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 12 | #include <backends/NeonWorkloadUtils.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 13 | #include <backends/Workload.hpp> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 14 | #include <Half.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 15 | |
| 16 | #include <boost/cast.hpp> |
| 17 | |
| 18 | namespace armnn |
| 19 | { |
| 20 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 21 | // Base class template providing an implementation of the Constant layer common to all data types. |
| 22 | template <armnn::DataType... DataFormats> |
| 23 | class NeonBaseConstantWorkload : public TypedWorkload<ConstantQueueDescriptor, DataFormats...> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 24 | { |
| 25 | public: |
| 26 | NeonBaseConstantWorkload(const ConstantQueueDescriptor& descriptor, const WorkloadInfo& info) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 27 | : TypedWorkload<ConstantQueueDescriptor, DataFormats...>(descriptor, info) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 28 | , m_RanOnce(false) |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | virtual void Execute() const override |
| 33 | { |
| 34 | using namespace armcomputetensorutils; |
| 35 | |
| 36 | // The intermediate tensor held by the corresponding layer output handler can be initialised with the |
| 37 | // given data on the first inference, then reused for subsequent inferences. |
| 38 | // The initialisation cannot happen at workload construction time since the ACL kernel for the next layer |
| 39 | // may not have been configured at the time. |
| 40 | if (!m_RanOnce) |
| 41 | { |
| 42 | const ConstantQueueDescriptor& data = this->m_Data; |
| 43 | |
| 44 | BOOST_ASSERT(data.m_LayerOutput != nullptr); |
| 45 | arm_compute::ITensor& output = |
| 46 | boost::polymorphic_downcast<NeonTensorHandle*>(data.m_Outputs[0])->GetTensor(); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 47 | arm_compute::DataType computeDataType = |
| 48 | boost::polymorphic_downcast<NeonTensorHandle*>(data.m_Outputs[0])->GetDataType(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 49 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 50 | switch (computeDataType) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 51 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 52 | case arm_compute::DataType::F16: |
| 53 | { |
| 54 | CopyArmComputeITensorData(data.m_LayerOutput->GetConstTensor<Half>(), output); |
| 55 | break; |
| 56 | } |
| 57 | case arm_compute::DataType::F32: |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 58 | { |
| 59 | CopyArmComputeITensorData(data.m_LayerOutput->GetConstTensor<float>(), output); |
| 60 | break; |
| 61 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 62 | case arm_compute::DataType::QASYMM8: |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 63 | { |
| 64 | CopyArmComputeITensorData(data.m_LayerOutput->GetConstTensor<uint8_t>(), output); |
| 65 | break; |
| 66 | } |
| 67 | default: |
| 68 | { |
| 69 | BOOST_ASSERT_MSG(false, "Unknown data type"); |
| 70 | break; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | m_RanOnce = true; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | private: |
| 79 | mutable bool m_RanOnce; |
| 80 | }; |
| 81 | |
| 82 | } //namespace armnn |