This adds a parameter SupplementalPatterns in tablegen class Pattern for
postprocessing code. For example, this can be used to ensure ops are
placed in the correct device by copying the atttributes that decide
devicement placement in Tensorflow dialect to prevent performance
regression.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
This is unfortunately not safe in general, the same named attribute may mean different things etc. Now having a postprocess option where it could be opted in, that we could do.
@jpienaar @rriddle @antiagainst this change is required to fix a performance issue in Tensorflow. Please let me know if it makes sense to you. Thanks.
(ugh sorry forgot to hit send!)
Overall looks good, just wanted to check on restrictions/ordering.
mlir/docs/DeclarativeRewrites.md | ||
---|---|---|
696 | OOC why not just have single post-process hook that points to a function? This does look useful for reusing though. And allow for different API's for post-processing. Do these execute in the order mentioned here? | |
mlir/include/mlir/IR/PatternBase.td | ||
109 | Invoke additional code on ... ? Actually what restrictions re here? Does this allow arbitrary changes to source and targets ops? | |
mlir/tools/mlir-tblgen/RewriterGen.cpp | ||
1108 | supplementary |
mlir/docs/DeclarativeRewrites.md | ||
---|---|---|
696 |
I'm not sure how a post-process hook works, but the number of post-processing patterns we need for each rewrite varies, and a pattern may either return mlir::OpResult or mlir::Instruction. Below is an example in Tensorflow, def CopyAttrs2: NativeCodeCallVoid<"CopyAttributes($0, $1)">; def CopyAttrs3: NativeCodeCallVoid<"CopyAttributes($0, $1.getOwner())">; def HashTableAndInitializeTableToV2 : Pat< (TF_InitializeTableFromTextFileOp:$src (TF_HashTableOp $container, $shared_name, $use_node_name_sharing, $key_dtype, $value_dtype), $filename, $key_index, $value_index, $vocab_size, $delimiter, $offset), (TF_InitializeTableFromTextFileV2Op:$dest1 (TF_HashTableV2Op:$dest2 $container, $shared_name, $use_node_name_sharing, $key_dtype, $value_dtype), $filename, $key_index, $value_index, $vocab_size, $delimiter, $offset), [], [(CopyAttrs2 $src, $dest1), (CopyAttrs3 $src, $dest2)]>; Would it be easy to implement this example with a function?
Yes patterns are executed in the specified order. I've updated the example to make it clearer.
Yes they are. I've added nested patterns in the example. | |
mlir/include/mlir/IR/PatternBase.td | ||
109 |
Done.
I'm not aware of any restrictions other than their results will never be used to replace source patterns. |
mlir/docs/DeclarativeRewrites.md | ||
---|---|---|
696 | FYI I've committed this change as this is need to unblock our work in Tensorflow. Let me know if you think having a post-process hook that points to a function is a better solution and I'll address that in another patch. Thanks! |
Fixed a typo in the doc in commit https://reviews.llvm.org/rG3c5b4dabdc06dd380391ac965b16961610c0db77.
This broke the build (you can see it in the pre-merge build log on this revision as well, but you should have got some emails already)
Thanks Mehdi! Applogy for the inconvenience. I've fixed the test failure and relanded the change in https://reviews.llvm.org/rGd22965f0d623392fdf87e5a09a0276aa70e8dfed
OOC why not just have single post-process hook that points to a function?
This does look useful for reusing though. And allow for different API's for post-processing.
Do these execute in the order mentioned here?
Is nesting of these supported? (e.g., (CopyAttrFoo (GetParent $src), $dest))