This is an archive of the discontinued LLVM Phabricator instance.

[mlir][OpDSL] Add `TypeFn` class.
ClosedPublic

Authored by gysit on Dec 7 2021, 4:49 AM.

Details

Summary

This revision introduces a the TypeFn class that similar to the PrimFn class contains an extensible set of type conversion functions. Having the same mechanism for both type conversion functions and arithmetic functions improves code consistency. Additionally, having an explicit function class and function name is a prerequisite to specify a conversion or arithmetic function via attribute. In a follow up commits, we will introduce function attributes to make OpDSL operations more generic. In particular, the goal is to handle signed and unsigned computation in one operations. Today, there is a linalg.matmul and a linalg.matmul_unsigned.

The commit implements the following changes:

  • Introduce the class of type conversion functions TypeFn
  • Replace the hardwired cast and cast_unsigned ops by the TypeFn counterparts
  • Adapt the python and C++ code generation paths to support the new cast operations

Example:

cast(U, A[D.m, D.k])

changes to

TypeFn.cast(U, A[D.m, D.k])

Depends On D115237

Diff Detail

Event Timeline

gysit created this revision.Dec 7 2021, 4:49 AM
gysit requested review of this revision.Dec 7 2021, 4:49 AM
gysit updated this revision to Diff 392361.Dec 7 2021, 5:06 AM

Fix formatting of templated code.

gysit added a comment.Dec 7 2021, 5:16 AM

The name TypeFn and the fact that TypeFn.cast is longer than just cast may be controversial. I am fine with renaming. ConversionFn or TypeConversionFn would be alternatives. Also not that it would be possible to define an alias tf = TypeFn and then write tf.cast. Once OpDSL has support for function attributes we may also redefine the cast function as cast = TypeFnAttrDef(default=TypeFn.cast).

gysit updated this revision to Diff 393982.Dec 13 2021, 11:46 AM

Improve doc.

stellaraccident accepted this revision.Jan 4 2022, 10:15 AM
This revision is now accepted and ready to land.Jan 4 2022, 10:15 AM
gysit updated this revision to Diff 398069.Jan 7 2022, 12:57 AM

Rebase.

This revision was landed with ongoing or failed builds.Jan 7 2022, 4:29 AM
This revision was automatically updated to reflect the committed changes.