Description
Hey,
I've been looking into the Vector Linearization transformation and hit a few issues. The current implementation uses the Conversion pattern driver and mostly makes every operation with a multi-dimensional vector type illegal using this target method. I see a couple of issues with this:
- If an operation is set as illegal but we don't have a conversion pattern for it or existing conversion patterns fail for some reason, the whole linearization conversion will fail. This will happen even when using
applyPartialConversion
because the target method mentioned above will explicit set operations as illegal. To give you a concrete example, I'm currently hitting a conversion error because scalarvector.insert
operations are not supported:
test2.mlir:13:12: error: failed to legalize operation 'vector.insert' that was explicitly marked illegal
%8 = vector.insert %7, %cst [0, 0] : f32 into vector<16x8xf32>
I hit more issues with other ops. Note that not linearizing an n-D operation shouldn't be a big deal as we have lowering patterns to LLVM that can handle multi-dimensional vectors so it should be fine to continue the compilation regardless or any implementation gaps in this pass.
- The linearization "conversion" is similar to other transformations that we have in the Vector dialect and are implemented as simple IR rewrites which can be applied using the greedy pattern rewriter driver. However, since we are using the conversion driver for vector linearization, it can't be composed with these IR rewrites. I think the idea of using the type converter and target to model the n-D -> 1-D vector type conversion is fine but this kind of vector "reshape" transformations are common in different vector rewrites and we don't use the conversion infrastructure for them.
All in all, I'm really excited to see the progress we are making in this transformation. I think it's reaching a point where we can start using it more broadly and make it more composable with other existing vector rewrites. As such, we may want to consider moving the current Conversion based implementation to a simpler IR rewrite. I'd love to hear what others think!
cc: @newling, @Hardcode84, @banach-space