Skip to content

Commit

Permalink
Add verifier for concat op (llvm#1099)
Browse files Browse the repository at this point in the history
* Add check-onnx-backend to Mac CI. (llvm#1069)

* Add check-onnx-backend to Mac CI.

Signed-off-by: Ettore Tiotto <etiotto@ca.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Additional Docker help and split README for easier reading (llvm#1084)

* initial docker documentation

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* split README with no redundant place for info

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* update

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* update

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* update

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* update

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* update

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* respond to suggestions

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* specify that onnx-mlir.py script generates only code suitable to be exec in Linux and/or Docker env

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* fix checkdocs

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* responded to review suggestion on onnx-mlir --help

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* use ONNX-MLIR everywhere

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* add verify for concat

Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* check all inputs

Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Support filtering out lit tests based on targets (llvm#1087)

Currently we ignore what targets llvm was built for in the lit tests, but recent changes to onnx-mlir explicitly initialize the available targets.
This makes the corresponding change to the lit configuration, so that we can filter out the lit tests based on the available targets.

Signed-off-by: Stella Stamenova <stilis@microsoft.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Switch URLs to use main instead of master (llvm#1094)

Signed-off-by: Charles Volzka <cjvolzka@us.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Fix MacOS build badge (llvm#1092)

Signed-off-by: Gong Su <gong_su@hotmail.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* onnx-mlir.py warning about binary output (.so and .jar) (llvm#1090)

not directly usable if host is not Linux

Signed-off-by: Gong Su <gong_su@hotmail.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Make the doc example obey ONNX_MLIR_BUILD_TESTS (llvm#1083)

* Make the doc example obey ONNX_MLIR_BUILD_TESTS

Currently, ONNX_MLIR_BUILD_TESTS controls EXCLUDE_FROM_ALL, however, the targets added through add_executable will always build. We follow the llvm pattern and explicitly set EXCLUDE_FROM_ALL in the add_onnx_mlir_executable function if it is set for the directory, so that add_executable targets don't always build.

Signed-off-by: Stella Stamenova <stilis@microsoft.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Explicitly install into lib on all systems (llvm#1088)

Signed-off-by: Gong Su <gong_su@hotmail.com>

Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* add check (llvm#1098)

Signed-off-by: Tong Chen <chentong@us.ibm.com>

Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* fix typos and add ssh-client to dockerfile (llvm#1096)

* fix typos and add ssh-client to dockerfile

Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* sync doc and script

Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Emit print statement only when the verbose option is in effect. (llvm#1097)

Signed-off-by: Ettore Tiotto <etiotto@ca.ibm.com>

Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* format & refine code by request

Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Support older versions 6, 11, 12 for Clip Op (llvm#1100)

Signed-off-by: Tung D. Le <tung@jp.ibm.com>

Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* using front to get first input

Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* add 3 lit test for concat  verifier

Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* add newline

Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Add check-onnx-backend to Mac CI. (llvm#1069)

* Add check-onnx-backend to Mac CI.

Signed-off-by: Ettore Tiotto <etiotto@ca.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Additional Docker help and split README for easier reading (llvm#1084)

* initial docker documentation

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* split README with no redundant place for info

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* update

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* update

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* update

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* update

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* update

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* respond to suggestions

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* specify that onnx-mlir.py script generates only code suitable to be exec in Linux and/or Docker env

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* fix checkdocs

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* responded to review suggestion on onnx-mlir --help

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>

* use ONNX-MLIR everywhere

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Switch URLs to use main instead of master (llvm#1094)

Signed-off-by: Charles Volzka <cjvolzka@us.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Fix MacOS build badge (llvm#1092)

Signed-off-by: Gong Su <gong_su@hotmail.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* fix typos and add ssh-client to dockerfile (llvm#1096)

* fix typos and add ssh-client to dockerfile

Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* sync doc and script

Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Update document (llvm#1077)

* create

Signed-off-by: Tong Chen <chentong@us.ibm.com>

* delete HowTOAddAnOperation.md

Signed-off-by: Tong Chen <chentong@us.ibm.com>

* modify testing

Signed-off-by: Tong Chen <chentong@us.ibm.com>

* create

Signed-off-by: Tong Chen <chentong@us.ibm.com>

* delete HowTOAddAnOperation.md

Signed-off-by: Tong Chen <chentong@us.ibm.com>

* modify testing

Signed-off-by: Tong Chen <chentong@us.ibm.com>

* fix

Signed-off-by: Tong Chen <chentong@us.ibm.com>

* create

Signed-off-by: Tong Chen <chentong@us.ibm.com>

* add comment

Signed-off-by: Tong Chen <chentong@us.ibm.com>

* delete HowTOAddAnOperation.md

Signed-off-by: Tong Chen <chentong@us.ibm.com>

* modify testing

Signed-off-by: Tong Chen <chentong@us.ibm.com>

* fix

Signed-off-by: Tong Chen <chentong@us.ibm.com>

* create

Signed-off-by: Tong Chen <chentong@us.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Update LLVM level (llvm#1095)

* Update LLVM level to 700997aef8c1f2f08c9ac5fca61650b57a01e8b1

Signed-off-by: Ettore Tiotto <etiotto@ca.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Pass a type converter to all ONNX operations. (llvm#1102)

Signed-off-by: Ettore Tiotto <etiotto@ca.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Nuke KrnlDummyCastOp now that we use MLIR's UnrealizedConversionCastOp (llvm#1103)

* Nuke KrnlDummyCastOp now that we use MLIR's UnrealizedConversionCastOp

Signed-off-by: Ettore Tiotto <etiotto@ca.ibm.com>

* Remove a dependency in src/Dialect/Krnl/CMakeList.txt.  Regenerate docs via 'ninja onnx-mlir-docs'.

Signed-off-by: Ettore Tiotto <etiotto@ca.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Add --emitObj option to onnx-mlir (llvm#1104)

Signed-off-by: Ettore Tiotto <etiotto@ca.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* fix warnings (llvm#1093)

Signed-off-by: Ian Bearman <ianb@microsoft.com>

Co-authored-by: Stella Stamenova <stilis@microsoft.com>
Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Add -march option to onnx-mlir (llvm#1107)

Signed-off-by: Ettore Tiotto <etiotto@ca.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Fix Doc spelling and broken links, removed warnings about using main (llvm#1106)

* removed warning about main vs master in CONTRIBUTING, fixed links and spelling mistakes

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>
Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

* Update BuildONNX.md

Signed-off-by: Ethan Wang <ywan2928@uwo.ca>

Co-authored-by: Ettore Tiotto <etiotto@ca.ibm.com>
Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
Co-authored-by: Stella Stamenova <stilis@microsoft.com>
Co-authored-by: Charles Volzka <42243335+cjvolzka@users.noreply.github.com>
Co-authored-by: gongsu832 <gong_su@hotmail.com>
Co-authored-by: chentong319 <chentong@us.ibm.com>
Co-authored-by: Tung D. Le <tung@jp.ibm.com>
Co-authored-by: Ian Bearman <ian.bearman@live.com>
  • Loading branch information
9 people committed Jan 21, 2022
1 parent 3594fbb commit 334f3de
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/BuildONNX.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Current thread 0x0000000107919e00 (most recent call first):

```shell
% export no_proxy="*"
```
```
62 changes: 42 additions & 20 deletions src/Dialect/ONNX/ONNXOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2687,6 +2687,48 @@ LogicalResult ONNXConstantOp::inferShapes(
// Concat
//===----------------------------------------------------------------------===//

static LogicalResult verify(ONNXConcatOp op) {
ONNXConcatOpAdaptor operandAdaptor(op);
// Check all inputs.
for (const auto &operand : operandAdaptor.getOperands()) {
if (!hasShapeAndRank(operand)) {
// Won't be able to do any checking at this stage.
return success();
}
}
// Checking value of axis parameter.
auto commonType =
operandAdaptor.getOperands().front().getType().cast<RankedTensorType>();
ArrayRef<int64_t> commonShape = commonType.getShape();
int64_t commonRank = commonShape.size();
int64_t axisIndex = op.axis();
if (axisIndex < 0)
axisIndex = commonRank + axisIndex;
if (axisIndex >= commonRank)
return op->emitError("Concat axis value out of bound");

for (const auto &operand : operandAdaptor.getOperands()) {
ArrayRef<int64_t> currShape =
operand.getType().cast<RankedTensorType>().getShape();
if ((int64_t)currShape.size() != commonRank)
return op->emitError("Concat input must all have the same rank");
for (int j = 0; j < commonRank; ++j) {
if (j == axisIndex)
continue;
if (currShape[j] != -1 && commonShape[j] != -1 &&
currShape[j] != commonShape[j]) {
return op->emitError(
"Concat input dimensions must be all identical, "
"except for dimension on the axis of the "
"concatenation. Expected something compatible with: ")
<< commonType << " but got " << operand.getType() << " instead.";
}
}
}

return success();
}

LogicalResult ONNXConcatOp::inferShapes(
std::function<void(mlir::Region &)> doShapeInference) {
// The check of constraints is kept
Expand All @@ -2711,26 +2753,6 @@ LogicalResult ONNXConcatOp::inferShapes(
axisAttr(IntegerAttr::get(builder.getIntegerType(64, /*isSigned=*/true),
APInt(64, /*value=*/axisIndex, /*isSigned=*/true)));
}
if (axisIndex >= commonRank)
return emitError("Concat axis value out of bound");

for (int i = 1; i < inputNum; ++i) {
auto currShape =
getOperand(i).getType().cast<RankedTensorType>().getShape();
if ((int64_t)currShape.size() != commonRank)
return emitError("Concat input must all have the same rank");
for (int j = 0; j < commonRank; ++j) {
if (j == axisIndex) {
} else if (currShape[j] != -1 && commonShape[j] != -1 &&
currShape[j] != commonShape[j]) {
return emitError("Concat input dimensions must be all identical, "
"except for dimension on the axis of the "
"concatenation. Expected something compatible with: ")
<< commonType << " but got " << getOperand(i).getType()
<< " instead.";
}
}
}

ONNXConcatOpAdaptor operandAdaptor(*this);
ONNXConcatOpShapeHelper shapeHelper(this);
Expand Down
1 change: 1 addition & 0 deletions src/Dialect/ONNX/ONNXOps.td.inc
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ def ONNXConcatOp:ONNX_Op<"Concat",
return {20};
}
}];
let verifier = [{ return ::verify(*this); }];
}

def ONNXConcatFromSequenceOp:ONNX_Op<"ConcatFromSequence",
Expand Down
24 changes: 24 additions & 0 deletions test/mlir/onnx/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,27 @@ func @test_depth_to_space_default(%arg0 : tensor<1x256x8x16xf32>) -> tensor<1x16
%0 = "onnx.DepthToSpace"(%arg0) {blocksize = 7 : si64} : (tensor<1x256x8x16xf32>) -> tensor<1x16x32x64xf32>
"std.return"(%0) : (tensor<1x16x32x64xf32>) -> ()
}

// -----

func @test_concat_verifier_1(%arg0 : tensor<5x5x1x32xf32>, %arg1 : tensor<5x5x3x32xf32>, %arg2 : tensor<5x5x5x32xf32>) -> tensor<*xf32> {
// expected-error @+1 {{Concat axis value out of bound}}
%1 = "onnx.Concat"(%arg0, %arg1, %arg2) { axis = 4 : si64} : (tensor<5x5x1x32xf32>, tensor<5x5x3x32xf32>, tensor<5x5x5x32xf32>) -> tensor<*xf32>
"std.return"(%1) : (tensor<*xf32>) -> ()
}

// -----

func @test_concat_verifier_2(%arg0 : tensor<5x5x1x32xf32>, %arg1 : tensor<5x5x3x32xf32>, %arg2 : tensor<5x5x32xf32>) -> tensor<*xf32> {
// expected-error @+1 {{Concat input must all have the same rank}}
%1 = "onnx.Concat"(%arg0, %arg1, %arg2) { axis = 2 : si64} : (tensor<5x5x1x32xf32>, tensor<5x5x3x32xf32>, tensor<5x5x32xf32>) -> tensor<*xf32>
"std.return"(%1) : (tensor<*xf32>) -> ()
}

// -----

func @test_concat_verifier_3(%arg0 : tensor<5x5x1x32xf32>, %arg1 : tensor<5x5x3x32xf32>, %arg2 : tensor<5x5x5x32xf32>) -> tensor<*xf32> {
// expected-error @+1 {{Concat input dimensions must be all identical, except for dimension on the axis of the concatenation. Expected something compatible with: 'tensor<5x5x1x32xf32>' but got 'tensor<5x5x3x32xf32>' instead.}}
%1 = "onnx.Concat"(%arg0, %arg1, %arg2) { axis = 1 : si64} : (tensor<5x5x1x32xf32>, tensor<5x5x3x32xf32>, tensor<5x5x5x32xf32>) -> tensor<*xf32>
"std.return"(%1) : (tensor<*xf32>) -> ()
}
1 change: 1 addition & 0 deletions utils/gen_onnx_mlir.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
'AveragePool',
'CategoryMapper',
'Compress',
'Concat',
'Conv',
'DepthToSpace',
'Expand',
Expand Down

0 comments on commit 334f3de

Please sign in to comment.