Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/torch-mlir/Dialect/Torch/IR/GeneratedTorchOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -6670,6 +6670,7 @@ def Torch_AtenMatmulOp : Torch_Op<"aten.matmul", [
printDefaultTorchOp(printer, *this, 2, 1);
}
}];
let hasVerifier = 1;
}

def Torch_AtenMvOp : Torch_Op<"aten.mv", [
Expand Down
23 changes: 23 additions & 0 deletions lib/Dialect/Torch/IR/TorchOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5293,6 +5293,29 @@ LogicalResult ShapeCalculateYieldShapesOp::verify() {
return success();
}

//===----------------------------------------------------------------------===//
// AtenMatmulOp
//===----------------------------------------------------------------------===//

LogicalResult AtenMatmulOp::verify() {

auto lhsType = cast<BaseTensorType>(getSelf().getType());
auto rhsType = cast<BaseTensorType>(getOther().getType());
auto resultType = cast<BaseTensorType>(getResult().getType());

if (lhsType.hasSizes() && rhsType.hasSizes() && resultType.hasSizes()) {
// Get the rank
auto lhsRank = lhsType.getSizes().size();
auto rhsRank = rhsType.getSizes().size();
auto resultRank = resultType.getSizes().size();

if (lhsRank == 1 && rhsRank == 1 && resultRank != 0) {
return emitOpError("1D x 1D matmul should produce a scalar (rank 0)");
}
}
return success();
}

//===----------------------------------------------------------------------===//
// AtenNormScalarOp
//===----------------------------------------------------------------------===//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def emit_with_mutating_variants(key, **kwargs):
emit("aten::mm : (Tensor, Tensor) -> (Tensor)")
emit("aten::_int_mm : (Tensor, Tensor) -> (Tensor)")
emit("aten::addmm : (Tensor, Tensor, Tensor, Scalar, Scalar) -> (Tensor)")
emit("aten::matmul : (Tensor, Tensor) -> (Tensor)")
emit("aten::matmul : (Tensor, Tensor) -> (Tensor)", has_verifier=True)
emit("aten::mv : (Tensor, Tensor) -> (Tensor)")
emit("aten::dot : (Tensor, Tensor) -> (Tensor)", has_canonicalizer=True)
emit("aten::outer : (Tensor, Tensor) -> (Tensor)")
Expand Down
10 changes: 10 additions & 0 deletions test/Dialect/Torch/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,13 @@ func.func @torch.symbolic_int$no_shape_symbols(%arg0: !torch.vtensor<[?],f32>) -
torch.bind_symbolic_shape %arg0, [%int0], affine_map<()[s0] -> (s0)> : !torch.vtensor<[?],f32>
return %arg0 : !torch.vtensor<[?],f32>
}

// -----

func.func @torch.matmul$1d_1d_result_not_scalar(%arg0: !torch.vtensor<[4],f32>, %arg1: !torch.vtensor<[4],f32>)
-> !torch.vtensor<[1],f32> {
// expected-error @+1 {{1D x 1D matmul should produce a scalar (rank 0)}}
%0 = torch.aten.matmul %arg0, %arg1
: !torch.vtensor<[4],f32>, !torch.vtensor<[4],f32> -> !torch.vtensor<[1],f32>
return %0 : !torch.vtensor<[1],f32>
}
Loading