Laurent Carlier | 749294b | 2020-06-01 09:03:17 +0100 | [diff] [blame] | 1 | // |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | #pragma once |
| 6 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 7 | #include <backendsCommon/Workload.hpp> |
| 8 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
| 9 | #include <neon/NeonTensorHandle.hpp> |
| 10 | #include <neon/NeonTimer.hpp> |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 11 | #include <backendsCommon/TensorHandle.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 12 | |
Derek Lamberti | d466a54 | 2020-01-22 15:37:29 +0000 | [diff] [blame] | 13 | #include <armnn/Utils.hpp> |
| 14 | |
Nattapat Chaimanowong | 177d8d2 | 2018-10-16 13:21:27 +0100 | [diff] [blame] | 15 | #include <Half.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 16 | |
Nattapat Chaimanowong | 177d8d2 | 2018-10-16 13:21:27 +0100 | [diff] [blame] | 17 | #define ARMNN_SCOPED_PROFILING_EVENT_NEON(name) \ |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 18 | ARMNN_SCOPED_PROFILING_EVENT_WITH_INSTRUMENTS(armnn::Compute::CpuAcc, \ |
Keith Davis | 5a64f22 | 2021-08-04 10:35:20 +0100 | [diff] [blame] | 19 | armnn::EmptyOptional(), \ |
| 20 | name, \ |
| 21 | armnn::NeonTimer(), \ |
| 22 | armnn::WallClockTimer()) |
| 23 | |
| 24 | #define ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID(name, guid) \ |
| 25 | ARMNN_SCOPED_PROFILING_EVENT_WITH_INSTRUMENTS(armnn::Compute::CpuAcc, \ |
| 26 | guid, \ |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 27 | name, \ |
Nina Drozd | 69851b5 | 2018-09-21 18:42:09 +0100 | [diff] [blame] | 28 | armnn::NeonTimer(), \ |
| 29 | armnn::WallClockTimer()) |
Nattapat Chaimanowong | 177d8d2 | 2018-10-16 13:21:27 +0100 | [diff] [blame] | 30 | |
| 31 | using namespace armnn::armcomputetensorutils; |
| 32 | |
| 33 | namespace armnn |
| 34 | { |
| 35 | |
Keith Davis | 5a64f22 | 2021-08-04 10:35:20 +0100 | [diff] [blame] | 36 | inline std::string GetConvolutionMethodString(arm_compute::ConvolutionMethod& convolutionMethod) |
| 37 | { |
| 38 | switch (convolutionMethod) |
| 39 | { |
| 40 | case arm_compute::ConvolutionMethod::FFT: |
| 41 | return "FFT"; |
| 42 | case arm_compute::ConvolutionMethod::DIRECT: |
| 43 | return "Direct"; |
| 44 | case arm_compute::ConvolutionMethod::GEMM: |
| 45 | return "GEMM"; |
| 46 | case arm_compute::ConvolutionMethod::WINOGRAD: |
| 47 | return "Winograd"; |
| 48 | default: |
| 49 | return "Unknown"; |
| 50 | } |
| 51 | } |
| 52 | |
Nattapat Chaimanowong | 177d8d2 | 2018-10-16 13:21:27 +0100 | [diff] [blame] | 53 | template <typename T> |
| 54 | void CopyArmComputeTensorData(arm_compute::Tensor& dstTensor, const T* srcData) |
| 55 | { |
| 56 | InitialiseArmComputeTensorEmpty(dstTensor); |
| 57 | CopyArmComputeITensorData(srcData, dstTensor); |
| 58 | } |
| 59 | |
| 60 | inline void InitializeArmComputeTensorData(arm_compute::Tensor& tensor, |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 61 | const ConstTensorHandle* handle) |
Nattapat Chaimanowong | 177d8d2 | 2018-10-16 13:21:27 +0100 | [diff] [blame] | 62 | { |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 63 | ARMNN_ASSERT(handle); |
Nattapat Chaimanowong | 177d8d2 | 2018-10-16 13:21:27 +0100 | [diff] [blame] | 64 | |
| 65 | switch(handle->GetTensorInfo().GetDataType()) |
| 66 | { |
| 67 | case DataType::Float16: |
| 68 | CopyArmComputeTensorData(tensor, handle->GetConstTensor<armnn::Half>()); |
| 69 | break; |
| 70 | case DataType::Float32: |
| 71 | CopyArmComputeTensorData(tensor, handle->GetConstTensor<float>()); |
| 72 | break; |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 73 | case DataType::QAsymmU8: |
Nattapat Chaimanowong | 177d8d2 | 2018-10-16 13:21:27 +0100 | [diff] [blame] | 74 | CopyArmComputeTensorData(tensor, handle->GetConstTensor<uint8_t>()); |
| 75 | break; |
Derek Lamberti | d466a54 | 2020-01-22 15:37:29 +0000 | [diff] [blame] | 76 | ARMNN_NO_DEPRECATE_WARN_BEGIN |
Aron Virginas-Tar | 21fc28b | 2019-11-26 14:04:54 +0000 | [diff] [blame] | 77 | case DataType::QuantizedSymm8PerAxis: |
Derek Lamberti | d466a54 | 2020-01-22 15:37:29 +0000 | [diff] [blame] | 78 | ARMNN_FALLTHROUGH; |
| 79 | case DataType::QSymmS8: |
Sadik Armagan | e5d0b93 | 2020-04-09 15:48:44 +0100 | [diff] [blame] | 80 | case DataType::QAsymmS8: |
Aron Virginas-Tar | 21fc28b | 2019-11-26 14:04:54 +0000 | [diff] [blame] | 81 | CopyArmComputeTensorData(tensor, handle->GetConstTensor<int8_t>()); |
| 82 | break; |
Derek Lamberti | d466a54 | 2020-01-22 15:37:29 +0000 | [diff] [blame] | 83 | ARMNN_NO_DEPRECATE_WARN_END |
Nattapat Chaimanowong | 177d8d2 | 2018-10-16 13:21:27 +0100 | [diff] [blame] | 84 | case DataType::Signed32: |
| 85 | CopyArmComputeTensorData(tensor, handle->GetConstTensor<int32_t>()); |
| 86 | break; |
James Conroy | cc34093 | 2020-05-12 18:08:52 +0100 | [diff] [blame] | 87 | case DataType::QSymmS16: |
| 88 | CopyArmComputeTensorData(tensor, handle->GetConstTensor<int16_t>()); |
| 89 | break; |
Nattapat Chaimanowong | 177d8d2 | 2018-10-16 13:21:27 +0100 | [diff] [blame] | 90 | default: |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 91 | ARMNN_ASSERT_MSG(false, "Unexpected tensor type."); |
Nattapat Chaimanowong | 177d8d2 | 2018-10-16 13:21:27 +0100 | [diff] [blame] | 92 | } |
| 93 | }; |
| 94 | |
FinnWilliamsArm | 1fa1919 | 2019-08-02 17:26:31 +0100 | [diff] [blame] | 95 | inline auto SetNeonStridedSliceData(const std::vector<int>& m_begin, |
| 96 | const std::vector<int>& m_end, |
| 97 | const std::vector<int>& m_stride) |
| 98 | { |
| 99 | arm_compute::Coordinates starts; |
| 100 | arm_compute::Coordinates ends; |
| 101 | arm_compute::Coordinates strides; |
| 102 | |
| 103 | unsigned int num_dims = static_cast<unsigned int>(m_begin.size()); |
| 104 | |
| 105 | for (unsigned int i = 0; i < num_dims; i++) |
| 106 | { |
| 107 | unsigned int revertedIndex = num_dims - i - 1; |
| 108 | |
| 109 | starts.set(i, static_cast<int>(m_begin[revertedIndex])); |
| 110 | ends.set(i, static_cast<int>(m_end[revertedIndex])); |
| 111 | strides.set(i, static_cast<int>(m_stride[revertedIndex])); |
| 112 | } |
| 113 | |
| 114 | return std::make_tuple(starts, ends, strides); |
| 115 | } |
| 116 | |
josh minor | 036f02d | 2019-11-15 14:53:22 -0600 | [diff] [blame] | 117 | inline auto SetNeonSliceData(const std::vector<unsigned int>& m_begin, |
| 118 | const std::vector<unsigned int>& m_size) |
| 119 | { |
| 120 | // This function must translate the size vector given to an end vector |
| 121 | // expected by the ACL NESlice workload |
| 122 | arm_compute::Coordinates starts; |
| 123 | arm_compute::Coordinates ends; |
| 124 | |
| 125 | unsigned int num_dims = static_cast<unsigned int>(m_begin.size()); |
| 126 | |
| 127 | // For strided slices, we have the relationship size = (end - begin) / stride |
| 128 | // For slice, we assume stride to be a vector of all ones, yielding the formula |
| 129 | // size = (end - begin) therefore we know end = size + begin |
| 130 | for (unsigned int i = 0; i < num_dims; i++) |
| 131 | { |
| 132 | unsigned int revertedIndex = num_dims - i - 1; |
| 133 | |
| 134 | starts.set(i, static_cast<int>(m_begin[revertedIndex])); |
| 135 | ends.set(i, static_cast<int>(m_begin[revertedIndex] + m_size[revertedIndex])); |
| 136 | } |
| 137 | |
| 138 | return std::make_tuple(starts, ends); |
| 139 | } |
| 140 | |
David Monahan | 97451b4 | 2020-12-03 09:48:06 +0000 | [diff] [blame] | 141 | template <typename DataType, typename PayloadType> |
| 142 | DataType* GetOutputTensorData(unsigned int idx, const PayloadType& data) |
| 143 | { |
| 144 | ITensorHandle* tensorHandle = data.m_Outputs[idx]; |
| 145 | return reinterpret_cast<DataType*>(tensorHandle->Map()); |
| 146 | } |
| 147 | |
Nattapat Chaimanowong | 177d8d2 | 2018-10-16 13:21:27 +0100 | [diff] [blame] | 148 | } //namespace armnn |