blob: a10237cf409e3ddad7ce1ac425fcdda6fd676a64 [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//
5#pragma once
6
Matthew Bentham14e46692018-09-20 15:35:30 +01007#include "OpenClTimer.hpp"
Matthew Bentham14e46692018-09-20 15:35:30 +01008#include "backends/ArmComputeTensorUtils.hpp"
9#include "backends/CpuTensorHandle.hpp"
10
Matthew Bentham14e46692018-09-20 15:35:30 +010011#include <Half.hpp>
telsoa01c577f2c2018-08-31 09:22:23 +010012
13#define ARMNN_SCOPED_PROFILING_EVENT_CL(name) \
14 ARMNN_SCOPED_PROFILING_EVENT_WITH_INSTRUMENTS(armnn::Compute::GpuAcc, \
15 name, \
16 armnn::OpenClTimer(), \
17 armnn::WallClockTimer())
telsoa014fcda012018-03-09 14:13:49 +000018
19namespace armnn
20{
21
22template <typename T>
23void CopyArmComputeClTensorData(const T* srcData, arm_compute::CLTensor& dstTensor)
24{
25 {
telsoa01c577f2c2018-08-31 09:22:23 +010026 ARMNN_SCOPED_PROFILING_EVENT_CL("MapClTensorForWriting");
telsoa014fcda012018-03-09 14:13:49 +000027 dstTensor.map(true);
28 }
29
30 {
telsoa01c577f2c2018-08-31 09:22:23 +010031 ARMNN_SCOPED_PROFILING_EVENT_CL("CopyToClTensor");
telsoa014fcda012018-03-09 14:13:49 +000032 armcomputetensorutils::CopyArmComputeITensorData<T>(srcData, dstTensor);
33 }
34
35 dstTensor.unmap();
36}
37
38template <typename T>
39void InitialiseArmComputeClTensorData(arm_compute::CLTensor& clTensor, const T* data)
40{
41 armcomputetensorutils::InitialiseArmComputeTensorEmpty(clTensor);
42 CopyArmComputeClTensorData<T>(data, clTensor);
43}
44
Matthew Bentham785df502018-09-21 10:29:58 +010045inline void InitializeArmComputeClTensorData(arm_compute::CLTensor& clTensor,
46 const ConstCpuTensorHandle* handle)
telsoa01c577f2c2018-08-31 09:22:23 +010047{
48 BOOST_ASSERT(handle);
49 switch(handle->GetTensorInfo().GetDataType())
50 {
51 case DataType::Float16:
52 InitialiseArmComputeClTensorData(clTensor, handle->GetConstTensor<armnn::Half>());
53 break;
54 case DataType::Float32:
55 InitialiseArmComputeClTensorData(clTensor, handle->GetConstTensor<float>());
56 break;
Matthew Bentham785df502018-09-21 10:29:58 +010057 case DataType::QuantisedAsymm8:
58 InitialiseArmComputeClTensorData(clTensor, handle->GetConstTensor<uint8_t>());
59 break;
60 case DataType::Signed32:
61 InitialiseArmComputeClTensorData(clTensor, handle->GetConstTensor<int32_t>());
62 break;
telsoa01c577f2c2018-08-31 09:22:23 +010063 default:
Matthew Bentham785df502018-09-21 10:29:58 +010064 BOOST_ASSERT_MSG(false, "Unexpected tensor type.");
telsoa01c577f2c2018-08-31 09:22:23 +010065 }
66};
67
telsoa014fcda012018-03-09 14:13:49 +000068} //namespace armnn