12 #include <fmt/format.h> 26 if (permutationVector.
GetSize() > 0)
52 weightShape[2] * weightShape[3] });
54 weightShape[0] * weightShape[1],
61 weightInfo.
SetShape({ 1, weightShape[0] * weightShape[1], weightShape[2], weightShape[3] });
66 template <
typename DataType>
71 unsigned int multiplier;
74 unsigned int inputChannels;
78 height = weightShape[0];
79 width = weightShape[1];
80 inputChannels = weightShape[2];
81 multiplier = weightShape[3];
85 height = weightShape[2];
86 width = weightShape[3];
87 inputChannels = weightShape[1];
88 multiplier = weightShape[0];
92 std::vector<DataType> weightAclOrder(height*width*inputChannels*multiplier);
93 unsigned int destinationWeightsChannel;
94 unsigned int totalChannels = inputChannels * multiplier;
95 unsigned int channelSize = height * width;
96 unsigned int inputChannel = 0;
98 for (
unsigned int originWeightsChannel = 0; originWeightsChannel < totalChannels; originWeightsChannel++)
100 inputChannel = originWeightsChannel % inputChannels;
101 destinationWeightsChannel = (originWeightsChannel - inputChannel) / inputChannels + multiplier * inputChannel;
103 for (
unsigned int i = 0; i < channelSize; i++)
105 weightAclOrder[i + destinationWeightsChannel * channelSize] =
106 weight[i + originWeightsChannel * channelSize];
135 return weightPermutedInfo;
145 unsigned int depthMultiplier = 1;
157 permutationVector = { 0, 2, 3, 1 };
167 return std::make_tuple(weightsPermuted, depthMultiplier);
174 unsigned int aclDepthMultiplier = 1;
180 weightsPermuted = weightInfo;
197 return std::make_tuple(weightsPermuted, aclDepthMultiplier);
211 "quantization is applied.");
215 auto weightsShape = weightsInfo.
GetShape();
217 unsigned int depthMultiplier = weightsShape[3] / inputInfo.
GetShape()[channelIndex];
218 weightsInfo.
SetShape({ weightsShape[1],
227 return std::make_tuple(weightsPermuted, depthMultiplier);
251 permutationVector = { 3, 2, 0, 1 };
261 weightPermuted = ReorderWeightChannelsForAcl<float>(weightPermuted, dataLayout, permuteBuffer);
265 ReorderWeightChannelsForAcl<half_float::half>(weightPermuted, dataLayout, permuteBuffer);
269 weightPermuted = ReorderWeightChannelsForAcl<uint8_t>(weightPermuted, dataLayout, permuteBuffer);
272 weightPermuted = ReorderWeightChannelsForAcl<int8_t>(weightPermuted, dataLayout, permuteBuffer);
283 return weightPermuted;
288 int32_t reversedMask = 0;
289 for (
unsigned int i = 0; i < armnn::numeric_cast<unsigned int>(numDim); ++i)
292 int32_t bit = (mask & 1 << i) != 0;
294 reversedMask += (bit << std::max(numDim-(armnn::numeric_cast<int>(i)+1), 0));
302 std::vector<unsigned int> paramsShape;
305 paramsShape.push_back(inputInfo0.
GetShape()[i]);
308 std::vector<unsigned int> indicesShape;
311 indicesShape.push_back(inputInfo1.
GetShape()[i]);
314 std::map<std::string, unsigned int> keyIndices;
320 keyIndices[
"ND"] = indicesShape.back();
324 static_cast<unsigned int>(std::accumulate(std::begin(indicesShape),
325 std::end(indicesShape) - 1,
327 std::multiplies<>() ));
330 static_cast<unsigned int>(std::accumulate(std::begin(paramsShape),
331 std::begin(paramsShape) + static_cast<int>(keyIndices[
"ND"]),
333 std::multiplies<>() ));
336 static_cast<unsigned int>(std::accumulate(std::begin(paramsShape) + static_cast<int>(keyIndices[
"ND"]),
337 std::end(paramsShape),
339 std::multiplies<>() ));
350 permutationVector = {1U, 0U};
353 permutationVector = {0U, 2U, 1U};
356 permutationVector = {0U, 1U, 3U, 2U};
359 throw Exception(
"Invalid number of dimensions.");
361 return permutationVector;
armnn::ConstTensor PermuteTensor(const ConstTensorHandle *tensor, const PermutationVector &permutationVector, void *permuteBuffer)
constexpr const char * GetDataLayoutName(DataLayout dataLayout)
const TensorShape & GetShape() const
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) ...
TensorInfo ConvertWeightTensorInfoFromArmnnToAcl(const TensorInfo &weightInfo, DataLayout dataLayout)
armnn::PermutationVector GeneratePermutationVectorOnLastTwoDimensions(unsigned int rank)
Generates a permutation vector of size rank that permutes the 2 most right dimensions.
bool HasPerAxisQuantization() const
armnn::ConstTensor ConvertWeightTensorFromArmnnToAcl(const ConstTensorHandle *weightTensor, DataLayout dataLayout, void *permuteBuffer)
const TensorShape & GetShape() const
unsigned int GetNumBytes() const
Copyright (c) 2021 ARM Limited and Contributors.
ConstTensor ReorderWeightChannelsForAcl(const ConstTensor &weightHandle, DataLayout dataLayout, void *permuteBuffer)
void SetShape(const TensorShape &newShape)
const TensorInfo & GetTensorInfo() const
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...
#define ARMNN_ASSERT_MSG(COND, MSG)
Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout...
DataType GetDataType() const
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
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...
const TensorInfo & GetInfo() const
int32_t ConvertMaskToACLFormat(int32_t mask, int32_t numDim)
Base class for all ArmNN exceptions so that users can filter to just those.
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].
void SetConstant(const bool IsConstant=true)
Marks the data corresponding to this tensor info as constant.
DataType GetDataType() const
void ReshapeWeightsForAcl(TensorInfo &weightInfo, DataLayout dataLayout)
unsigned int GetNumDimensions() const
unsigned int GetChannelsIndex() const
armnn::TensorShape Permuted(const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)
const T * GetConstTensor() const
constexpr unsigned int GetDataTypeSize(DataType dataType)