14 #include <neon/test/NeonWorkloadFactoryHelper.hpp> 22 unsigned int CalcAclAxis(
unsigned int numDimensions,
unsigned int axis)
24 return (numDimensions - axis) - 1;
30 using namespace armcomputetensorutils;
38 descriptor.m_Parameters,
43 const arm_compute::ITensor& input =
static_cast<IAclTensorHandle*
>(m_Data.m_Inputs[0])->GetTensor();
44 arm_compute::ITensor& outputStateIn =
static_cast<IAclTensorHandle*
>(m_Data.m_Inputs[1])->GetTensor();
45 const arm_compute::ITensor& cellStateIn =
static_cast<IAclTensorHandle*
>(m_Data.m_Inputs[2])->GetTensor();
47 arm_compute::ITensor& outputStateOut =
static_cast<IAclTensorHandle*
>(m_Data.m_Outputs[0])->GetTensor();
48 arm_compute::ITensor& cellStateOut =
static_cast<IAclTensorHandle*
>(m_Data.m_Outputs[1])->GetTensor();
49 arm_compute::ITensor& output =
static_cast<IAclTensorHandle*
>(m_Data.m_Outputs[2])->GetTensor();
57 unsigned int maxTime = m_Data.m_Parameters.m_TimeMajor ? inputLayerShape[0] : inputLayerShape[1];
58 unsigned int batchSize = m_Data.m_Parameters.m_TimeMajor ? inputLayerShape[1] : inputLayerShape[0];
59 unsigned int inputSize = inputLayerShape[2];
60 unsigned int outputSize = outputLayerShape[2];
62 const TensorShape timeMajorShapeInput({maxTime, batchSize, inputSize});
63 const TensorShape timeMajorShapeOutput({maxTime, batchSize, outputSize});
68 if (!m_Data.m_Parameters.m_TimeMajor)
70 std::unique_ptr<arm_compute::NEPermute> layer(
new arm_compute::NEPermute());
73 permuteOutInfo.
SetShape(timeMajorShapeInput);
74 BuildArmComputeTensor(m_PermuteFirstOut, permuteOutInfo);
75 armcomputetensorutils::InitialiseArmComputeTensorEmpty(m_PermuteFirstOut);
78 layer->configure(&input, &m_PermuteFirstOut, arm_compute::PermutationVector(0U,2U,1U));
79 m_Permute1.reset(layer.release());
85 for (
unsigned int i = 0; i < maxTime; ++i)
87 arm_compute::Tensor splitter_out;
88 arm_compute::Tensor concat_in;
90 auto splitterTensorInfo = inputInfo;
91 auto concatTensorInfo = outputInfo;
92 splitterTensorInfo.
SetShape({batchSize, inputSize});
93 concatTensorInfo.SetShape({batchSize, outputSize});
94 BuildArmComputeTensor(splitter_out, splitterTensorInfo);
95 BuildArmComputeTensor(concat_in, concatTensorInfo);
97 armcomputetensorutils::InitialiseArmComputeTensorEmpty(splitter_out);
98 armcomputetensorutils::InitialiseArmComputeTensorEmpty(concat_in);
101 m_SplitterOutputsTensors.push_back(std::move(splitter_out));
102 m_ConcatInputsTensors.push_back(std::move(concat_in));
105 for (
unsigned int i = 0; i < maxTime; ++i)
108 m_SplitterOutputs.push_back(&m_SplitterOutputsTensors[i]);
109 m_ConcatInputs.push_back(&m_ConcatInputsTensors[i]);
115 unsigned int numberDimensions = 3;
116 unsigned int dimension = 0;
121 unsigned int splitterDimSizes[3] = {1, batchSize, inputSize};
122 for (
unsigned int outputIdx = 0u; outputIdx < maxTime; ++outputIdx)
124 splitterDesc.
SetViewOriginCoord(outputIdx, dimension, splitterDimSizes[dimension] * outputIdx);
125 for (
unsigned int dimIdx = 0u; dimIdx < numberDimensions; ++dimIdx)
127 splitterDesc.
SetViewSize(outputIdx, dimIdx, splitterDimSizes[dimIdx]);
131 std::set<unsigned int> splitAxis =
ComputeSplitAxis(splitterDesc, timeMajorShapeInput);
133 std::unique_ptr<arm_compute::NESplit> split_layer(
new arm_compute::NESplit());
136 if (!m_Data.m_Parameters.m_TimeMajor)
138 split_layer->configure(&m_PermuteFirstOut, m_SplitterOutputs, aclAxisSplit);
141 split_layer->configure(&input, m_SplitterOutputs, aclAxisSplit);
144 split_layer->prepare();
145 m_Splitter.reset(split_layer.release());
151 arm_compute::LSTMParams<arm_compute::ITensor> lstm_param;
153 lstm_param.set_cell_clip_params(descriptor.m_Parameters.m_ClippingThresCell);
154 lstm_param.set_projection_clip_params(descriptor.m_Parameters.m_ClippingThresProj);
156 lstm_param.set_matmul_scale_params(descriptor.m_Parameters.m_InputIntermediateScale,
157 descriptor.m_Parameters.m_ForgetIntermediateScale,
158 descriptor.m_Parameters.m_CellIntermediateScale,
159 descriptor.m_Parameters.m_OutputIntermediateScale);
161 lstm_param.set_hidden_state_params(descriptor.m_Parameters.m_HiddenStateZeroPoint,
162 descriptor.m_Parameters.m_HiddenStateScale);
164 m_InputToForgetWeightsTensor = std::make_unique<arm_compute::Tensor>();
165 BuildArmComputeTensor(*m_InputToForgetWeightsTensor, m_Data.m_InputToForgetWeights->GetTensorInfo());
167 m_InputToCellWeightsTensor = std::make_unique<arm_compute::Tensor>();
168 BuildArmComputeTensor(*m_InputToCellWeightsTensor, m_Data.m_InputToCellWeights->GetTensorInfo());
170 m_InputToOutputWeightsTensor = std::make_unique<arm_compute::Tensor>();
171 BuildArmComputeTensor(*m_InputToOutputWeightsTensor, m_Data.m_InputToOutputWeights->GetTensorInfo());
173 m_RecurrentToForgetWeightsTensor = std::make_unique<arm_compute::Tensor>();
174 BuildArmComputeTensor(*m_RecurrentToForgetWeightsTensor, m_Data.m_RecurrentToForgetWeights->GetTensorInfo());
176 m_RecurrentToCellWeightsTensor = std::make_unique<arm_compute::Tensor>();
177 BuildArmComputeTensor(*m_RecurrentToCellWeightsTensor, m_Data.m_RecurrentToCellWeights->GetTensorInfo());
179 m_RecurrentToOutputWeightsTensor = std::make_unique<arm_compute::Tensor>();
180 BuildArmComputeTensor(*m_RecurrentToOutputWeightsTensor, m_Data.m_RecurrentToOutputWeights->GetTensorInfo());
182 m_ForgetGateBiasTensor = std::make_unique<arm_compute::Tensor>();
183 BuildArmComputeTensor(*m_ForgetGateBiasTensor, m_Data.m_ForgetGateBias->GetTensorInfo());
185 m_CellBiasTensor = std::make_unique<arm_compute::Tensor>();
186 BuildArmComputeTensor(*m_CellBiasTensor, m_Data.m_CellBias->GetTensorInfo());
188 m_OutputGateBiasTensor = std::make_unique<arm_compute::Tensor>();
189 BuildArmComputeTensor(*m_OutputGateBiasTensor, m_Data.m_OutputGateBias->GetTensorInfo());
192 if (!m_Data.m_Parameters.m_CifgEnabled)
194 m_InputToInputWeightsTensor = std::make_unique<arm_compute::Tensor>();
195 BuildArmComputeTensor(*m_InputToInputWeightsTensor, m_Data.m_InputToInputWeights->GetTensorInfo());
197 m_RecurrentToInputWeightsTensor = std::make_unique<arm_compute::Tensor>();
198 BuildArmComputeTensor(*m_RecurrentToInputWeightsTensor, m_Data.m_RecurrentToInputWeights->GetTensorInfo());
200 m_CellToInputWeightsTensor = std::make_unique<arm_compute::Tensor>();
201 if (m_Data.m_CellToInputWeights !=
nullptr)
203 BuildArmComputeTensor(*m_CellToInputWeightsTensor, m_Data.m_CellToInputWeights->GetTensorInfo());
206 m_InputGateBiasTensor = std::make_unique<arm_compute::Tensor>();
207 BuildArmComputeTensor(*m_InputGateBiasTensor, m_Data.m_InputGateBias->GetTensorInfo());
208 lstm_param.set_cifg_params(m_InputToInputWeightsTensor.get(),
209 m_RecurrentToInputWeightsTensor.get(),
210 m_Data.m_CellToInputWeights ? m_CellToInputWeightsTensor.get() :
nullptr,
211 m_InputGateBiasTensor.get());
214 if (m_Data.m_Parameters.m_ProjectionEnabled)
216 m_ProjectionWeightsTensor = std::make_unique<arm_compute::Tensor>();
217 BuildArmComputeTensor(*m_ProjectionWeightsTensor, m_Data.m_ProjectionWeights->GetTensorInfo());
219 m_ProjectionBiasTensor = std::make_unique<arm_compute::Tensor>();
220 if (m_Data.m_ProjectionBias !=
nullptr)
222 BuildArmComputeTensor(*m_ProjectionBiasTensor, m_Data.m_ProjectionBias->GetTensorInfo());
225 lstm_param.set_projection_params(m_ProjectionWeightsTensor.get(),
226 m_Data.m_ProjectionBias ? m_ProjectionBiasTensor.get() :
nullptr);
229 if (m_Data.m_Parameters.m_PeepholeEnabled)
231 m_CellToForgetWeightsTensor = std::make_unique<arm_compute::Tensor>();
232 BuildArmComputeTensor(*m_CellToForgetWeightsTensor, m_Data.m_CellToForgetWeights->GetTensorInfo());
234 m_CellToOutputWeightsTensor = std::make_unique<arm_compute::Tensor>();
235 BuildArmComputeTensor(*m_CellToOutputWeightsTensor, m_Data.m_CellToOutputWeights->GetTensorInfo());
237 lstm_param.set_peephole_params(m_CellToForgetWeightsTensor.get(), m_CellToOutputWeightsTensor.get());
240 if (m_Data.m_Parameters.m_LayerNormEnabled)
242 m_InputLayerNormWeightsTensor = std::make_unique<arm_compute::Tensor>();
243 if (!m_Data.m_Parameters.m_CifgEnabled)
245 BuildArmComputeTensor(*m_InputLayerNormWeightsTensor, m_Data.m_InputLayerNormWeights->GetTensorInfo());
248 m_ForgetLayerNormWeightsTensor = std::make_unique<arm_compute::Tensor>();
249 BuildArmComputeTensor(*m_ForgetLayerNormWeightsTensor, m_Data.m_ForgetLayerNormWeights->GetTensorInfo());
251 m_CellLayerNormWeightsTensor = std::make_unique<arm_compute::Tensor>();
252 BuildArmComputeTensor(*m_CellLayerNormWeightsTensor, m_Data.m_CellLayerNormWeights->GetTensorInfo());
254 m_OutputLayerNormWeightsTensor = std::make_unique<arm_compute::Tensor>();
255 BuildArmComputeTensor(*m_OutputLayerNormWeightsTensor, m_Data.m_OutputLayerNormWeights->GetTensorInfo());
257 auto inputNormWeightTensor = m_Data.m_Parameters.m_CifgEnabled ? nullptr : m_InputLayerNormWeightsTensor.get();
258 lstm_param.set_layer_normalization_params(inputNormWeightTensor,
259 m_ForgetLayerNormWeightsTensor.get(),
260 m_CellLayerNormWeightsTensor.get(),
261 m_OutputLayerNormWeightsTensor.get());
264 for (
unsigned int i = 0; i != maxTime; ++i)
268 arm_compute::ITensor* outputLSTM;
269 arm_compute::ITensor* inputLSTM;
275 if (maxTime == 1 && m_Data.m_Parameters.m_TimeMajor)
280 TensorShape inputShapeShrink({inputShape[1], inputShape[2]});
281 TensorShape outputShapeShrink({outputShape[1], outputShape[2]});
283 auto acl_input_shape_shrink = BuildArmComputeTensorShape(inputShapeShrink);
284 auto acl_output_shape_shrink = BuildArmComputeTensorShape(outputShapeShrink);
286 input.info()->set_tensor_shape(acl_input_shape_shrink);
287 inputLSTM =
const_cast<arm_compute::ITensor*
>(&input);
289 output.info()->set_tensor_shape(acl_output_shape_shrink);
290 outputLSTM = &output;
296 else if (maxTime == 1 && !m_Data.m_Parameters.m_TimeMajor)
299 TensorShape inputShapeShrink({inputShape[1], inputShape[2]});
300 auto acl_input_shape_shrink = BuildArmComputeTensorShape(inputShapeShrink);
301 m_PermuteFirstOut.info()->set_tensor_shape(acl_input_shape_shrink);
302 inputLSTM = &m_PermuteFirstOut;
304 outputLSTM =
const_cast<arm_compute::ITensor*
>(m_ConcatInputs[i]);
309 inputLSTM = m_SplitterOutputs[i];
310 outputLSTM =
const_cast<arm_compute::ITensor*
>(m_ConcatInputs[i]);
313 std::unique_ptr<arm_compute::NEQLSTMLayer> lstm_layer(
new arm_compute::NEQLSTMLayer());
315 lstm_layer->configure(inputLSTM,
316 m_InputToForgetWeightsTensor.get(),
317 m_InputToCellWeightsTensor.get(),
318 m_InputToOutputWeightsTensor.get(),
319 m_RecurrentToForgetWeightsTensor.get(),
320 m_RecurrentToCellWeightsTensor.get(),
321 m_RecurrentToOutputWeightsTensor.get(),
322 m_ForgetGateBiasTensor.get(),
323 m_CellBiasTensor.get(),
324 m_OutputGateBiasTensor.get(),
332 m_Layers.emplace_back(std::move(lstm_layer));
345 if (!m_Data.m_Parameters.m_CifgEnabled)
349 if (m_Data.m_CellToInputWeights !=
nullptr)
356 if (m_Data.m_Parameters.m_ProjectionEnabled)
359 if (m_Data.m_ProjectionBias !=
nullptr)
365 if (m_Data.m_Parameters.m_PeepholeEnabled)
371 if (m_Data.m_Parameters.m_LayerNormEnabled)
373 if (!m_Data.m_Parameters.m_CifgEnabled)
384 for (uint32_t i = 0; i < m_Layers.size(); ++i)
386 m_Layers[i]->prepare();
395 TensorShape shapeExpandTimeMajor({1, shape[0], shape[1]});
396 TensorShape shapeExpandBatchMajor({shape[0], 1, shape[1]});
400 for (
unsigned int i = 0; i < maxTime; ++i)
402 m_ConcatInputs[i]->info()->set_tensor_shape(BuildArmComputeTensorShape(shapeExpandTimeMajor));
406 for (
unsigned int inputIdx = 0u; inputIdx < maxTime; ++inputIdx)
411 m_Concat.reset(
new arm_compute::NEConcatenateLayer());
414 if (!m_Data.m_Parameters.m_TimeMajor)
416 TensorInfo concatOutputTensorInfo = outputInfo;
417 concatOutputTensorInfo.
SetShape(timeMajorShapeOutput);
418 BuildArmComputeTensor(concat_out, concatOutputTensorInfo);
419 armcomputetensorutils::InitialiseArmComputeTensorEmpty(concat_out);
421 m_Concat->configure(m_ConcatInputs, &concat_out, aclAxisConcat);
425 m_Concat->configure(m_ConcatInputs, &output, aclAxisConcat);
434 if (!m_Data.m_Parameters.m_TimeMajor)
436 output.info()->set_tensor_shape(BuildArmComputeTensorShape(shapeExpandBatchMajor));
440 output.info()->set_tensor_shape(BuildArmComputeTensorShape(shapeExpandTimeMajor));
447 if (!m_Data.m_Parameters.m_TimeMajor)
450 std::unique_ptr<arm_compute::NEPermute> layer(
new arm_compute::NEPermute());
453 layer->configure(&concat_out, &output, arm_compute::PermutationVector(0U, 2U, 1U));
457 layer->configure(m_ConcatInputs[0], &output, arm_compute::PermutationVector(0U, 2U, 1U));
459 m_Permute2.reset(layer.release());
476 for (uint32_t i = 0; i < m_Layers.size(); ++i)
503 unsigned int maxTime = descriptor.
m_TimeMajor ? inputLayerShape[0] : inputLayerShape[1];
504 unsigned int batchSize = descriptor.
m_TimeMajor ? inputLayerShape[1] : inputLayerShape[0];
505 unsigned int inputSize = inputLayerShape[2];
506 unsigned int outputSize = outputLayerShape[2];
508 const TensorShape timeMajorShapeInput({maxTime, batchSize, inputSize});
509 const TensorShape timeMajorShapeOutput({maxTime, batchSize, outputSize});
522 const arm_compute::TensorInfo aclInputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(input);
523 const arm_compute::TensorInfo aclOutputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(output);
529 arm_compute::TensorInfo aclPermuteOutInfo = armcomputetensorutils::BuildArmComputeTensorInfo(permuteOutInfo);
532 statusPermute1 = arm_compute::NEPermute::validate(&aclInputInfo,
534 arm_compute::PermutationVector(0U, 2U, 1U));
540 std::vector<arm_compute::TensorInfo> splitterOutputsTensorInfos;
541 std::vector<arm_compute::TensorInfo> concatInputsTensorInfos;
542 std::vector<arm_compute::ITensorInfo*> splitterOutputsTensorInfosPtr;
543 std::vector<const arm_compute::ITensorInfo*> concatInputsTensorInfosPtr;
544 splitterOutputsTensorInfos.reserve(maxTime);
545 concatInputsTensorInfos.reserve(maxTime);
546 for (
unsigned int i = 0; i < maxTime; ++i)
548 arm_compute::TensorInfo splitter_out;
549 arm_compute::TensorInfo concat_in;
553 splitterTensorInfo.SetShape({batchSize, inputSize});
554 concatTensorInfo.SetShape({batchSize, outputSize});
556 arm_compute::TensorInfo aclSplitterTensorInfo
557 = armcomputetensorutils::BuildArmComputeTensorInfo(splitterTensorInfo);
558 arm_compute::TensorInfo aclConcatTensorInfo
559 = armcomputetensorutils::BuildArmComputeTensorInfo(concatTensorInfo);
561 splitterOutputsTensorInfos.emplace_back(aclSplitterTensorInfo);
562 concatInputsTensorInfos.emplace_back(aclConcatTensorInfo);
563 splitterOutputsTensorInfosPtr.emplace_back(&splitterOutputsTensorInfos[i]);
564 concatInputsTensorInfosPtr.emplace_back(&concatInputsTensorInfos[i]);
570 unsigned int numberDimensions = 3;
571 unsigned int dimension = 0;
572 unsigned int aclAxisSplit = CalcAclAxis(numberDimensions, dimension);
578 statusSplit = arm_compute::NESplit::validate(&aclPermuteOutInfo,
579 splitterOutputsTensorInfosPtr,
583 statusSplit = arm_compute::NESplit::validate(&aclInputInfo, splitterOutputsTensorInfosPtr, aclAxisSplit);
591 arm_compute::LSTMParams<arm_compute::ITensorInfo> lstm_params_info;
598 const arm_compute::TensorInfo aclOutputStateInInfo = BuildArmComputeTensorInfo(outputStateIn);
599 const arm_compute::TensorInfo aclCellStateInInfo = BuildArmComputeTensorInfo(cellStateIn);
600 const arm_compute::TensorInfo aclScratchBufferInfo = BuildArmComputeTensorInfo(scratchBuffer);
601 const arm_compute::TensorInfo aclOutputStateOutInfo = BuildArmComputeTensorInfo(outputStateOut);
602 const arm_compute::TensorInfo aclCellStateOutInfo = BuildArmComputeTensorInfo(cellStateOut);
605 const arm_compute::TensorInfo aclInputToForgetWeightsInfo
607 const arm_compute::TensorInfo aclInputToCellWeightsInfo
609 const arm_compute::TensorInfo aclInputToOutputWeightsInfo
611 const arm_compute::TensorInfo aclRecurrentToForgetWeightsInfo
613 const arm_compute::TensorInfo aclRecurrentToCellWeightsInfo
615 const arm_compute::TensorInfo aclRecurrentToOutputWeightsInfo
617 const arm_compute::TensorInfo aclForgetGateBiasInfo
619 const arm_compute::TensorInfo aclCellBiasInfo
620 = BuildArmComputeTensorInfo(paramsInfo.
GetCellBias());
621 const arm_compute::TensorInfo aclOutputGateBiasInfo
624 arm_compute::TensorInfo aclInputToInputWeightsInfo;
625 arm_compute::TensorInfo aclRecurrentToInputWeightsInfo;
626 arm_compute::TensorInfo aclCellToInputWeightsInfo;
627 arm_compute::TensorInfo aclInputGateBiasInfo;
628 arm_compute::TensorInfo aclProjectionWeightsInfo;
629 arm_compute::TensorInfo aclProjectionBiasInfo;
630 arm_compute::TensorInfo aclCellToForgetWeightsInfo;
631 arm_compute::TensorInfo aclCellToOutputWeightsInfo;
633 arm_compute::TensorInfo aclInputLayerNormWeightsInfo;
634 arm_compute::TensorInfo aclForgetLayerNormWeightsInfo;
635 arm_compute::TensorInfo aclCellLayerNormWeightsInfo;
636 arm_compute::TensorInfo aclOutputLayerNormWeightsInfo;
646 aclInputGateBiasInfo = BuildArmComputeTensorInfo(paramsInfo.
GetInputGateBias());
648 lstm_params_info.set_cifg_params(&aclInputToInputWeightsInfo,
649 &aclRecurrentToInputWeightsInfo,
651 &aclInputGateBiasInfo);
658 aclProjectionBiasInfo = BuildArmComputeTensorInfo(paramsInfo.
GetProjectionBias());
662 lstm_params_info.set_projection_params(&aclProjectionWeightsInfo,
671 lstm_params_info.set_peephole_params(&aclCellToForgetWeightsInfo, &aclCellToOutputWeightsInfo);
684 lstm_params_info.set_layer_normalization_params(descriptor.
m_CifgEnabled ?
nullptr :
685 &aclInputLayerNormWeightsInfo,
686 &aclForgetLayerNormWeightsInfo,
687 &aclCellLayerNormWeightsInfo,
688 &aclOutputLayerNormWeightsInfo);
698 for (
unsigned int i = 0; i != maxTime; ++i)
703 arm_compute::ITensorInfo* outputLSTM;
704 arm_compute::ITensorInfo* inputLSTM;
715 TensorShape inputShapeShrink({inputShape[1], inputShape[2]});
716 TensorShape outputShapeShrink({outputShape[1], outputShape[2]});
718 auto acl_input_shape_shrink = BuildArmComputeTensorShape(inputShapeShrink);
719 auto acl_output_shape_shrink = BuildArmComputeTensorShape(outputShapeShrink);
721 const_cast<arm_compute::TensorInfo*
>(&aclInputInfo)->set_tensor_shape(acl_input_shape_shrink);
722 inputLSTM =
const_cast<arm_compute::TensorInfo*
>(&aclInputInfo);
724 const_cast<arm_compute::TensorInfo*
>(&aclOutputInfo)->set_tensor_shape(acl_output_shape_shrink);
725 outputLSTM =
const_cast<arm_compute::TensorInfo*
>(&aclOutputInfo);
734 TensorShape inputShapeShrink({inputShape[1], inputShape[2]});
735 auto acl_input_shape_shrink = BuildArmComputeTensorShape(inputShapeShrink);
736 aclPermuteOutInfo.set_tensor_shape(acl_input_shape_shrink);
737 inputLSTM = &aclPermuteOutInfo;
739 outputLSTM =
const_cast<arm_compute::ITensorInfo*
>(concatInputsTensorInfosPtr[i]);
744 inputLSTM = splitterOutputsTensorInfosPtr[i];
745 outputLSTM =
const_cast<arm_compute::ITensorInfo*
>(concatInputsTensorInfosPtr[i]);
748 statusLSTM = arm_compute::NEQLSTMLayer::validate(inputLSTM,
749 &aclInputToForgetWeightsInfo,
750 &aclInputToCellWeightsInfo,
751 &aclInputToOutputWeightsInfo,
752 &aclRecurrentToForgetWeightsInfo,
753 &aclRecurrentToCellWeightsInfo,
754 &aclRecurrentToOutputWeightsInfo,
755 &aclForgetGateBiasInfo,
757 &aclOutputGateBiasInfo,
759 &aclOutputStateInInfo,
760 &aclCellStateOutInfo,
761 &aclOutputStateOutInfo,
772 TensorShape shapeExpandTimeMajor({1, shape[0], shape[1]});
773 TensorShape shapeExpandBatchMajor({shape[0], 1, shape[1]});
776 concatOutputTensorInfo.SetShape(timeMajorShapeOutput);
777 arm_compute::TensorInfo aclConcatOutputTensorInfo= BuildArmComputeTensorInfo(concatOutputTensorInfo);
781 for (
unsigned int i = 0; i < maxTime; ++i)
783 auto acl_shape_expand = BuildArmComputeTensorShape(shapeExpandTimeMajor);
784 concatInputsTensorInfos[i].set_tensor_shape(acl_shape_expand);
787 unsigned int aclAxisConcat = CalcAclAxis(numberDimensions, dimension);
790 statusConcat = arm_compute::NEConcatenateLayer::validate(concatInputsTensorInfosPtr,
791 &aclConcatOutputTensorInfo,
796 statusConcat = arm_compute::NEConcatenateLayer::validate(concatInputsTensorInfosPtr,
807 const_cast<arm_compute::TensorInfo*
>(&aclInputInfo)->set_tensor_shape(
808 BuildArmComputeTensorShape(shapeExpandBatchMajor));
812 const_cast<arm_compute::TensorInfo*
>(&aclInputInfo)->set_tensor_shape(
813 BuildArmComputeTensorShape(shapeExpandTimeMajor));
825 statusPermute2 = arm_compute::NEPermute::validate(&aclConcatOutputTensorInfo,
827 arm_compute::PermutationVector(0U, 2U, 1U));
831 statusPermute2 = arm_compute::NEPermute::validate(concatInputsTensorInfosPtr[0],
833 arm_compute::PermutationVector(0U, 2U, 1U));
837 auto okCode = arm_compute::ErrorCode::OK;
838 if (statusPermute1.error_code() == okCode &&
839 statusSplit.error_code() == okCode &&
840 statusLSTM .error_code() == okCode &&
841 statusConcat.error_code() == okCode &&
842 statusPermute2.error_code() == okCode)
845 "All Unidirectional Sequence LSTM layer validate status OK.");
850 "Unidirectional Sequence LSTM layer validate status failed.");
854 void NeonUnidirectionalSequenceLstmWorkload::FreeUnusedTensors()
856 FreeTensorIfUnused(m_InputToInputWeightsTensor);
857 FreeTensorIfUnused(m_InputToForgetWeightsTensor);
858 FreeTensorIfUnused(m_InputToCellWeightsTensor);
859 FreeTensorIfUnused(m_InputToOutputWeightsTensor);
860 FreeTensorIfUnused(m_RecurrentToInputWeightsTensor);
861 FreeTensorIfUnused(m_RecurrentToForgetWeightsTensor);
862 FreeTensorIfUnused(m_RecurrentToCellWeightsTensor);
863 FreeTensorIfUnused(m_RecurrentToOutputWeightsTensor);
864 FreeTensorIfUnused(m_CellToInputWeightsTensor);
865 FreeTensorIfUnused(m_CellToForgetWeightsTensor);
866 FreeTensorIfUnused(m_CellToOutputWeightsTensor);
867 FreeTensorIfUnused(m_InputGateBiasTensor);
868 FreeTensorIfUnused(m_ForgetGateBiasTensor);
869 FreeTensorIfUnused(m_CellBiasTensor);
870 FreeTensorIfUnused(m_OutputGateBiasTensor);
871 FreeTensorIfUnused(m_ProjectionWeightsTensor);
872 FreeTensorIfUnused(m_ProjectionBiasTensor);
873 FreeTensorIfUnused(m_InputLayerNormWeightsTensor);
874 FreeTensorIfUnused(m_ForgetLayerNormWeightsTensor);
875 FreeTensorIfUnused(m_CellLayerNormWeightsTensor);
876 FreeTensorIfUnused(m_OutputLayerNormWeightsTensor);
bool m_ProjectionEnabled
Enable/disable the projection layer.
A ViewsDescriptor for the SplitterLayer.
const TensorShape & GetShape() const
float m_ClippingThresProj
Clipping threshold value for the projection.
uint32_t GetNumDimensions() const
Get the number of dimensions.
virtual void Execute() const override
bool m_TimeMajor
Enable/disable time major.
Copyright (c) 2021 ARM Limited and Contributors.
std::set< unsigned int > ComputeSplitAxis(const armnn::SplitterDescriptor &desc, const TensorShape &input)
void SetShape(const TensorShape &newShape)
float m_ForgetIntermediateScale
Forget intermediate quantization scale.
std::vector< TensorInfo > m_InputTensorInfos
int32_t m_HiddenStateZeroPoint
Hidden State zero point.
float m_CellIntermediateScale
Cell intermediate quantization scale.
An LstmDescriptor for the LstmLayer.
Status SetViewSize(uint32_t view, uint32_t coord, uint32_t value)
Set the size of the views.
DataType GetDataType() const
An OriginsDescriptor for the ConcatLayer.
bool m_PeepholeEnabled
Enable/disable peephole.
arm_compute::Status NeonUnidirectionalSequenceLstmWorkloadValidate(const TensorInfo &input, const TensorInfo &outputStateIn, const TensorInfo &cellStateIn, const TensorInfo &outputStateOut, const TensorInfo &cellStateOut, const TensorInfo &output, const UnidirectionalSequenceLstmDescriptor &descriptor, const LstmInputParamsInfo ¶msInfo)
float m_InputIntermediateScale
Input intermediate quantization scale.
armnn::TensorShape GetTensorShape(unsigned int numberOfBatches, unsigned int numberOfChannels, unsigned int height, unsigned int width, const armnn::DataLayout dataLayout)
std::vector< TensorInfo > m_OutputTensorInfos
float m_ClippingThresCell
Clipping threshold value for the cell state.
float m_HiddenStateScale
Hidden State quantization scale.
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).
void SetConcatAxis(unsigned int concatAxis)
Set the concatenation axis value.
uint32_t GetNumDimensions() const
Get the number of dimensions.
#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC(name, desc, infos, guid)
NeonUnidirectionalSequenceLstmWorkload(const UnidirectionalSequenceLstmQueueDescriptor &descriptor, const WorkloadInfo &info)
bool m_LayerNormEnabled
Enable/disable layer normalization.
void InitializeArmComputeTensorData(arm_compute::Tensor &tensor, const ConstTensorHandle *handle)
Contains information about TensorInfos of a layer.
unsigned int GetConcatAxis() const
Get the concatenation axis value.
#define ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID(name, guid)
Status SetViewOriginCoord(uint32_t view, uint32_t coord, uint32_t value)
Set the view origin coordinates.
Status SetViewOriginCoord(uint32_t view, uint32_t coord, uint32_t value)
Set the view origin coordinates.
float m_OutputIntermediateScale
Output intermediate quantization scale.