Fix bidirectional sequence RNN crash when auxiliary input is omitted The crash would happen if auxiliary inputs were provided with a shape with less than 3 dimensions. This is the case when marking optional input as omitted. The tests weren't catching this behaviour because they set three- or two-dimensional shape consisting of zeros instead of just one-dimensional zero. The change modifies the tests so that they use one-dimensional shape. Fix: 135242001 Test: NeuralNetworksTest_static Change-Id: I47168d6a59445d2591a3c25ce7bbd4e17e6b2547 Merged-In: I47168d6a59445d2591a3c25ce7bbd4e17e6b2547 (cherry picked from commit 66ac07117146b77d9be8e72c6e615dea1adc9a64)
diff --git a/common/operations/BidirectionalSequenceRNN.cpp b/common/operations/BidirectionalSequenceRNN.cpp index 0e8bc6d..32ab00f 100644 --- a/common/operations/BidirectionalSequenceRNN.cpp +++ b/common/operations/BidirectionalSequenceRNN.cpp
@@ -168,12 +168,18 @@ const uint32_t maxTime = getSizeOfDimension(inputShape, 0); const uint32_t batchSize = getSizeOfDimension(inputShape, 1); const uint32_t inputSize = getSizeOfDimension(inputShape, 2); - const uint32_t auxInputSize = getSizeOfDimension(auxInputShape, 2); + uint32_t auxInputSize = 0; + if (hasAuxInputs) { + auxInputSize = getSizeOfDimension(auxInputShape, 2); + } const uint32_t fwNumUnits = getSizeOfDimension(fwWeightsShape, 0); const uint32_t bwNumUnits = getSizeOfDimension(bwWeightsShape, 0); Shape fixedTimeInputShape = removeFirstDim(inputShape); - Shape fixedTimeAuxInputShape = removeFirstDim(auxInputShape); + Shape fixedTimeAuxInputShape = auxInputShape; + if (hasAuxInputs) { + fixedTimeAuxInputShape = removeFirstDim(auxInputShape); + } // Create an additional buffer to store a hidden state between steps. std::vector<T> tempHiddenState(batchSize * fwNumUnits);