[all-commits] [llvm/llvm-project] 51fdd8: [mlir][OpDSL] Add type function attributes.

Tobias Gysi via All-commits all-commits at lists.llvm.org
Fri Feb 25 00:26:23 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 51fdd802c794faf6e5b57cccd6ea181c7f8a83e9
      https://github.com/llvm/llvm-project/commit/51fdd802c794faf6e5b57cccd6ea181c7f8a83e9
  Author: gysit <gysit at google.com>
  Date:   2022-02-25 (Fri, 25 Feb 2022)

  Changed paths:
    M mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt
    M mlir/include/mlir/Dialect/Linalg/IR/Linalg.h
    M mlir/include/mlir/Dialect/Linalg/IR/LinalgBase.td
    M mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml
    M mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td
    M mlir/lib/Dialect/Linalg/IR/CMakeLists.txt
    M mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp
    M mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
    M mlir/python/mlir/dialects/linalg/opdsl/lang/comprehension.py
    M mlir/python/mlir/dialects/linalg/opdsl/lang/config.py
    M mlir/python/mlir/dialects/linalg/opdsl/lang/dsl.py
    M mlir/python/mlir/dialects/linalg/opdsl/lang/emitter.py
    M mlir/python/mlir/dialects/linalg/opdsl/lang/scalar_expr.py
    M mlir/python/mlir/dialects/linalg/opdsl/ops/core_named_ops.py
    M mlir/test/Dialect/Linalg/generalize-named-polymorphic-ops.mlir
    M mlir/test/Integration/Dialect/SparseTensor/taco/tools/mlir_pytaco.py
    M mlir/test/mlir-linalg-ods-gen/test-linalg-ods-yaml-gen.yaml
    M mlir/test/python/dialects/linalg/opdsl/arguments.py
    M mlir/test/python/dialects/linalg/opdsl/assignments.py
    M mlir/test/python/dialects/linalg/opdsl/emit_matmul.py
    M mlir/test/python/dialects/linalg/ops.py
    M mlir/test/python/integration/dialects/linalg/opsrun.py
    M mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp
    M utils/bazel/llvm-project-overlay/mlir/BUILD.bazel

  Log Message:
  -----------
  [mlir][OpDSL] Add type function attributes.

Previously, OpDSL operation used hardcoded type conversion operations (cast or cast_unsigned). Supporting signed and unsigned casts thus meant implementing two different operations. Type function attributes allow us to define a single operation that has a cast type function attribute which at operation instantiation time may be set to cast or cast_unsigned. We may for example, defina a matmul operation with a cast argument:

```
@linalg_structured_op
def matmul(A=TensorDef(T1, S.M, S.K), B=TensorDef(T2, S.K, S.N), C=TensorDef(U, S.M, S.N, output=True),
    cast=TypeFnAttrDef(default=TypeFn.cast)):
  C[D.m, D.n] += cast(U, A[D.m, D.k]) * cast(U, B[D.k, D.n])
```

When instantiating the operation the attribute may be set to the desired cast function:

```
linalg.matmul(lhs, rhs, outs=[out], cast=TypeFn.cast_unsigned)
```

The revsion introduces a enum in the Linalg dialect that maps one-by-one to the type functions defined by OpDSL.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D119718




More information about the All-commits mailing list