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 | |
Nattapat Chaimanowong | 55b1cda | 2018-10-10 14:51:27 +0100 | [diff] [blame] | 6 | #include "ClConstantWorkload.hpp" |
arovir01 | 616e775 | 2018-10-01 17:08:59 +0100 | [diff] [blame] | 7 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 8 | #include <Half.hpp> |
| 9 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
| 10 | #include <cl/ClTensorHandle.hpp> |
| 11 | #include <backendsCommon/CpuTensorHandle.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 12 | |
Matthew Bentham | 14e4669 | 2018-09-20 15:35:30 +0100 | [diff] [blame] | 13 | #include "ClWorkloadUtils.hpp" |
| 14 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 15 | namespace armnn |
| 16 | { |
| 17 | |
Nattapat Chaimanowong | 55b1cda | 2018-10-10 14:51:27 +0100 | [diff] [blame] | 18 | ClConstantWorkload::ClConstantWorkload(const ConstantQueueDescriptor& descriptor, const WorkloadInfo& info) |
| 19 | : BaseWorkload<ConstantQueueDescriptor>(descriptor, info) |
| 20 | , m_RanOnce(false) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 21 | { |
Nattapat Chaimanowong | 55b1cda | 2018-10-10 14:51:27 +0100 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | void ClConstantWorkload::Execute() const |
| 25 | { |
| 26 | ARMNN_SCOPED_PROFILING_EVENT_CL("ClConstantWorkload_Execute"); |
| 27 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 28 | // The intermediate tensor held by the corresponding layer output handler can be initialised with the given data |
| 29 | // on the first inference, then reused for subsequent inferences. |
| 30 | // The initialisation cannot happen at workload construction time since the ACL kernel for the next layer may not |
| 31 | // have been configured at the time. |
| 32 | if (!m_RanOnce) |
| 33 | { |
| 34 | const ConstantQueueDescriptor& data = this->m_Data; |
| 35 | |
| 36 | BOOST_ASSERT(data.m_LayerOutput != nullptr); |
| 37 | arm_compute::CLTensor& output = static_cast<ClTensorHandle*>(data.m_Outputs[0])->GetTensor(); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 38 | arm_compute::DataType computeDataType = static_cast<ClTensorHandle*>(data.m_Outputs[0])->GetDataType(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 39 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 40 | switch (computeDataType) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 41 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 42 | case arm_compute::DataType::F16: |
| 43 | { |
Matthew Bentham | ca6616c | 2018-09-21 15:16:53 +0100 | [diff] [blame] | 44 | CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<Half>()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 45 | break; |
| 46 | } |
| 47 | case arm_compute::DataType::F32: |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 48 | { |
Matthew Bentham | ca6616c | 2018-09-21 15:16:53 +0100 | [diff] [blame] | 49 | CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<float>()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 50 | break; |
| 51 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 52 | case arm_compute::DataType::QASYMM8: |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 53 | { |
Matthew Bentham | ca6616c | 2018-09-21 15:16:53 +0100 | [diff] [blame] | 54 | CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<uint8_t>()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 55 | break; |
| 56 | } |
| 57 | default: |
| 58 | { |
| 59 | BOOST_ASSERT_MSG(false, "Unknown data type"); |
| 60 | break; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | m_RanOnce = true; |
| 65 | } |
| 66 | } |
| 67 | |
Matthew Bentham | 14e4669 | 2018-09-20 15:35:30 +0100 | [diff] [blame] | 68 | } //namespace armnn |