Add MLIR verifier to BConv op
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 258
- Forks
- 35
- PR merge metrics
- No merged PRs in 30d
Description
Since #384 we can make use of the IR verification features of MLIR.
Our BConv op has a few parameter combinations where it can throw during Init or Prepare. In the converter we try to make sure that none of those cases will ever occur, but it would be good to add verification code so that potential errors are already caught during conversion and not at runtime which makes for a much nicer user experience if something goes wrong (especially when relying one some of our experimental features).
Most of the verification is already autogenerated by MLIR based on the attr constraints, but we also have some unsupported cases that depend on the interaction between different attributes [e.g. padding and fused activation functions).
This verification can be done nicely by populating the following verifier boilerplate with the relevant constraints of our TFLite kernel:
diff --git a/larq_compute_engine/mlir/ir/lce_ops.cc b/larq_compute_engine/mlir/ir/lce_ops.cc
index 4283888..9ec481a 100644
--- a/larq_compute_engine/mlir/ir/lce_ops.cc
+++ b/larq_compute_engine/mlir/ir/lce_ops.cc
@@ -47,5 +47,11 @@ LarqDialect::LarqDialect(MLIRContext* context)
#include "larq_compute_engine/mlir/ir/lce_ops.cc.inc"
>();
}
+
+LogicalResult Verify(Bconv2dOp op) {
+ return mlir::success();
+ return op.emitOpError("Something is not correct!");
+}
+
} // namespace TF
} // namespace mlir
diff --git a/larq_compute_engine/mlir/ir/lce_ops.td b/larq_compute_engine/mlir/ir/lce_ops.td
index d45ef14..a5c54ec 100644
--- a/larq_compute_engine/mlir/ir/lce_ops.td
+++ b/larq_compute_engine/mlir/ir/lce_ops.td
@@ -111,6 +111,8 @@ TODO
let results = (outs
TensorOf<[F32, I32, QI8]>:$output
);
+
+ /* let verifier = [{ return Verify(*this); }]; */
}
def LQ_BMaxPool2dOp : LQ_Op<"BMaxPool2d", [NoSideEffect]> {
I am labeling this as a "good first issue" since it is a well scoped problem and we are happy to assist if anyone wants to tackle this.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with larq_compute_engine/mlir/ir/lce_ops.cc and lce_ops.td, then inspect the BConv2d Init and Prepare paths in larq_compute_engine/tflite/kernels/bconv2d.cc. Add the verifier constraints for unsupported attribute combinations, including padding and fused activation interactions, and confirm conversion rejects cases that would otherwise fail at runtime.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100