diff options
author | Nattapat Chaimanowong <nattapat.chaimanowong@arm.com> | 2018-10-10 14:51:27 +0100 |
---|---|---|
committer | Matthew Bentham <matthew.bentham@arm.com> | 2018-10-22 16:57:53 +0100 |
commit | 55b1cda7d242ceb22963fd40370c2e6dbbb074ba (patch) | |
tree | 5005cb3411de2d2a3b10eeb785ca9da4b39f2a87 /src/backends/cl/workloads/ClConstantWorkload.cpp | |
parent | f1153cd864805ad2ed1197a9667e333dc38b8873 (diff) | |
download | armnn-55b1cda7d242ceb22963fd40370c2e6dbbb074ba.tar.gz |
IVGCVSW-1951 Remove type templating from ClConstantWorkload
Change-Id: Ib2c9fe56c59aedabeff899a81a0afe260bd57c9f
Diffstat (limited to 'src/backends/cl/workloads/ClConstantWorkload.cpp')
-rw-r--r-- | src/backends/cl/workloads/ClConstantWorkload.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/backends/cl/workloads/ClConstantWorkload.cpp b/src/backends/cl/workloads/ClConstantWorkload.cpp new file mode 100644 index 0000000000..eee6dbdd55 --- /dev/null +++ b/src/backends/cl/workloads/ClConstantWorkload.cpp @@ -0,0 +1,68 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "ClConstantWorkload.hpp" + +#include <armnnUtils/Half.hpp> +#include <backends/aclCommon/ArmComputeTensorUtils.hpp> +#include <backends/cl/ClTensorHandle.hpp> +#include <backends/CpuTensorHandle.hpp> + +#include "ClWorkloadUtils.hpp" + +namespace armnn +{ + +ClConstantWorkload::ClConstantWorkload(const ConstantQueueDescriptor& descriptor, const WorkloadInfo& info) + : BaseWorkload<ConstantQueueDescriptor>(descriptor, info) + , m_RanOnce(false) +{ +} + +void ClConstantWorkload::Execute() const +{ + ARMNN_SCOPED_PROFILING_EVENT_CL("ClConstantWorkload_Execute"); + + // The intermediate tensor held by the corresponding layer output handler can be initialised with the given data + // on the first inference, then reused for subsequent inferences. + // The initialisation cannot happen at workload construction time since the ACL kernel for the next layer may not + // have been configured at the time. + if (!m_RanOnce) + { + const ConstantQueueDescriptor& data = this->m_Data; + + BOOST_ASSERT(data.m_LayerOutput != nullptr); + arm_compute::CLTensor& output = static_cast<ClTensorHandle*>(data.m_Outputs[0])->GetTensor(); + arm_compute::DataType computeDataType = static_cast<ClTensorHandle*>(data.m_Outputs[0])->GetDataType(); + + switch (computeDataType) + { + case arm_compute::DataType::F16: + { + CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<Half>()); + break; + } + case arm_compute::DataType::F32: + { + CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<float>()); + break; + } + case arm_compute::DataType::QASYMM8: + { + CopyArmComputeClTensorData(output, data.m_LayerOutput->GetConstTensor<uint8_t>()); + break; + } + default: + { + BOOST_ASSERT_MSG(false, "Unknown data type"); + break; + } + } + + m_RanOnce = true; + } +} + +} //namespace armnn |