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);