2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
9 #include <aclCommon/ArmComputeTensorUtils.hpp>
10 #include <cl/OpenClTimer.hpp>
11 #include <backendsCommon/CpuTensorHandle.hpp>
13 #include <arm_compute/runtime/CL/CLFunctions.h>
17 #define ARMNN_SCOPED_PROFILING_EVENT_CL(name) \
18 ARMNN_SCOPED_PROFILING_EVENT_WITH_INSTRUMENTS(armnn::Compute::GpuAcc, \
20 armnn::OpenClTimer(), \
21 armnn::WallClockTimer())
27 void CopyArmComputeClTensorData(arm_compute::CLTensor& dstTensor, const T* srcData)
30 ARMNN_SCOPED_PROFILING_EVENT_CL("MapClTensorForWriting");
35 ARMNN_SCOPED_PROFILING_EVENT_CL("CopyToClTensor");
36 armcomputetensorutils::CopyArmComputeITensorData<T>(srcData, dstTensor);
42 inline void InitializeArmComputeClTensorData(arm_compute::CLTensor& clTensor,
43 const ConstCpuTensorHandle* handle)
47 armcomputetensorutils::InitialiseArmComputeTensorEmpty(clTensor);
48 switch(handle->GetTensorInfo().GetDataType())
50 case DataType::Float16:
51 CopyArmComputeClTensorData(clTensor, handle->GetConstTensor<armnn::Half>());
53 case DataType::Float32:
54 CopyArmComputeClTensorData(clTensor, handle->GetConstTensor<float>());
56 case DataType::QuantisedAsymm8:
57 CopyArmComputeClTensorData(clTensor, handle->GetConstTensor<uint8_t>());
59 case DataType::Signed32:
60 CopyArmComputeClTensorData(clTensor, handle->GetConstTensor<int32_t>());
63 BOOST_ASSERT_MSG(false, "Unexpected tensor type.");
67 inline RuntimeException WrapClError(const cl::Error& clError, const CheckLocation& location)
69 std::stringstream message;
70 message << "CL error: " << clError.what() << ". Error code: " << clError.err();
72 return RuntimeException(message.str(), location);
75 inline void RunClFunction(arm_compute::IFunction& function, const CheckLocation& location)
81 catch (cl::Error& error)
83 throw WrapClError(error, location);