blob: 0fa04f8f464e3cfc734221a473ddfe25b84280d2 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// 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
telsoa014fcda012018-03-09 14:13:49 +00006#include "MemCopyWorkload.hpp"
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +00007
David Beckac42efd2018-09-26 17:41:13 +01008#include "CpuTensorHandle.hpp"
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +00009
David Beckac42efd2018-09-26 17:41:13 +010010#include <TypeUtils.hpp>
telsoa014fcda012018-03-09 14:13:49 +000011
telsoa014fcda012018-03-09 14:13:49 +000012#include <boost/cast.hpp>
13
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000014#include <cstring>
15
telsoa014fcda012018-03-09 14:13:49 +000016namespace armnn
17{
18
19namespace
20{
21
22template <typename SrcTensorHandleType, typename DstTensorHandleType>
23void GatherTensorHandlePairs(const MemCopyQueueDescriptor& descriptor,
24 std::vector<std::pair<SrcTensorHandleType*, DstTensorHandleType*>>& tensorHandlePairs)
25{
telsoa01c577f2c2018-08-31 09:22:23 +010026 const unsigned int numInputs = static_cast<unsigned int>(descriptor.m_Inputs.size());
telsoa014fcda012018-03-09 14:13:49 +000027 tensorHandlePairs.reserve(numInputs);
28
29 for (unsigned int i = 0; i < numInputs; ++i)
30 {
31 SrcTensorHandleType* const srcTensorHandle = boost::polymorphic_downcast<SrcTensorHandleType*>(
32 descriptor.m_Inputs[i]);
33 DstTensorHandleType* const dstTensorHandle = boost::polymorphic_downcast<DstTensorHandleType*>(
34 descriptor.m_Outputs[i]);
35
36 tensorHandlePairs.emplace_back(srcTensorHandle, dstTensorHandle);
37 }
38}
39
telsoa01c577f2c2018-08-31 09:22:23 +010040} //namespace
telsoa014fcda012018-03-09 14:13:49 +000041
telsoa014fcda012018-03-09 14:13:49 +000042
telsoa01c577f2c2018-08-31 09:22:23 +010043CopyMemGenericWorkload::CopyMemGenericWorkload(const MemCopyQueueDescriptor& descriptor,
44 const WorkloadInfo& info)
45 : BaseWorkload<MemCopyQueueDescriptor>(descriptor, info)
telsoa014fcda012018-03-09 14:13:49 +000046{
47 GatherTensorHandlePairs(descriptor, m_TensorHandlePairs);
48}
49
telsoa01c577f2c2018-08-31 09:22:23 +010050void CopyMemGenericWorkload::Execute() const
telsoa014fcda012018-03-09 14:13:49 +000051{
telsoa01c577f2c2018-08-31 09:22:23 +010052 ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "CopyMemGeneric_Execute");
53
54 auto copyFunc = [](void* dst, const void* src, size_t size)
55 {
56 memcpy(dst, src, size);
57 };
telsoa014fcda012018-03-09 14:13:49 +000058
59 for (const auto& pair : m_TensorHandlePairs)
60 {
telsoa01c577f2c2018-08-31 09:22:23 +010061 CopyTensorContentsGeneric(pair.first, pair.second, copyFunc);
telsoa014fcda012018-03-09 14:13:49 +000062 }
63}
64
telsoa01c577f2c2018-08-31 09:22:23 +010065} //namespace armnn