blob: 3a8ff00bb6ed8a567d471e24ad28327f09bc2d21 [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"
David Beck711fa312018-09-24 10:46:38 +01008#include <backends/aclCommon/ArmComputeTensorUtils.hpp>
9#include <backends/CpuTensorHandle.hpp>
Matthew Bentham14e46692018-09-20 15:35:30 +010010
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>
Matthew Benthamca6616c2018-09-21 15:16:53 +010023void CopyArmComputeClTensorData(arm_compute::CLTensor& dstTensor, const T* srcData)
telsoa014fcda012018-03-09 14:13:49 +000024{
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
Matthew Bentham785df502018-09-21 10:29:58 +010038inline void InitializeArmComputeClTensorData(arm_compute::CLTensor& clTensor,
39 const ConstCpuTensorHandle* handle)
telsoa01c577f2c2018-08-31 09:22:23 +010040{
41 BOOST_ASSERT(handle);
Matthew Benthamca6616c2018-09-21 15:16:53 +010042
43 armcomputetensorutils::InitialiseArmComputeTensorEmpty(clTensor);
telsoa01c577f2c2018-08-31 09:22:23 +010044 switch(handle->GetTensorInfo().GetDataType())
45 {
46 case DataType::Float16:
Matthew Benthamca6616c2018-09-21 15:16:53 +010047 CopyArmComputeClTensorData(clTensor, handle->GetConstTensor<armnn::Half>());
telsoa01c577f2c2018-08-31 09:22:23 +010048 break;
49 case DataType::Float32:
Matthew Benthamca6616c2018-09-21 15:16:53 +010050 CopyArmComputeClTensorData(clTensor, handle->GetConstTensor<float>());
telsoa01c577f2c2018-08-31 09:22:23 +010051 break;
Matthew Bentham785df502018-09-21 10:29:58 +010052 case DataType::QuantisedAsymm8:
Matthew Benthamca6616c2018-09-21 15:16:53 +010053 CopyArmComputeClTensorData(clTensor, handle->GetConstTensor<uint8_t>());
Matthew Bentham785df502018-09-21 10:29:58 +010054 break;
55 case DataType::Signed32:
Matthew Benthamca6616c2018-09-21 15:16:53 +010056 CopyArmComputeClTensorData(clTensor, handle->GetConstTensor<int32_t>());
Matthew Bentham785df502018-09-21 10:29:58 +010057 break;
telsoa01c577f2c2018-08-31 09:22:23 +010058 default:
Matthew Bentham785df502018-09-21 10:29:58 +010059 BOOST_ASSERT_MSG(false, "Unexpected tensor type.");
telsoa01c577f2c2018-08-31 09:22:23 +010060 }
61};
62
telsoa014fcda012018-03-09 14:13:49 +000063} //namespace armnn