20 "ConvertStackToTosaOperator: Stack must have at least one input");
23 "ConvertStackToTosaOperator: Stack must have only one output");
26 "ConvertStackToTosaOperator: Scalar / Rank 0 input not supported");
28 const auto inputTensorRank = inputs[0]->GetNumDimensions();
31 "ConvertStackToTosaOperator: Scalar / Rank 0 input not supported");
34 if (stackDescriptor->
m_Axis > inputTensorRank)
36 throw armnn::Exception(
"ConvertStackToTosaOperator: Axis is out of a valid range.");
40 if (outputs[0]->GetNumDimensions() != inputTensorRank + 1)
42 throw armnn::Exception(
"ConvertStackToTosaOperator: Output shape mismatch.");
45 auto inputDType =
ArmNNToDType(inputs[0]->GetDataType());
47 std::vector<TosaSerializationTensor*> tensors;
48 std::vector<TosaSerializationOperator*> operators;
50 std::string outputName = std::string(
"output0_");
56 std::vector<std::string> inputNames;
57 for (
unsigned int i = 0; i < inputs.size(); ++i)
59 if (inputs[i]->GetShape() != stackDescriptor->
m_InputShape)
61 throw armnn::Exception(
"ConvertStackToTosaOperator: Inputs have mismatched shapes.");
64 std::string inputName =
"input" + std::to_string(i) +
"_";
72 tensors.emplace_back(
new TosaSerializationTensor(inputName,
76 inputNames.push_back(inputName);
80 tensors.emplace_back(
new TosaSerializationTensor(outputName,
85 bool transposeOpNeeded = (stackDescriptor->
m_Axis == inputTensorRank);
88 std::vector<int32_t> permutationOrder;
89 std::vector<int32_t> reshapeOutputShape;
91 if (transposeOpNeeded)
95 reshapeOutputShape.push_back(
static_cast<int32_t
>(blockOutputShape[stackDescriptor->
m_Axis]));
97 for (
unsigned int d = 0; d < inputTensorRank; d++)
99 permutationOrder.push_back(
static_cast<int32_t
>(d) + 1);
100 reshapeOutputShape.push_back(
static_cast<int32_t
>(blockOutputShape[d]));
102 permutationOrder.push_back(0);
106 concatAxis = stackDescriptor->
m_Axis;
110 std::vector<int32_t> concatOutputShape;
112 for (
unsigned int i = 0; i < inputTensorRank; i++)
114 concatOutputShape.push_back(inputTensorShape[i]);
117 concatOutputShape[concatAxis] *=
static_cast<int>(stackDescriptor->
m_NumInputs);
122 TosaAxisAttribute axisAttribute(
static_cast<int32_t
>(concatAxis));
124 auto* concatOp =
new TosaSerializationOperator(Op_CONCAT,
125 Attribute_AxisAttribute,
129 operators.push_back(concatOp);
131 tensors.emplace_back(
new TosaSerializationTensor(concatOutputName,
138 std::string& reshapeOpOutputName = transposeOpNeeded ? reshapeOutputName : outputName;
140 TosaReshapeAttribute reshapeAttribute = transposeOpNeeded ? reshapeOutputShape : blockOutputShape;
142 auto* reshapeOp =
new TosaSerializationOperator(Op_RESHAPE,
143 Attribute_ReshapeAttribute,
146 {reshapeOpOutputName});
147 operators.push_back(reshapeOp);
149 if (transposeOpNeeded)
152 tensors.emplace_back(
new TosaSerializationTensor(reshapeOutputName,
157 TosaTransposeAttribute transposeAttribute(permutationOrder);
159 TosaSerializationOperator *transposeOp =
new TosaSerializationOperator(Op_TRANSPOSE,
160 Attribute_TransposeAttribute,
164 operators.push_back(transposeOp);
169 return new TosaSerializationBasicBlock(blockName,
#define ARMNN_THROW_INVALIDARG_MSG_IF_FALSE(_cond, _str)
std::string GenerateUniqueOutputName(const Layer &layer, uint32_t layerSlot=0)
const std::string mainName
DType ArmNNToDType(const DataType &type)
std::vector< int32_t > GetTosaTensorShape(const TensorShape &shape)
std::string GenerateUniqueInputName(const armnn::InputSlot &slot)
std::string GetUniqueTosaMappingID()
Base class for all ArmNN exceptions so that users can filter to just those.
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
TensorShape m_InputShape
Required shape of all input tensors.
uint32_t m_Axis
0-based axis along which to stack the input tensors.
uint32_t m_NumInputs
Number of input tensors.