Extend the OpDSL syntax with an optional domain function to specify an explicit dimension order. The extension is needed to provide more control over the dimension order instead of deducing it implicitly depending on the formulation of the tensor comprehension. Additionally, the patch also ensures the symbols are ordered according to the operand definitions of the operation.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
I initially planed to have a simpler loop syntax that instead of listing the dimensions as domain parameters would use inspection to set the dimension names according to the induction variable names of the for loop. For example, matrix multiplication would look as follows:
def matmul( A=TensorDef(T, S.M, S.K), B=TensorDef(T, S.K, S.N), C=TensorDef(U, S.M, S.N, output=True)): for m, n, k in domain(): C[m, n] += cast(U, A[m, k]) * cast(U, B[k, n])
However, at least my implementation requires features that are not guaranteed to be implemented by all Python implementations. I thus went for a more verbose syntax initializes the dimensions manually:
for m, n, k in domain(D.m, D.n, D.k):
Quite nice: I didn't know if this was going to work out so easily.
mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml | ||
---|---|---|
19 | Good: the implicit domain inference here was causing uncertainty/surprise for the ordering. | |
mlir/python/mlir/dialects/linalg/opdsl/lang/config.py | ||
147 | Can you also add the collected vs specified to the error message? Actually, I feel that both of these conditions could trigger the same mismatch error message if it opened the full lists. | |
mlir/python/mlir/dialects/linalg/opdsl/lang/dsl.py | ||
141 | The for loop syntax is cute from a DSL standpoint but does introduce some repetition. An I correct in reading this as a free standing statement of: domain(D.m, D.n) Would also work? (With just continuing to use the dims directly in the rest of the body instead of aliasing them to local variables? |
mlir/python/mlir/dialects/linalg/opdsl/lang/dsl.py | ||
---|---|---|
141 | Right I can change to the following syntax: domain(D.m, D.n, D.k) C[D.m, D.n] += A[D.m, D.k] * B[D.k, D.n] It makes the index expressions a bit longer but there is no duplication between induction variables and domain function arguments. I do not have a strong preference and will just change to the version above then. |
Good: the implicit domain inference here was causing uncertainty/surprise for the ordering.