Skip to content

Commit

Permalink
LowerToBackendContract: Explicitly error out on unimplemented operator
Browse files Browse the repository at this point in the history
  • Loading branch information
mgehre-amd committed Mar 16, 2023
1 parent 91cd372 commit e8b9d10
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/Dialect/Torch/Transforms/LowerToBackendContract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,17 @@ static bool satisfiesBackendContract(ModuleOp module,
if (walkResult0.wasInterrupted())
return false;

// Check for unimplemented operators first to give more direct diagnostics.
walkResult0 = module.walk([&](Torch::OperatorOp op) {
if (actuallyEmitDiagnostics) {
op->emitError("unsupported by backend contract: Unimplemented operator '"
+ op.getName() + "'");
}
return WalkResult::interrupt();
});
if (walkResult0.wasInterrupted())
return false;

// Check all the types of all Value's in the program and the legality of all
// the ops.
//
Expand Down
10 changes: 10 additions & 0 deletions test/Dialect/Torch/verify-backend-contract-unimplemented-op.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: torch-mlir-opt -torch-verify-backend-contract-no-decompositions -split-input-file -verify-diagnostics %s
func.func @forward(%arg0: !torch.vtensor<[3,5],f32>) -> !torch.vtensor {
%none = torch.constant.none
%0 = torch.tensor_static_info_cast %arg0 : !torch.vtensor<[3,5],f32> to !torch.vtensor<*,f32>
%1 = torch.copy.to_tensor %0 : !torch.tensor<*,f32>
// expected-error @+1 {{unsupported by backend contract: Unimplemented operator 'an.unimplemented.op'}}
%2 = torch.operator "an.unimplemented.op"(%1, %1, %none) : (!torch.tensor<*,f32>, !torch.tensor<*,f32>, !torch.none) -> !torch.tensor
%3 = torch.copy.to_vtensor %2 : !torch.vtensor
return %3 : !torch.vtensor
}

0 comments on commit e8b9d10

Please sign in to comment.