Laurent Carlier | 749294b | 2020-06-01 09:03:17 +0100 | [diff] [blame] | 1 | // |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 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 | // |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 5 | |
Aron Virginas-Tar | d4f0fea | 2019-04-09 14:08:06 +0100 | [diff] [blame] | 6 | #include <ResolveType.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 7 | |
Matteo Martincigh | e5b8eb9 | 2019-11-28 15:45:42 +0000 | [diff] [blame] | 8 | #include <backendsCommon/MemCopyWorkload.hpp> |
| 9 | #include <backendsCommon/CpuTensorHandle.hpp> |
| 10 | |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 11 | #include <armnn/utility/PolymorphicDowncast.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 12 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 13 | #include <cstring> |
| 14 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 15 | namespace armnn |
| 16 | { |
| 17 | |
| 18 | namespace |
| 19 | { |
| 20 | |
| 21 | template <typename SrcTensorHandleType, typename DstTensorHandleType> |
| 22 | void GatherTensorHandlePairs(const MemCopyQueueDescriptor& descriptor, |
| 23 | std::vector<std::pair<SrcTensorHandleType*, DstTensorHandleType*>>& tensorHandlePairs) |
| 24 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 25 | const unsigned int numInputs = static_cast<unsigned int>(descriptor.m_Inputs.size()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 26 | tensorHandlePairs.reserve(numInputs); |
| 27 | |
| 28 | for (unsigned int i = 0; i < numInputs; ++i) |
| 29 | { |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 30 | SrcTensorHandleType* const srcTensorHandle = PolymorphicDowncast<SrcTensorHandleType*>( |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 31 | descriptor.m_Inputs[i]); |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 32 | DstTensorHandleType* const dstTensorHandle = PolymorphicDowncast<DstTensorHandleType*>( |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 33 | descriptor.m_Outputs[i]); |
| 34 | |
| 35 | tensorHandlePairs.emplace_back(srcTensorHandle, dstTensorHandle); |
| 36 | } |
| 37 | } |
| 38 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 39 | } //namespace |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 40 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 41 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 42 | CopyMemGenericWorkload::CopyMemGenericWorkload(const MemCopyQueueDescriptor& descriptor, |
| 43 | const WorkloadInfo& info) |
| 44 | : BaseWorkload<MemCopyQueueDescriptor>(descriptor, info) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 45 | { |
| 46 | GatherTensorHandlePairs(descriptor, m_TensorHandlePairs); |
| 47 | } |
| 48 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 49 | void CopyMemGenericWorkload::Execute() const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 50 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 51 | 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 | }; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 57 | |
| 58 | for (const auto& pair : m_TensorHandlePairs) |
| 59 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 60 | CopyTensorContentsGeneric(pair.first, pair.second, copyFunc); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 64 | } //namespace armnn |