ArmNN
 24.02
MemCopyWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include <ResolveType.hpp>
7 
8 #include "WorkloadUtils.hpp"
9 
12 
14 
15 #include <cstring>
16 
17 namespace armnn
18 {
19 
20 namespace
21 {
22 
23 template <typename SrcTensorHandleType, typename DstTensorHandleType>
24 void GatherTensorHandlePairs(const MemCopyQueueDescriptor& descriptor,
25  std::vector<std::pair<SrcTensorHandleType*, DstTensorHandleType*>>& tensorHandlePairs)
26 {
27  const unsigned int numInputs = static_cast<unsigned int>(descriptor.m_Inputs.size());
28  tensorHandlePairs.reserve(numInputs);
29 
30  for (unsigned int i = 0; i < numInputs; ++i)
31  {
32  SrcTensorHandleType* const srcTensorHandle = PolymorphicDowncast<SrcTensorHandleType*>(
33  descriptor.m_Inputs[i]);
34  DstTensorHandleType* const dstTensorHandle = PolymorphicDowncast<DstTensorHandleType*>(
35  descriptor.m_Outputs[i]);
36 
37  tensorHandlePairs.emplace_back(srcTensorHandle, dstTensorHandle);
38  }
39 }
40 
41 } //namespace
42 
43 
45  const WorkloadInfo& info)
47 {
48  GatherTensorHandlePairs(descriptor, m_TensorHandlePairs);
49 }
50 
52 {
53  ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "CopyMemGeneric_Execute");
54 
55  auto copyFunc = [](void* dst, const void* src, size_t size)
56  {
57  memcpy(dst, src, size);
58  };
59 
60  for (const auto& pair : m_TensorHandlePairs)
61  {
62  CopyTensorContentsGeneric(pair.first, pair.second, copyFunc);
63  }
64 }
65 
67 {
68  ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "CopyMemGeneric_Execute_WorkingMemDescriptor");
69 
70  WorkingMemDescriptor* workingMemDescriptor = static_cast<WorkingMemDescriptor*>(executionData.m_Data);
71  std::vector<TensorHandlePair> tensorHandlePairs;
72 
73  GatherTensorHandlePairs(*workingMemDescriptor, tensorHandlePairs);
74 
75  auto copyFunc = [](void* dst, const void* src, size_t size)
76  {
77  memcpy(dst, src, size);
78  };
79 
80  for (const auto& pair : tensorHandlePairs)
81  {
82  CopyTensorContentsGeneric(pair.first, pair.second, copyFunc);
83  }
84 }
85 
86 } //namespace armnn
armnn::Compute::Undefined
@ Undefined
WorkloadUtils.hpp
armnn::experimental::ExecutionData::m_Data
void * m_Data
Definition: ExecutionData.hpp:16
armnn::CopyMemGenericWorkload::ExecuteAsync
void ExecuteAsync(ExecutionData &executionData) override
Definition: MemCopyWorkload.cpp:66
ResolveType.hpp
ARMNN_SCOPED_PROFILING_EVENT
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
Definition: Profiling.hpp:220
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
PolymorphicDowncast.hpp
armnn::GatherTensorHandlePairs
void GatherTensorHandlePairs(const DescriptorType &descriptor, std::vector< std::pair< SrcTensorHandleType *, DstTensorHandleType * >> &tensorHandlePairs)
Definition: WorkloadUtils.hpp:204
armnn::BoostLogSeverityMapping::info
@ info
armnn::CopyTensorContentsGeneric
void CopyTensorContentsGeneric(const ITensorHandle *srcTensor, ITensorHandle *dstTensor, CopyFunc copy)
Definition: WorkloadUtils.hpp:46
armnn::MemCopyQueueDescriptor
Definition: WorkloadData.hpp:86
armnn::BaseWorkload
Definition: Workload.hpp:33
TensorHandle.hpp
MemCopyWorkload.hpp
armnn::CopyMemGenericWorkload::CopyMemGenericWorkload
CopyMemGenericWorkload(const MemCopyQueueDescriptor &descriptor, const WorkloadInfo &info)
Definition: MemCopyWorkload.cpp:44
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::experimental::WorkingMemDescriptor
Definition: WorkingMemDescriptor.hpp:18
armnn::CopyMemGenericWorkload::Execute
void Execute() const override
Definition: MemCopyWorkload.cpp:51
armnn::experimental::ExecutionData
Definition: ExecutionData.hpp:14