blob: e074c6fb04183db792e77e9b1f13a1054b743252 [file] [log] [blame]
narpra01db2b1602019-01-23 15:23:11 +00001//
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//
5
narpra01db2b1602019-01-23 15:23:11 +00006#include "RefConstantWorkload.hpp"
telsoa014fcda012018-03-09 14:13:49 +00007
8#include "RefWorkloadUtils.hpp"
9
10#include <armnn/Types.hpp>
11
12#include <boost/assert.hpp>
13
14#include <cstring>
15
16namespace armnn
17{
18
19template <armnn::DataType DataType>
narpra01db2b1602019-01-23 15:23:11 +000020void RefConstantWorkload<DataType>::Execute() const
telsoa014fcda012018-03-09 14:13:49 +000021{
22 // Considering the reference backend independently, it could be possible to initialise the intermediate tensor
23 // created by the layer output handler at workload construction time, rather than at workload execution time.
24 // However, this is not an option for other backends (e.g. CL). For consistency, we prefer to align all
25 // implementations.
26 // A similar argument can be made about performing the memory copy in the first place (the layer output handler
27 // could have a non-owning reference to the layer output tensor managed by the const input layer); again, this is
28 // not an option for other backends, and the extra complexity required to make this work for the reference backend
29 // may not be worth the effort (skipping a memory copy in the first inference).
narpra01db2b1602019-01-23 15:23:11 +000030 ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefConstantWorkload_Execute");
31
telsoa014fcda012018-03-09 14:13:49 +000032 if (!m_RanOnce)
33 {
34 const ConstantQueueDescriptor& data = this->m_Data;
35
36 BOOST_ASSERT(data.m_LayerOutput != nullptr);
37
38 const TensorInfo& outputInfo = GetTensorInfo(data.m_Outputs[0]);
39 BOOST_ASSERT(data.m_LayerOutput->GetTensorInfo().GetNumBytes() == outputInfo.GetNumBytes());
40
41 memcpy(GetOutputTensorData<void>(0, data), data.m_LayerOutput->GetConstTensor<void>(),
42 outputInfo.GetNumBytes());
43
44 m_RanOnce = true;
45 }
46}
47
narpra01db2b1602019-01-23 15:23:11 +000048template class RefConstantWorkload<DataType::Float32>;
49template class RefConstantWorkload<DataType::QuantisedAsymm8>;
50template class RefConstantWorkload<DataType::Signed32>;
telsoa014fcda012018-03-09 14:13:49 +000051
52} //namespace armnn