telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1 | // |
Colm Donelan | a9bea1a | 2023-04-24 21:51:44 +0100 | [diff] [blame] | 2 | // Copyright © 2017, 2023 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
Matteo Martincigh | e5b8eb9 | 2019-11-28 15:45:42 +0000 | [diff] [blame] | 8 | #include <armnn/backends/ITensorHandle.hpp> |
Colm Donelan | 0c47974 | 2021-12-10 12:43:54 +0000 | [diff] [blame] | 9 | #include <armnn/backends/TensorHandle.hpp> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 10 | #include <armnn/Tensor.hpp> |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 11 | #include <armnn/utility/PolymorphicDowncast.hpp> |
Matteo Martincigh | e011d20 | 2019-11-28 11:35:47 +0000 | [diff] [blame] | 12 | #include <armnnUtils/Permute.hpp> |
| 13 | |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 14 | #include <Half.hpp> |
Matteo Martincigh | 747ef82 | 2018-12-18 09:26:39 +0000 | [diff] [blame] | 15 | #include <Profiling.hpp> |
Matteo Martincigh | 747ef82 | 2018-12-18 09:26:39 +0000 | [diff] [blame] | 16 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 17 | |
| 18 | namespace armnn |
| 19 | { |
| 20 | namespace |
| 21 | { |
Matteo Martincigh | 747ef82 | 2018-12-18 09:26:39 +0000 | [diff] [blame] | 22 | |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 23 | template <typename ArrayType, typename Arg> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 24 | void AssignValues(unsigned int num, unsigned int& idx, const ArrayType& array, Arg& arg) |
| 25 | { |
Matteo Martincigh | 747ef82 | 2018-12-18 09:26:39 +0000 | [diff] [blame] | 26 | if (idx >= num) |
| 27 | { |
| 28 | return; |
| 29 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 30 | |
Matteo Martincigh | 747ef82 | 2018-12-18 09:26:39 +0000 | [diff] [blame] | 31 | arg = array[(num - 1) - idx]; |
| 32 | idx++; |
| 33 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 34 | |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 35 | template <typename T, typename ArrayType, typename... Args> |
| 36 | void AssignValues(unsigned int num, unsigned int idx, const ArrayType& array, T& assignee, Args&... args) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 37 | { |
Matteo Martincigh | 747ef82 | 2018-12-18 09:26:39 +0000 | [diff] [blame] | 38 | AssignValues(num, idx, array, assignee); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 39 | |
Matteo Martincigh | 747ef82 | 2018-12-18 09:26:39 +0000 | [diff] [blame] | 40 | AssignValues(num, idx, array, args...); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 41 | } |
Matteo Martincigh | 747ef82 | 2018-12-18 09:26:39 +0000 | [diff] [blame] | 42 | |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 43 | } // anonymous namespace |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 44 | |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 45 | template <typename CopyFunc> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 46 | void CopyTensorContentsGeneric(const ITensorHandle* srcTensor, ITensorHandle* dstTensor, CopyFunc copy) |
| 47 | { |
Matthew Bentham | efdbca6 | 2019-09-14 23:35:28 +0100 | [diff] [blame] | 48 | // For ease of understanding, names are assigned to the dimensions |
| 49 | // of the tensor as if NHWC, however this routine works with any 5D tensor |
Matthew Jackson | dba634f | 2019-08-15 15:14:18 +0100 | [diff] [blame] | 50 | static_assert(MaxNumOfTensorDimensions == 5, "Please update CopyTensorContents"); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 51 | |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 52 | TensorShape srcStrides = srcTensor->GetStrides(); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 53 | const TensorShape& srcShape = srcTensor->GetShape(); |
Rob Hughes | 9934e4e | 2019-11-27 14:27:11 +0000 | [diff] [blame] | 54 | const auto srcSize = srcTensor->GetStrides()[0] * srcShape[0]; |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 55 | TensorShape dstStrides = dstTensor->GetStrides(); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 56 | const TensorShape& dstShape = dstTensor->GetShape(); |
Rob Hughes | 9934e4e | 2019-11-27 14:27:11 +0000 | [diff] [blame] | 57 | const auto dstSize = dstTensor->GetStrides()[0] * dstShape[0]; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 58 | |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 59 | size_t srcDepth = 1; |
| 60 | size_t srcBatches = 1; |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 61 | size_t srcHeight = 1; |
| 62 | size_t srcWidth = 1; |
Matthew Bentham | efdbca6 | 2019-09-14 23:35:28 +0100 | [diff] [blame] | 63 | size_t srcChannels = 1; |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 64 | AssignValues(srcShape.GetNumDimensions(), |
| 65 | 0, |
| 66 | srcShape, |
Matthew Bentham | efdbca6 | 2019-09-14 23:35:28 +0100 | [diff] [blame] | 67 | srcChannels, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 68 | srcWidth, |
| 69 | srcHeight, |
Matthew Jackson | dba634f | 2019-08-15 15:14:18 +0100 | [diff] [blame] | 70 | srcBatches, |
| 71 | srcDepth); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 72 | |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 73 | size_t srcDepthStride = 0; |
| 74 | size_t srcBatchStride = 0; |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 75 | size_t srcHeightStride = 0; |
| 76 | size_t srcWidthStride = 0; |
Matthew Bentham | efdbca6 | 2019-09-14 23:35:28 +0100 | [diff] [blame] | 77 | size_t srcChannelStride = 0; |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 78 | AssignValues(srcStrides.GetNumDimensions(), |
| 79 | 0, |
| 80 | srcStrides, |
Matthew Bentham | efdbca6 | 2019-09-14 23:35:28 +0100 | [diff] [blame] | 81 | srcChannelStride, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 82 | srcWidthStride, |
| 83 | srcHeightStride, |
Matthew Jackson | dba634f | 2019-08-15 15:14:18 +0100 | [diff] [blame] | 84 | srcBatchStride, |
| 85 | srcDepthStride); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 86 | |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 87 | size_t dstDepth = 1; |
| 88 | size_t dstBatches = 1; |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 89 | size_t dstHeight = 1; |
| 90 | size_t dstWidth = 1; |
Matthew Bentham | efdbca6 | 2019-09-14 23:35:28 +0100 | [diff] [blame] | 91 | size_t dstChannels = 1; |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 92 | AssignValues(dstShape.GetNumDimensions(), |
| 93 | 0, |
| 94 | dstShape, |
Matthew Bentham | efdbca6 | 2019-09-14 23:35:28 +0100 | [diff] [blame] | 95 | dstChannels, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 96 | dstWidth, |
| 97 | dstHeight, |
Matthew Jackson | dba634f | 2019-08-15 15:14:18 +0100 | [diff] [blame] | 98 | dstBatches, |
| 99 | dstDepth); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 100 | |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 101 | size_t dstDepthStride = 0; |
| 102 | size_t dstBatchStride = 0; |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 103 | size_t dstHeightStride = 0; |
| 104 | size_t dstWidthStride = 0; |
Matthew Bentham | efdbca6 | 2019-09-14 23:35:28 +0100 | [diff] [blame] | 105 | size_t dstChannelStride = 0; |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 106 | AssignValues(dstStrides.GetNumDimensions(), |
| 107 | 0, |
| 108 | dstStrides, |
Matthew Bentham | efdbca6 | 2019-09-14 23:35:28 +0100 | [diff] [blame] | 109 | dstChannelStride, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 110 | dstWidthStride, |
| 111 | dstHeightStride, |
Matthew Jackson | dba634f | 2019-08-15 15:14:18 +0100 | [diff] [blame] | 112 | dstBatchStride, |
| 113 | dstDepthStride); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 114 | |
Rob Hughes | 9934e4e | 2019-11-27 14:27:11 +0000 | [diff] [blame] | 115 | const unsigned char* srcDataStart; |
| 116 | unsigned char* dstDataStart; |
Sadik Armagan | bf86d51 | 2018-12-24 09:01:31 +0000 | [diff] [blame] | 117 | { |
| 118 | ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "Synchronize buffers"); |
Rob Hughes | 9934e4e | 2019-11-27 14:27:11 +0000 | [diff] [blame] | 119 | srcDataStart = static_cast<const uint8_t*>(srcTensor->Map()); |
| 120 | dstDataStart = static_cast<uint8_t*>(dstTensor->Map()); |
Sadik Armagan | bf86d51 | 2018-12-24 09:01:31 +0000 | [diff] [blame] | 121 | } |
Colm Donelan | a9bea1a | 2023-04-24 21:51:44 +0100 | [diff] [blame] | 122 | if (srcDataStart == nullptr) |
| 123 | { |
| 124 | throw MemoryValidationException("The source tensor is null."); |
| 125 | } |
| 126 | if (dstDataStart == nullptr) |
| 127 | { |
| 128 | throw MemoryValidationException("The destination tensor is null."); |
| 129 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 130 | |
Rob Hughes | 9934e4e | 2019-11-27 14:27:11 +0000 | [diff] [blame] | 131 | size_t copyLength = std::min(srcChannels * srcChannelStride, dstChannels * dstChannelStride); |
Matthew Bentham | efdbca6 | 2019-09-14 23:35:28 +0100 | [diff] [blame] | 132 | size_t copyWidth = std::min(srcWidth, dstWidth); |
| 133 | size_t copyHeight = std::min(srcHeight, dstHeight); |
| 134 | size_t copyBatches = std::min(srcBatches, dstBatches); |
| 135 | size_t copyDepth = std::min(srcDepth, dstDepth); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 136 | |
Matthew Bentham | 019c4b1 | 2019-09-15 00:06:05 +0100 | [diff] [blame] | 137 | // Coalesce inner dimensions where possible |
| 138 | // to reduce overheard calling copy() and to |
| 139 | // allow for memory bandwidth optimisations |
| 140 | if (copyLength == srcWidthStride && |
| 141 | copyLength == dstWidthStride) |
| 142 | { |
| 143 | // There is no special padding between rows, |
| 144 | // and sizes are compatible, so copy whole rows |
| 145 | copyLength *= copyWidth; |
| 146 | copyWidth = 1; |
| 147 | |
| 148 | if (copyLength == srcHeightStride && |
| 149 | copyLength == dstHeightStride) |
| 150 | { |
| 151 | // There is no special padding between batches |
| 152 | // and sizes are compatible so copy whole batches |
| 153 | copyLength *= copyHeight; |
| 154 | copyHeight = 1; |
| 155 | } |
| 156 | } |
| 157 | |
Rob Hughes | 9934e4e | 2019-11-27 14:27:11 +0000 | [diff] [blame] | 158 | const unsigned char* srcData = srcDataStart; |
| 159 | unsigned char* dstData = dstDataStart; |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 160 | for (unsigned int d = 0; d < copyDepth; ++d) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 161 | { |
Matthew Jackson | dba634f | 2019-08-15 15:14:18 +0100 | [diff] [blame] | 162 | auto srcPtrDepth = srcData; |
| 163 | auto dstPtrDepth = dstData; |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 164 | for (unsigned int b = 0; b < copyBatches; ++b) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 165 | { |
Matthew Jackson | dba634f | 2019-08-15 15:14:18 +0100 | [diff] [blame] | 166 | auto srcPtrBatch = srcData; |
| 167 | auto dstPtrBatch = dstData; |
Matthew Bentham | efdbca6 | 2019-09-14 23:35:28 +0100 | [diff] [blame] | 168 | for (unsigned int h = 0; h < copyHeight; ++h) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 169 | { |
Matthew Jackson | dba634f | 2019-08-15 15:14:18 +0100 | [diff] [blame] | 170 | auto srcPtrChannel = srcData; |
| 171 | auto dstPtrChannel = dstData; |
Matthew Bentham | efdbca6 | 2019-09-14 23:35:28 +0100 | [diff] [blame] | 172 | for (unsigned int w = 0; w < copyWidth; ++w) |
Matthew Jackson | dba634f | 2019-08-15 15:14:18 +0100 | [diff] [blame] | 173 | { |
Colm Donelan | a9bea1a | 2023-04-24 21:51:44 +0100 | [diff] [blame] | 174 | // Sanity check the memory area we've been asked to copy from and to. |
| 175 | if (copyLength > srcSize) |
| 176 | { |
| 177 | throw MemoryValidationException( |
| 178 | "The source tensor size does not match the size of the allocated tensor."); |
| 179 | } |
| 180 | if (copyLength > dstSize) |
| 181 | { |
| 182 | throw MemoryValidationException( |
| 183 | "The destination tensor size will overrun the destination tensor."); |
| 184 | } |
Matthew Jackson | dba634f | 2019-08-15 15:14:18 +0100 | [diff] [blame] | 185 | copy(dstData, srcData, copyLength); |
Matthew Bentham | efdbca6 | 2019-09-14 23:35:28 +0100 | [diff] [blame] | 186 | dstData += dstWidthStride; |
| 187 | srcData += srcWidthStride; |
Matthew Jackson | dba634f | 2019-08-15 15:14:18 +0100 | [diff] [blame] | 188 | } |
Matthew Bentham | efdbca6 | 2019-09-14 23:35:28 +0100 | [diff] [blame] | 189 | dstData += (static_cast<long>(dstHeightStride) - (dstData - dstPtrChannel)); |
| 190 | srcData += (static_cast<long>(srcHeightStride) - (srcData - srcPtrChannel)); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 191 | } |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 192 | dstData += (static_cast<long>(dstBatchStride) - (dstData - dstPtrBatch)); |
| 193 | srcData += (static_cast<long>(srcBatchStride) - (srcData - srcPtrBatch)); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 194 | } |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 195 | dstData += (static_cast<long>(dstDepthStride) - (dstData - dstPtrDepth)); |
| 196 | srcData += (static_cast<long>(srcDepthStride) - (srcData - srcPtrDepth)); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | srcTensor->Unmap(); |
| 200 | dstTensor->Unmap(); |
| 201 | } |
| 202 | |
| 203 | template <typename SrcTensorHandleType, typename DstTensorHandleType, typename DescriptorType> |
| 204 | void GatherTensorHandlePairs(const DescriptorType& descriptor, |
| 205 | std::vector<std::pair<SrcTensorHandleType*, DstTensorHandleType*>>& tensorHandlePairs) |
| 206 | { |
| 207 | const unsigned int numInputs = static_cast<unsigned int>(descriptor.m_Inputs.size()); |
| 208 | tensorHandlePairs.reserve(numInputs); |
| 209 | |
| 210 | for (unsigned int i = 0; i < numInputs; ++i) |
| 211 | { |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 212 | SrcTensorHandleType* const srcTensorHandle = |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 213 | PolymorphicDowncast<SrcTensorHandleType*>(descriptor.m_Inputs[i]); |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 214 | DstTensorHandleType* const dstTensorHandle = |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 215 | PolymorphicDowncast<DstTensorHandleType*>(descriptor.m_Outputs[i]); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 216 | |
| 217 | tensorHandlePairs.emplace_back(srcTensorHandle, dstTensorHandle); |
| 218 | } |
| 219 | } |
| 220 | |
Francis Murtagh | ec33a91 | 2019-11-05 14:26:23 +0000 | [diff] [blame] | 221 | int32_t ConvertMaskToACLFormat(int32_t mask, int32_t numDim); |
| 222 | |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 223 | armnn::ConstTensor PermuteTensor(const ConstTensorHandle* tensor, |
Matteo Martincigh | 747ef82 | 2018-12-18 09:26:39 +0000 | [diff] [blame] | 224 | const PermutationVector& permutationVector, |
| 225 | void* permuteBuffer); |
| 226 | |
| 227 | void ReshapeWeightsForAcl(TensorInfo& weightInfo, DataLayout dataLayout); |
| 228 | |
| 229 | TensorInfo ConvertWeightTensorInfoFromArmnnToAcl(const TensorInfo& weightInfo, DataLayout dataLayout); |
| 230 | |
Jan Eilers | 53ef795 | 2021-06-02 12:01:25 +0100 | [diff] [blame] | 231 | /// Weights for depthwise have a datalayout of [1,H,W,O] = [1,H,W,I*M] |
| 232 | /// This function coverts a TensorInfo from [1,H,W,I*M] to [1,I*M,H,W] (if NCHW) or keeps it at [1,H,W,I*M] (if NHWC) |
| 233 | /// as required by the compute library |
| 234 | /// Returns a tuple of converted weights tensor info and depth multiplier |
| 235 | std::tuple<TensorInfo, unsigned int> Convert1HWOTensorInfoToAcl(const TensorInfo& weightInfo, |
| 236 | const TensorInfo& inputInfo, |
| 237 | const DataLayout dataLayout); |
| 238 | |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 239 | armnn::ConstTensor ConvertWeightTensorFromArmnnToAcl(const ConstTensorHandle* weightTensor, |
Matteo Martincigh | 747ef82 | 2018-12-18 09:26:39 +0000 | [diff] [blame] | 240 | DataLayout dataLayout, |
| 241 | void* permuteBuffer); |
| 242 | |
Jan Eilers | 53ef795 | 2021-06-02 12:01:25 +0100 | [diff] [blame] | 243 | /// Weights for depthwise have a datalayout of [1,H,W,O] = [1,H,W,I*M] |
| 244 | /// This function coverts a ConstCpuTensorHandle from [1,H,W,I*M] to [1,I*M,H,W] (if NCHW) or |
| 245 | /// keeps it at [1,H,W,I*M] (if NHWC) as required by the compute library |
| 246 | /// |
| 247 | /// \param weightTensor - ConstTensorHandle of weights tensor |
| 248 | /// \param inputInfo - TensorInfo of input tensor |
| 249 | /// \param dataLayout - DataLayout of the input tensor |
| 250 | /// \param permuteBuffer - Pointer to memory with the size of tensor. Used for the permutation |
| 251 | /// \return tuple of transformed weights-ConstTensor and depthwise multiplier |
| 252 | std::tuple<ConstTensor, unsigned int> Convert1HWOTensorToAcl(const ConstTensorHandle* weightTensor, |
| 253 | const TensorInfo& inputInfo, |
| 254 | const DataLayout dataLayout, |
| 255 | void* permuteBuffer); |
| 256 | |
| 257 | /// Converts a (weights) tensor from [1, H, W, I*M] = [1, H, W, O] to [M, I, H, W] |
| 258 | /// |
| 259 | /// \param weightTensor - ConstTensorHandle of the weight tensor that should be converted |
| 260 | /// \param inputInfo - TensorInfo of the corresponding input tensor |
| 261 | /// \param dataLayout - DataLayout of the input tensor e.g. NHWC or NCHW |
| 262 | /// \param permuteBuffer - Memory location with the same size as the weight tensor to write converted data to |
| 263 | /// \return - A tuple of ConstTensor and unsigned int which is the converted weightTensor and the depthMultiplier |
| 264 | std::tuple<ConstTensor, unsigned int> Convert1HWOtoMIHW(const ConstTensorHandle* weightTensor, |
| 265 | const TensorInfo& inputInfo, |
| 266 | const DataLayout& dataLayout, |
| 267 | void* permuteBuffer); |
| 268 | |
Teresa Charlin | b2d3ec5 | 2022-04-12 22:07:09 +0100 | [diff] [blame] | 269 | /// Calculates the key index values needed for GatherNd: N, ND, K, W, C (N is always 1) |
| 270 | /// |
| 271 | /// \param inputInfo0 - TensorInfo of the corresponding input tensor: params |
| 272 | /// \param inputInfo1 - TensorInfo of the corresponding input tensor: indices |
| 273 | /// \return - A map with names and values for N, ND, K, W, C |
| 274 | std::map<std::string, unsigned int> CalculateGatherNdKeyIndices(TensorInfo inputInfo0, TensorInfo inputInfo1); |
| 275 | |
Teresa Charlin | 0f86ecf | 2022-10-13 15:47:08 +0100 | [diff] [blame] | 276 | /// Generates a permutation vector of size rank that permutes the 2 most right dimensions |
| 277 | /// |
| 278 | /// \param rank - Tensor rank, i.e. number of dimensions in the tensors |
| 279 | /// \return - A permutation vector that permutes the 2 last dimensions |
| 280 | armnn::PermutationVector GeneratePermutationVectorOnLastTwoDimensions(unsigned int rank); |
| 281 | |
Kevin May | 665a964a | 2019-08-21 16:53:50 +0100 | [diff] [blame] | 282 | } //namespace armnn |