This version takes the real maximum and minimum indices of each affine expressions binding to each dims. So, we can check if the index ranges are valid or not.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
This version can check if the index ranges are in bound of the sizes of dimensions using getStaticMaximumIndex and getStaticMinimumIndex methods. The methods get the appropriate dims and substitude them to Affine Expressions using AffineMap.compose method. For example, if we have (-d0 + d1) and d0 and d1 are from 0 to 1, then the maximum index method has 0 for d0 and 1 for d1 because the negative values get larger as its absolute values are smaller. And, the minimum index method has 1 for d0 and 0 for d1.
This version uses AffineMap.compose to get each affine expressions' constant value, but the map.compose method returns all results of expressions of the map. I tried to make a new compose method returning only the result of the given expression, but it seemed I still need AffineMap.. Is there any way to get the only target expression's value? I tried to use getAffineConstantExpr method, but it did not return the exact result..
mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp | ||
---|---|---|
94 | Ah, like this? | |
98–109 | My idea is something like this: |
mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp | ||
---|---|---|
94 | I meant SmallVectorImpl<int64_t>. | |
98–109 | I'd like to point out this again. They are rare cases. I don't see any use cases of this before. This increases overheads in verifying operations. However, we don't see any such case, which means that we are just adding overheads in verification. I also suspect we won't see them in the near future. Can we add the check when this is really a case? Other concerns on my side:
|
mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp | ||
---|---|---|
520 | Logically, en.value().getDimSize() makes sense only when en.value().isDynamicDim(j) is false. If so, I recommend checking en.value().isDynamicDim(j) before calling en.value().getDimSize(). |
mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp | ||
---|---|---|
520 | If shapedDimSize == 0, any access to this tensor is invalid since # of elements in this tensor is 0. I think we should report an error instead of ignoring this and "continue" to the next dimension. |
- Updating D102305: The final update of static checker for linalg operations with the maximum and minimum indices #
- Enter a brief description of the changes included in this update.
- The first line is used as subject, next lines as comment.
Rebase for sync
mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp | ||
---|---|---|
98–109 | I see. Thanks for letting me the concerns. I just found the case that the startIndices and endIndices might not detect, and wanted to try making the checker as perfect as possible. But my implementation might have other issues as you said.. I thought the parser could simplify all affine expressions, and mod or floordiv might not be used here because I couldn't find such testcases.. | |
520 | Yes, I think it can still be checked as the invalid one even although we don't check if the shapedDimSize == 0 here because of line number 494 of the original code, or line number 530-531 of the current patch. If the DimSize is 0, then the index would be -1, so the conditions would detect it and generate the error message. But, @hanchung and I found a testcase using 0xf32 tensor, so we had to choose to modify the testcase or ignore the case.func @dce_zero_memref(%arg0 : memref<0xf32>, %arg1: tensor<0xf32>) -> tensor<0xf32> { // memref<0x32> is expected to be dce'ed linalg.copy(%arg0, %arg0): memref<0xf32>, memref<0xf32> // tensor<0xf32> cannot be dce'ed %1 = linalg.generic #trait outs(%arg1 : tensor<0xf32>) { ^bb(%0: f32) : linalg.yield %0 : f32 } -> tensor<0xf32> return %1: tensor<0xf32> }@hanchung What do you think about this? |
mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp | ||
---|---|---|
98–109 |
Some could be simplified, but some could not. I looked into some tests of AffineMap and realized it.
They are not well defined I think. We can have them, but we don't recommend it. Actually the case you're trying to check can't be found in the repo right?
Sure thing, feel free to close it. | |
520 | They were come from https://reviews.llvm.org/D85413 I don't have much context about it, but there are some reasons to having it. |
We usually pass SmallVectorImpl as function argument.