Don't assert fail on strided memrefs when dropping unit dims.
Instead just leave them unchanged.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Time | Test | |
---|---|---|
100 ms | x64 windows > Clang.Index::complete-preamble.cpp |
Event Timeline
mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp | ||
---|---|---|
289 | This seems a bit hard to follow. Can we instead make this return an Optional<...> and handle the case where nothing changes at the call site? |
mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp | ||
---|---|---|
289 | The caller takes these data structures and uses them at quite a few places and most of them need 1:1 mappings with the original input/outputs, so the alternative of returning an Optional would move this code to the caller. The caller would still need to generate this same information. There's no simple way to change that due to the caller needing the same number of data structures as the original operation had. Given that this information needs to be generated regardless, I think it's better to just return it in here rather than have an additional if/else statement in the caller. This function can already return this NoOp like result also, so this doesn't result in a situation for the caller that didn't exist before. |
mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp | ||
---|---|---|
289 | I find it hard to maintain/read code if there is a whole data structure that models the no-op. It is much cleaner IMO to have to caller explicitly deal with the no-op situation than having a no-op being encoded in data structure values. I dont really see too much of an if-then-else situation on the caller side. Even if it does, it is then explicit in code that the caller is dealing with the no-op situation. |
I added some minor comments that should be orthogonal to where the nop handling happens.
mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp | ||
---|---|---|
291–296 | nit: AFAIK there is a constructor taking a single affine expression so the makeArrayRef can be dropped. It may also be an idea to start from an identity map to make this a bit simpler. However, since we need AffineMapAttr there is probably no substantially shorter solution here... | |
299–300 | Can we use the indexingMap directly in this case? | |
308 | nit: As long as this is the single instance I would inline the neutral result generation. | |
321–322 | nit: I would probably delete the assertion since we handle the case above? | |
mlir/test/Dialect/Linalg/drop-unit-extent-dims.mlir | ||
795 | nit: %0 should probably be replaced by a variable matching the collapse_shape result |
mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp | ||
---|---|---|
289 | I'm doing it as you wish, but just to note, this is not making the caller handle the no-op situation. This function handles the no-op case. Then there is a separate unsupported case that results in a no-op. This is making the caller handle the unsupported situation while this function handles the no-op situation. | |
291–296 | I did as you suggested for the single affine expression. I did not see any way to start with an identity map, as a given identity map needed to be N->N for any value N in [0,D), and the given functionalities for identity maps created a mapping for every value in a suffix of [0,D) only. |
This seems a bit hard to follow. Can we instead make this return an Optional<...> and handle the case where nothing changes at the call site?