This is an archive of the discontinued LLVM Phabricator instance.

[mlir][linalg] Add a few unary operations.
ClosedPublic

Authored by bixia on Mar 9 2022, 2:04 PM.

Details

Summary

Add operations abs, ceil, floor, and neg to the C++ API and Python API.

Add test cases.

Diff Detail

Event Timeline

bixia created this revision.Mar 9 2022, 2:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 9 2022, 2:04 PM
bixia requested review of this revision.Mar 9 2022, 2:04 PM

LGTM, but please wait for Nicolas, since this really is his playground ;-)

bixia added a reviewer: gysit.Mar 10 2022, 6:58 AM
gysit added a comment.Mar 10 2022, 7:45 AM

Thanks for adding!

There are also a couple of places on the C++ side that need to be updated.

  1. there is an enum that defines all the Unary function types:

https://github.com/llvm/llvm-project/blob/9fac110bf70896a5411cf57b3ff34fab5798ab78/mlir/include/mlir/Dialect/Linalg/IR/LinalgBase.td#L62
the names have to match the function names used on the Python side!

  1. there is a helper to build the functions:

https://github.com/llvm/llvm-project/blob/9fac110bf70896a5411cf57b3ff34fab5798ab78/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp#L138
it is the counterpart to emitter.py if the operation is generated from the yaml file.

  1. is an example that tests the C++ code generation path

https://github.com/llvm/llvm-project/blob/eb6a3c0c0c71ab44141e71112ecd0a2ae2848037/mlir/test/Dialect/Linalg/generalize-named-polymorphic-ops.mlir#L290

I think it would be great to update the C++ side in the same revision. Doing it in a follow up commit is also fine for me.

bixia updated this revision to Diff 414402.Mar 10 2022, 9:18 AM

Added the operations to C++.

bixia retitled this revision from [mlir][linalg][opdsl] Add a few unary operations. to [mlir][linalg] Add a few unary operations..Mar 10 2022, 9:18 AM
bixia edited the summary of this revision. (Show Details)

Thanks for the review and pointers for the C++ changes! I added the C++ change and modified the PR description. PTAL.

gysit accepted this revision.Mar 10 2022, 9:24 AM

perfect, thanks!

This revision is now accepted and ready to land.Mar 10 2022, 9:24 AM
This revision was automatically updated to reflect the committed changes.