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