ArmNN
 20.02
NeonWorkloadUtils.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
10 #include <neon/NeonTimer.hpp>
12 
13 #include <armnn/Utils.hpp>
14 
15 #include <Half.hpp>
16 
17 #define ARMNN_SCOPED_PROFILING_EVENT_NEON(name) \
18  ARMNN_SCOPED_PROFILING_EVENT_WITH_INSTRUMENTS(armnn::Compute::CpuAcc, \
19  name, \
20  armnn::NeonTimer(), \
21  armnn::WallClockTimer())
22 
23 using namespace armnn::armcomputetensorutils;
24 
25 namespace armnn
26 {
27 
28 template <typename T>
29 void CopyArmComputeTensorData(arm_compute::Tensor& dstTensor, const T* srcData)
30 {
31  InitialiseArmComputeTensorEmpty(dstTensor);
32  CopyArmComputeITensorData(srcData, dstTensor);
33 }
34 
35 inline void InitializeArmComputeTensorData(arm_compute::Tensor& tensor,
36  const ConstCpuTensorHandle* handle)
37 {
38  BOOST_ASSERT(handle);
39 
40  switch(handle->GetTensorInfo().GetDataType())
41  {
42  case DataType::Float16:
44  break;
45  case DataType::Float32:
46  CopyArmComputeTensorData(tensor, handle->GetConstTensor<float>());
47  break;
48  case DataType::QAsymmU8:
49  CopyArmComputeTensorData(tensor, handle->GetConstTensor<uint8_t>());
50  break;
54  case DataType::QSymmS8:
55  CopyArmComputeTensorData(tensor, handle->GetConstTensor<int8_t>());
56  break;
58  case DataType::Signed32:
59  CopyArmComputeTensorData(tensor, handle->GetConstTensor<int32_t>());
60  break;
61  default:
62  BOOST_ASSERT_MSG(false, "Unexpected tensor type.");
63  }
64 };
65 
66 inline auto SetNeonStridedSliceData(const std::vector<int>& m_begin,
67  const std::vector<int>& m_end,
68  const std::vector<int>& m_stride)
69 {
73 
74  unsigned int num_dims = static_cast<unsigned int>(m_begin.size());
75 
76  for (unsigned int i = 0; i < num_dims; i++)
77  {
78  unsigned int revertedIndex = num_dims - i - 1;
79 
80  starts.set(i, static_cast<int>(m_begin[revertedIndex]));
81  ends.set(i, static_cast<int>(m_end[revertedIndex]));
82  strides.set(i, static_cast<int>(m_stride[revertedIndex]));
83  }
84 
85  return std::make_tuple(starts, ends, strides);
86 }
87 
88 inline auto SetNeonSliceData(const std::vector<unsigned int>& m_begin,
89  const std::vector<unsigned int>& m_size)
90 {
91  // This function must translate the size vector given to an end vector
92  // expected by the ACL NESlice workload
95 
96  unsigned int num_dims = static_cast<unsigned int>(m_begin.size());
97 
98  // For strided slices, we have the relationship size = (end - begin) / stride
99  // For slice, we assume stride to be a vector of all ones, yielding the formula
100  // size = (end - begin) therefore we know end = size + begin
101  for (unsigned int i = 0; i < num_dims; i++)
102  {
103  unsigned int revertedIndex = num_dims - i - 1;
104 
105  starts.set(i, static_cast<int>(m_begin[revertedIndex]));
106  ends.set(i, static_cast<int>(m_begin[revertedIndex] + m_size[revertedIndex]));
107  }
108 
109  return std::make_tuple(starts, ends);
110 }
111 
112 } //namespace armnn
#define ARMNN_NO_DEPRECATE_WARN_BEGIN
Definition: Deprecated.hpp:33
std::array< unsigned int, MaxNumOfTensorDimensions > Coordinates
const T * GetConstTensor() const
Copyright (c) 2020 ARM Limited.
auto SetNeonStridedSliceData(const std::vector< int > &m_begin, const std::vector< int > &m_end, const std::vector< int > &m_stride)
#define ARMNN_NO_DEPRECATE_WARN_END
Definition: Deprecated.hpp:34
DataType GetDataType() const
Definition: Tensor.hpp:95
auto SetNeonSliceData(const std::vector< unsigned int > &m_begin, const std::vector< unsigned int > &m_size)
#define ARMNN_FALLTHROUGH
Definition: Utils.hpp:35
void InitializeArmComputeTensorData(arm_compute::Tensor &tensor, const ConstCpuTensorHandle *handle)
void CopyArmComputeTensorData(arm_compute::Tensor &dstTensor, const T *srcData)
half_float::half Half
Definition: Half.hpp:16
const TensorInfo & GetTensorInfo() const