12 #include <fmt/format.h>
21 if (tensor ==
nullptr)
25 if (permuteBuffer ==
nullptr)
32 if (permutationVector.
GetSize() > 0)
58 weightShape[2] * weightShape[3] });
60 weightShape[0] * weightShape[1],
67 weightInfo.
SetShape({ 1, weightShape[0] * weightShape[1], weightShape[2], weightShape[3] });
72 template <
typename DataType>
77 unsigned int multiplier;
80 unsigned int inputChannels;
84 height = weightShape[0];
85 width = weightShape[1];
86 inputChannels = weightShape[2];
87 multiplier = weightShape[3];
91 height = weightShape[2];
92 width = weightShape[3];
93 inputChannels = weightShape[1];
94 multiplier = weightShape[0];
98 std::vector<DataType> weightAclOrder(height*width*inputChannels*multiplier);
99 unsigned int destinationWeightsChannel;
100 unsigned int totalChannels = inputChannels * multiplier;
101 unsigned int channelSize = height * width;
102 unsigned int inputChannel = 0;
104 for (
unsigned int originWeightsChannel = 0; originWeightsChannel < totalChannels; originWeightsChannel++)
106 inputChannel = originWeightsChannel % inputChannels;
107 destinationWeightsChannel = (originWeightsChannel - inputChannel) / inputChannels + multiplier * inputChannel;
109 for (
unsigned int i = 0; i < channelSize; i++)
111 weightAclOrder[i + destinationWeightsChannel * channelSize] =
112 weight[i + originWeightsChannel * channelSize];
141 return weightPermutedInfo;
151 unsigned int depthMultiplier = 1;
163 permutationVector = { 0, 2, 3, 1 };
173 return std::make_tuple(weightsPermuted, depthMultiplier);
180 unsigned int aclDepthMultiplier = 1;
186 weightsPermuted = weightInfo;
203 return std::make_tuple(weightsPermuted, aclDepthMultiplier);
217 "quantization is applied.");
221 auto weightsShape = weightsInfo.
GetShape();
223 unsigned int depthMultiplier = weightsShape[3] / inputInfo.
GetShape()[channelIndex];
224 weightsInfo.
SetShape({ weightsShape[1],
233 return std::make_tuple(weightsPermuted, depthMultiplier);
240 if (weightTensor ==
nullptr)
244 if (permuteBuffer ==
nullptr)
263 permutationVector = { 3, 2, 0, 1 };
273 weightPermuted = ReorderWeightChannelsForAcl<float>(weightPermuted, dataLayout, permuteBuffer);
277 ReorderWeightChannelsForAcl<half_float::half>(weightPermuted, dataLayout, permuteBuffer);
281 weightPermuted = ReorderWeightChannelsForAcl<uint8_t>(weightPermuted, dataLayout, permuteBuffer);
284 weightPermuted = ReorderWeightChannelsForAcl<int8_t>(weightPermuted, dataLayout, permuteBuffer);
295 return weightPermuted;
300 int32_t reversedMask = 0;
301 for (
unsigned int i = 0; i < armnn::numeric_cast<unsigned int>(numDim); ++i)
304 int32_t bit = (mask & 1 << i) != 0;
306 reversedMask += (bit << std::max(numDim-(armnn::numeric_cast<int>(i)+1), 0));
314 std::vector<unsigned int> paramsShape;
317 paramsShape.push_back(inputInfo0.
GetShape()[i]);
320 std::vector<unsigned int> indicesShape;
323 indicesShape.push_back(inputInfo1.
GetShape()[i]);
326 std::map<std::string, unsigned int> keyIndices;
332 keyIndices[
"ND"] = indicesShape.back();
336 static_cast<unsigned int>(std::accumulate(std::begin(indicesShape),
337 std::end(indicesShape) - 1,
339 std::multiplies<>() ));
342 static_cast<unsigned int>(std::accumulate(std::begin(paramsShape),
343 std::begin(paramsShape) +
static_cast<int>(keyIndices[
"ND"]),
345 std::multiplies<>() ));
348 static_cast<unsigned int>(std::accumulate(std::begin(paramsShape) +
static_cast<int>(keyIndices[
"ND"]),
349 std::end(paramsShape),
351 std::multiplies<>() ));
362 permutationVector = {1U, 0U};
365 permutationVector = {0U, 2U, 1U};
368 permutationVector = {0U, 1U, 3U, 2U};
371 throw Exception(
"Invalid number of dimensions.");
373 return permutationVector;