[all-commits] [llvm/llvm-project] a96940: [mlir][linalg] regionBuilder for transpose, broadc...

Maksim Levental via All-commits all-commits at lists.llvm.org
Fri Oct 20 14:15:00 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a9694043c9b8625fbe0d1a34bc5afadf380cda97
      https://github.com/llvm/llvm-project/commit/a9694043c9b8625fbe0d1a34bc5afadf380cda97
  Author: Maksim Levental <maksim.levental at gmail.com>
  Date:   2023-10-20 (Fri, 20 Oct 2023)

  Changed paths:
    M mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td
    M mlir/python/mlir/dialects/linalg/__init__.py
    M mlir/test/python/dialects/linalg/ops.py

  Log Message:
  -----------
  [mlir][linalg] regionBuilder for transpose, broadcast (#69742)

Currently, `linalg.transpose` and `linalg.broadcast` can't be emitted
through either the C API or the python bindings (which of course go
through the C API). See
https://discourse.llvm.org/t/how-to-build-linalg-transposeop-in-mlir-pybind/73989/10.

The reason is even though they're named ops, there is no opdsl
`@linalg_structured_op` for them and thus while they can be instantiated
they cannot be passed to
[`mlirLinalgFillBuiltinNamedOpRegion`](https://github.com/llvm/llvm-project/blob/a7cccb9cbb2b9954684cbea37615303a59719973/mlir/lib/CAPI/Dialect/Linalg.cpp#L18).
I believe the issue is they both take a `IndexAttrDef` but
`IndexAttrDef` cannot represent dynamic rank. Note, if I'm mistaken and
there is a way to write the `@linalg_structured_op` let me know.

The solution here simply implements the `regionBuilder` interface which
is then picked up by
[`LinalgDialect::addNamedOpBuilders`](https://github.com/llvm/llvm-project/blob/7557530f428a2f226d8d925c33d527dfcfdcb0c5/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp#L116).

Extension classes are added "by hand" that mirror the API of the
`@linalg_structured_op`s. Note, the extension classes are added to to
`dialects/linalg/__init__.py` instead of
`dialects/linalg/opdsl/ops/core_named_ops.py` in order that they're not
confused for opdsl generators/emitters.




More information about the All-commits mailing list