13 #include <fmt/format.h>
22 if (tensor ==
nullptr)
26 if (permuteBuffer ==
nullptr)
33 if (permutationVector.
GetSize() > 0)
59 weightShape[2] * weightShape[3] });
61 weightShape[0] * weightShape[1],
68 weightInfo.
SetShape({ 1, weightShape[0] * weightShape[1], weightShape[2], weightShape[3] });
73 template <
typename DataType>
78 unsigned int multiplier;
81 unsigned int inputChannels;
85 height = weightShape[0];
86 width = weightShape[1];
87 inputChannels = weightShape[2];
88 multiplier = weightShape[3];
92 height = weightShape[2];
93 width = weightShape[3];
94 inputChannels = weightShape[1];
95 multiplier = weightShape[0];
99 std::vector<DataType> weightAclOrder(height*width*inputChannels*multiplier);
100 unsigned int destinationWeightsChannel;
101 unsigned int totalChannels = inputChannels * multiplier;
102 unsigned int channelSize = height * width;
103 unsigned int inputChannel = 0;
105 for (
unsigned int originWeightsChannel = 0; originWeightsChannel < totalChannels; originWeightsChannel++)
107 inputChannel = originWeightsChannel % inputChannels;
108 destinationWeightsChannel = (originWeightsChannel - inputChannel) / inputChannels + multiplier * inputChannel;
110 for (
unsigned int i = 0; i < channelSize; i++)
112 weightAclOrder[i + destinationWeightsChannel * channelSize] =
113 weight[i + originWeightsChannel * channelSize];
142 return weightPermutedInfo;
152 unsigned int depthMultiplier = 1;
164 permutationVector = { 0, 2, 3, 1 };
174 return std::make_tuple(weightsPermuted, depthMultiplier);
181 unsigned int aclDepthMultiplier = 1;
187 weightsPermuted = weightInfo;
204 return std::make_tuple(weightsPermuted, aclDepthMultiplier);
218 "quantization is applied.");
222 auto weightsShape = weightsInfo.
GetShape();
224 unsigned int depthMultiplier = weightsShape[3] / inputInfo.
GetShape()[channelIndex];
225 weightsInfo.
SetShape({ weightsShape[1],
234 return std::make_tuple(weightsPermuted, depthMultiplier);
241 if (weightTensor ==
nullptr)
245 if (permuteBuffer ==
nullptr)
264 permutationVector = { 3, 2, 0, 1 };
274 weightPermuted = ReorderWeightChannelsForAcl<float>(weightPermuted, dataLayout, permuteBuffer);
278 ReorderWeightChannelsForAcl<half_float::half>(weightPermuted, dataLayout, permuteBuffer);
282 weightPermuted = ReorderWeightChannelsForAcl<uint8_t>(weightPermuted, dataLayout, permuteBuffer);
285 weightPermuted = ReorderWeightChannelsForAcl<int8_t>(weightPermuted, dataLayout, permuteBuffer);
296 return weightPermuted;
301 int32_t reversedMask = 0;
302 for (
unsigned int i = 0; i < armnn::numeric_cast<unsigned int>(numDim); ++i)
305 int32_t bit = (mask & 1 << i) != 0;
307 reversedMask += (bit << std::max(numDim-(armnn::numeric_cast<int>(i)+1), 0));
315 std::vector<unsigned int> paramsShape;
318 paramsShape.push_back(inputInfo0.
GetShape()[i]);
321 std::vector<unsigned int> indicesShape;
324 indicesShape.push_back(inputInfo1.
GetShape()[i]);
327 std::map<std::string, unsigned int> keyIndices;
333 keyIndices[
"ND"] = indicesShape.back();
337 static_cast<unsigned int>(std::accumulate(std::begin(indicesShape),
338 std::end(indicesShape) - 1,
340 std::multiplies<>() ));
343 static_cast<unsigned int>(std::accumulate(std::begin(paramsShape),
344 std::begin(paramsShape) +
static_cast<int>(keyIndices[
"ND"]),
346 std::multiplies<>() ));
349 static_cast<unsigned int>(std::accumulate(std::begin(paramsShape) +
static_cast<int>(keyIndices[
"ND"]),
350 std::end(paramsShape),
352 std::multiplies<>() ));
363 permutationVector = {1U, 0U};
366 permutationVector = {0U, 2U, 1U};
369 permutationVector = {0U, 1U, 3U, 2U};
372 throw Exception(
"Invalid number of dimensions.");
374 return permutationVector;
381 std::set<unsigned int> splitAxis;
388 for (
unsigned int i = 0; i < numSplit; ++i)
390 for (
unsigned int dimIdx = 0; dimIdx < numDimensions; ++dimIdx)
394 splitAxis.insert(dimIdx);
const TensorInfo & GetInfo() const
const TensorShape & GetShape() const
DataType GetDataType() const
const T * GetConstTensor() const
const TensorInfo & GetTensorInfo() const
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Base class for all ArmNN exceptions so that users can filter to just those.
unsigned int GetNumDimensions() const
const TensorShape & GetShape() const
void SetConstant(const bool IsConstant=true)
Marks the data corresponding to this tensor info as constant.
bool HasPerAxisQuantization() const
unsigned int GetNumBytes() const
void SetShape(const TensorShape &newShape)
DataType GetDataType() const
Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout.
unsigned int GetChannelsIndex() const
Copyright (c) 2021 ARM Limited and Contributors.
armnn::PermutationVector GeneratePermutationVectorOnLastTwoDimensions(unsigned int rank)
Generates a permutation vector of size rank that permutes the 2 most right dimensions.
TensorInfo ConvertWeightTensorInfoFromArmnnToAcl(const TensorInfo &weightInfo, DataLayout dataLayout)
std::set< unsigned int > ComputeSplitAxis(const armnn::SplitterDescriptor &desc, const TensorShape &input)
Calculates the axis values for split operation.
void ReshapeWeightsForAcl(TensorInfo &weightInfo, DataLayout dataLayout)
ConstTensor ReorderWeightChannelsForAcl(const ConstTensor &weightHandle, DataLayout dataLayout, void *permuteBuffer)
armnn::ConstTensor ConvertWeightTensorFromArmnnToAcl(const ConstTensorHandle *weightTensor, DataLayout dataLayout, void *permuteBuffer)
constexpr unsigned int GetDataTypeSize(DataType dataType)
std::tuple< ConstTensor, unsigned int > Convert1HWOtoMIHW(const ConstTensorHandle *weightTensor, const TensorInfo &inputInfo, const DataLayout &dataLayout, void *permuteBuffer)
Converts a (weights) tensor from [1, H, W, I*M] = [1, H, W, O] to [M, I, H, W].
armnn::ConstTensor PermuteTensor(const ConstTensorHandle *tensor, const PermutationVector &permutationVector, void *permuteBuffer)
std::map< std::string, unsigned int > CalculateGatherNdKeyIndices(TensorInfo inputInfo0, TensorInfo inputInfo1)
Calculates the key index values needed for GatherNd: N, ND, K, W, C (N is always 1)
std::tuple< TensorInfo, unsigned int > Convert1HWOTensorInfoToAcl(const TensorInfo &weightInfo, const TensorInfo &inputInfo, const DataLayout dataLayout)
Weights for depthwise have a datalayout of [1,H,W,O] = [1,H,W,I*M] This function coverts a TensorInfo...
int32_t ConvertMaskToACLFormat(int32_t mask, int32_t numDim)
constexpr const char * GetDataLayoutName(DataLayout dataLayout)
std::tuple< ConstTensor, unsigned int > Convert1HWOTensorToAcl(const ConstTensorHandle *weightTensor, const TensorInfo &inputInfo, const DataLayout dataLayout, void *permuteBuffer)
Weights for depthwise have a datalayout of [1,H,W,O] = [1,H,W,I*M] This function coverts a ConstCpuTe...
armnn::TensorShape Permuted(const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)
unsigned int GetUnsignedAxis(const unsigned int inputDimension, const int axis)
void Permute(const armnn::TensorShape &dstShape, const armnn::PermutationVector &mappings, const void *src, void *dst, size_t dataTypeSize)
A ViewsDescriptor for the SplitterLayer.
bool HasAxis() const
Returns true if an axis has been set.
int32_t GetAxis() const
Get the axis value.
uint32_t GetNumViews() const
Get the number of views.
const uint32_t * GetViewSizes(uint32_t idx) const
Get the view sizes at the int value idx.
uint32_t GetNumDimensions() const
Get the number of dimensions.