We have too many similar operations in Linalg (*_conv_*
, *_matmul_*
) that cannot be decomposed because they were defined in OpDSL.
We discussed about this in the past and the end result is to move it out of OpDSL (Python, YAML), into ODS (table-gen, C++) so that we can common up implementation details (such as broadcast, transpose, quantize, loop order).
There is ongoing work to move all matmul
operations to a common format, with the first patch ([mlir][linalg] Introduce transpose semantic to 'linalg.matmul' ops. by shahidact Ā· Pull Request #104783 Ā· llvm/llvm-project Ā· GitHub) landed and follow ups in development.
Convolutions are currently at about 30 ops and counting, with recent PRs adding more and more ([linalg] Add quantized version of `conv_3d_ncdhw_fcdhw` by ubfx Ā· Pull Request #113953 Ā· llvm/llvm-project Ā· GitHub, [mlir][linalg] Add Grouped Convolution Ops: conv_2d_nhwgc_gfhwc and conv_2d_nhwgc_gfhwc_q by stefankoncarevic Ā· Pull Request #108192 Ā· llvm/llvm-project Ā· GitHub).
Can we have a discussion on how to stop the op explosion and focus on a few operations that we agree is reasonable for such a core dialect?
Here are the discussions I had personally with different people and where my plan stands for the near future:
- No implicit cast, broadcast, transpose, reduction. These can all be represented by affine maps (or attributes), including compute type and quantization.
- There should be only one
matmul
op, onebatch_matmul
and onebatch_reduce_matmul
. No*_matmul_transpose_*
operations should be necessary. Weāre not going to delete any op now, but they should be left over in OpDSL and be removed with it. @mshahid is working on this. matmul
has only 2D operands,batch_matmul
has 3D operands with the outer-most batch,batch_reduce_matmul
has 3D inputs, 2D accumulator, with the outer batch. We could reusematmul
for the latter two above if we can easily validate shapes and affine maps, but thatās not our current goal. Anything else should be implemented as alinalg.generic
or the upcominglinalg.contract
.- Element wise ops with operation attribute. We already had this, but with implicit casts. I added a lot of named ops, which was the wrong thing to do but necessary due to OpDSL. Now @javedabsar will add those to ODS with the right semantics.
- Convolutions have the same issues, but with the addition of loop order (NCWH variations), which can be attributes and C++ implementation detail in ODS. We can use dimensionality to lower ND correctly in C++, which was impossible in OpDSL. Depthwise can also be an attribute.
I want to repeat @stellaraccident words in the latest PR:
āI am sympathetic to the need to have a practical solution for them in short order. Iām also cringing at the addition of technical debt this adds because the project overall doesnāt have a plan for how to manage the expansion.ā
Been there, done that and now Iām trying to undo my mistakes from last year. I want to avoid other people making the same mistakes. This is why we started with matmul
, but we canāt work efficiently while the pile is still growing and people are working against these goals.
So, letās just agree on a goal and everyone follow that goal.