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> |
| 11 | #include <backendsCommon/CpuTensorHandle.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, \ |
| 19 | name, \ |
Nina Drozd | 69851b5 | 2018-09-21 18:42:09 +0100 | [diff] [blame] | 20 | armnn::NeonTimer(), \ |
| 21 | armnn::WallClockTimer()) |
Nattapat Chaimanowong | 177d8d2 | 2018-10-16 13:21:27 +0100 | [diff] [blame] | 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 | { |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 38 | ARMNN_ASSERT(handle); |
Nattapat Chaimanowong | 177d8d2 | 2018-10-16 13:21:27 +0100 | [diff] [blame] | 39 | |
| 40 | switch(handle->GetTensorInfo().GetDataType()) |
| 41 | { |
| 42 | case DataType::Float16: |
| 43 | CopyArmComputeTensorData(tensor, handle->GetConstTensor<armnn::Half>()); |
| 44 | break; |
| 45 | case DataType::Float32: |
| 46 | CopyArmComputeTensorData(tensor, handle->GetConstTensor<float>()); |
| 47 | break; |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 48 | case DataType::QAsymmU8: |
Nattapat Chaimanowong | 177d8d2 | 2018-10-16 13:21:27 +0100 | [diff] [blame] | 49 | CopyArmComputeTensorData(tensor, handle->GetConstTensor<uint8_t>()); |
| 50 | break; |
Derek Lamberti | d466a54 | 2020-01-22 15:37:29 +0000 | [diff] [blame] | 51 | ARMNN_NO_DEPRECATE_WARN_BEGIN |
Aron Virginas-Tar | 21fc28b | 2019-11-26 14:04:54 +0000 | [diff] [blame] | 52 | case DataType::QuantizedSymm8PerAxis: |
Derek Lamberti | d466a54 | 2020-01-22 15:37:29 +0000 | [diff] [blame] | 53 | ARMNN_FALLTHROUGH; |
| 54 | case DataType::QSymmS8: |
Sadik Armagan | e5d0b93 | 2020-04-09 15:48:44 +0100 | [diff] [blame] | 55 | case DataType::QAsymmS8: |
Aron Virginas-Tar | 21fc28b | 2019-11-26 14:04:54 +0000 | [diff] [blame] | 56 | CopyArmComputeTensorData(tensor, handle->GetConstTensor<int8_t>()); |
| 57 | break; |
Derek Lamberti | d466a54 | 2020-01-22 15:37:29 +0000 | [diff] [blame] | 58 | ARMNN_NO_DEPRECATE_WARN_END |
Nattapat Chaimanowong | 177d8d2 | 2018-10-16 13:21:27 +0100 | [diff] [blame] | 59 | case DataType::Signed32: |
| 60 | CopyArmComputeTensorData(tensor, handle->GetConstTensor<int32_t>()); |
| 61 | break; |
James Conroy | cc34093 | 2020-05-12 18:08:52 +0100 | [diff] [blame] | 62 | case DataType::QSymmS16: |
| 63 | CopyArmComputeTensorData(tensor, handle->GetConstTensor<int16_t>()); |
| 64 | break; |
Nattapat Chaimanowong | 177d8d2 | 2018-10-16 13:21:27 +0100 | [diff] [blame] | 65 | default: |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 66 | ARMNN_ASSERT_MSG(false, "Unexpected tensor type."); |
Nattapat Chaimanowong | 177d8d2 | 2018-10-16 13:21:27 +0100 | [diff] [blame] | 67 | } |
| 68 | }; |
| 69 | |
FinnWilliamsArm | 1fa1919 | 2019-08-02 17:26:31 +0100 | [diff] [blame] | 70 | inline auto SetNeonStridedSliceData(const std::vector<int>& m_begin, |
| 71 | const std::vector<int>& m_end, |
| 72 | const std::vector<int>& m_stride) |
| 73 | { |
| 74 | arm_compute::Coordinates starts; |
| 75 | arm_compute::Coordinates ends; |
| 76 | arm_compute::Coordinates strides; |
| 77 | |
| 78 | unsigned int num_dims = static_cast<unsigned int>(m_begin.size()); |
| 79 | |
| 80 | for (unsigned int i = 0; i < num_dims; i++) |
| 81 | { |
| 82 | unsigned int revertedIndex = num_dims - i - 1; |
| 83 | |
| 84 | starts.set(i, static_cast<int>(m_begin[revertedIndex])); |
| 85 | ends.set(i, static_cast<int>(m_end[revertedIndex])); |
| 86 | strides.set(i, static_cast<int>(m_stride[revertedIndex])); |
| 87 | } |
| 88 | |
| 89 | return std::make_tuple(starts, ends, strides); |
| 90 | } |
| 91 | |
josh minor | 036f02d | 2019-11-15 14:53:22 -0600 | [diff] [blame] | 92 | inline auto SetNeonSliceData(const std::vector<unsigned int>& m_begin, |
| 93 | const std::vector<unsigned int>& m_size) |
| 94 | { |
| 95 | // This function must translate the size vector given to an end vector |
| 96 | // expected by the ACL NESlice workload |
| 97 | arm_compute::Coordinates starts; |
| 98 | arm_compute::Coordinates ends; |
| 99 | |
| 100 | unsigned int num_dims = static_cast<unsigned int>(m_begin.size()); |
| 101 | |
| 102 | // For strided slices, we have the relationship size = (end - begin) / stride |
| 103 | // For slice, we assume stride to be a vector of all ones, yielding the formula |
| 104 | // size = (end - begin) therefore we know end = size + begin |
| 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_begin[revertedIndex] + m_size[revertedIndex])); |
| 111 | } |
| 112 | |
| 113 | return std::make_tuple(starts, ends); |
| 114 | } |
| 115 | |
David Monahan | 97451b4 | 2020-12-03 09:48:06 +0000 | [diff] [blame] | 116 | template <typename DataType, typename PayloadType> |
| 117 | DataType* GetOutputTensorData(unsigned int idx, const PayloadType& data) |
| 118 | { |
| 119 | ITensorHandle* tensorHandle = data.m_Outputs[idx]; |
| 120 | return reinterpret_cast<DataType*>(tensorHandle->Map()); |
| 121 | } |
| 122 | |
Nattapat Chaimanowong | 177d8d2 | 2018-10-16 13:21:27 +0100 | [diff] [blame] | 123 | } //namespace armnn |