blob: 7bdc05e4a23a1bdc335276e4579621b3845fc2e4 [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
telsoa014fcda012018-03-09 14:13:49 +00002// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +00005
Aron Virginas-Tard4f0fea2019-04-09 14:08:06 +01006#include <ResolveType.hpp>
telsoa014fcda012018-03-09 14:13:49 +00007
Matteo Martincighe5b8eb92019-11-28 15:45:42 +00008#include <backendsCommon/MemCopyWorkload.hpp>
9#include <backendsCommon/CpuTensorHandle.hpp>
10
Jan Eilersbb446e52020-04-02 13:56:54 +010011#include <armnn/utility/PolymorphicDowncast.hpp>
telsoa014fcda012018-03-09 14:13:49 +000012
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000013#include <cstring>
14
telsoa014fcda012018-03-09 14:13:49 +000015namespace armnn
16{
17
18namespace
19{
20
21template <typename SrcTensorHandleType, typename DstTensorHandleType>
22void GatherTensorHandlePairs(const MemCopyQueueDescriptor& descriptor,
23 std::vector<std::pair<SrcTensorHandleType*, DstTensorHandleType*>>& tensorHandlePairs)
24{
telsoa01c577f2c2018-08-31 09:22:23 +010025 const unsigned int numInputs = static_cast<unsigned int>(descriptor.m_Inputs.size());
telsoa014fcda012018-03-09 14:13:49 +000026 tensorHandlePairs.reserve(numInputs);
27
28 for (unsigned int i = 0; i < numInputs; ++i)
29 {
Jan Eilersbb446e52020-04-02 13:56:54 +010030 SrcTensorHandleType* const srcTensorHandle = PolymorphicDowncast<SrcTensorHandleType*>(
telsoa014fcda012018-03-09 14:13:49 +000031 descriptor.m_Inputs[i]);
Jan Eilersbb446e52020-04-02 13:56:54 +010032 DstTensorHandleType* const dstTensorHandle = PolymorphicDowncast<DstTensorHandleType*>(
telsoa014fcda012018-03-09 14:13:49 +000033 descriptor.m_Outputs[i]);
34
35 tensorHandlePairs.emplace_back(srcTensorHandle, dstTensorHandle);
36 }
37}
38
telsoa01c577f2c2018-08-31 09:22:23 +010039} //namespace
telsoa014fcda012018-03-09 14:13:49 +000040
telsoa014fcda012018-03-09 14:13:49 +000041
telsoa01c577f2c2018-08-31 09:22:23 +010042CopyMemGenericWorkload::CopyMemGenericWorkload(const MemCopyQueueDescriptor& descriptor,
43 const WorkloadInfo& info)
44 : BaseWorkload<MemCopyQueueDescriptor>(descriptor, info)
telsoa014fcda012018-03-09 14:13:49 +000045{
46 GatherTensorHandlePairs(descriptor, m_TensorHandlePairs);
47}
48
telsoa01c577f2c2018-08-31 09:22:23 +010049void CopyMemGenericWorkload::Execute() const
telsoa014fcda012018-03-09 14:13:49 +000050{
telsoa01c577f2c2018-08-31 09:22:23 +010051 ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "CopyMemGeneric_Execute");
52
53 auto copyFunc = [](void* dst, const void* src, size_t size)
54 {
55 memcpy(dst, src, size);
56 };
telsoa014fcda012018-03-09 14:13:49 +000057
58 for (const auto& pair : m_TensorHandlePairs)
59 {
telsoa01c577f2c2018-08-31 09:22:23 +010060 CopyTensorContentsGeneric(pair.first, pair.second, copyFunc);
telsoa014fcda012018-03-09 14:13:49 +000061 }
62}
63
telsoa01c577f2c2018-08-31 09:22:23 +010064} //namespace armnn