forked from onnx/onnx-mlir
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Diagnose axis out of range for FlattenOp, GatherOp, GatherElementsOp (o…
…nnx#1328) Use the Diagnostic class to diagnose the axis attribute for the ONNX Flatten, Gather and GatherElements operators. Signed-off-by: Ettore Tiotto <[email protected]>
- Loading branch information
Ettore Tiotto
authored
Apr 26, 2022
1 parent
5484243
commit 313928c
Showing
11 changed files
with
195 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
//===---------- Flatten.cpp - Shape Inference for Flatten Op --------------===// | ||
// | ||
// Copyright 2022 The IBM Research Authors. | ||
// | ||
// ============================================================================= | ||
// | ||
// This file implements shape inference for the ONNX Flatten Operator. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/Dialect/ONNX/ShapeInference/ONNXShapeHelper.hpp" | ||
|
||
using namespace mlir; | ||
|
||
namespace onnx_mlir { | ||
|
||
LogicalResult ONNXFlattenOpShapeHelper::computeShape( | ||
ONNXFlattenOpAdaptor operandAdaptor) { | ||
// Get info about input operand. | ||
Value input = operandAdaptor.input(); | ||
auto inputType = input.getType().cast<ShapedType>(); | ||
ArrayRef<int64_t> inputShape = inputType.getShape(); | ||
int64_t inputRank = inputType.getRank(); | ||
int64_t axis = op->axis(); | ||
assert(axis >= -inputRank && axis < inputRank && "Invalid inputRank"); | ||
|
||
// Negative axis means values are counted from the opposite side. | ||
if (axis < 0) | ||
axis += inputRank; | ||
|
||
// Compute outputDims. | ||
DimsExpr outputDims = {LiteralIndexExpr(1), LiteralIndexExpr(1)}; | ||
for (int64_t i = 0; i < axis; ++i) { | ||
if (inputShape[i] == -1) { | ||
outputDims[0] = QuestionmarkIndexExpr(); | ||
break; | ||
} | ||
outputDims[0] = outputDims[0] * LiteralIndexExpr(inputShape[i]); | ||
} | ||
|
||
for (int64_t i = axis; i < inputRank; ++i) { | ||
if (inputShape[i] == -1) { | ||
outputDims[1] = QuestionmarkIndexExpr(); | ||
break; | ||
} | ||
outputDims[1] = outputDims[1] * LiteralIndexExpr(inputShape[i]); | ||
} | ||
|
||
dimsForOutput() = outputDims; | ||
return success(); | ||
} | ||
|
||
} // namespace onnx_mlir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.