-
Notifications
You must be signed in to change notification settings - Fork 599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GlobalOptimization] 1x1 filter convolutions not converted to matmul #18710
Comments
For %1 = linalg.conv_2d_nchw_fchw {
dilations = dense<1> : tensor<2xi64>,
strides = dense<1> : tensor<2xi64>}
ins(%input, %filter : tensor<5x2x4x5xf32>, tensor<7x2x1x1xf32>) outs(%0 : tensor<5x7x4x5xf32>) -> tensor<5x7x4x5xf32> |
In this case, I think it is best to create a |
What the conv_* to matmul pass should do is not collapse dimensions. It should simply be doing a rewrite of the indexing maps. In particular we have an indexing map of the form
All we are doing is looking at the unit kernel loops (in this case |
The
Convert1x1FilterConvToMatmul
pass currently fails when there is a non-unit batch N dimension. In such cases, the transformation is still possible, and the N dimension should be folded into the M dimension of the matmul. For example:The N dimension of 2 can be collapsed into the M dimension along with the H and W dimensions, and become:
Similarly, for NCHW convolutions, the N dimension of the convolution can be folded into the N dimension of the matmul.
This is addressing the TODO here:
iree/compiler/src/iree/compiler/GlobalOptimization/Convert1X1FilterConv2DToMatmul.cpp
Line 69 in 691aa4f
Dynamic N
The current implementation also bails on dynamic H or W dimensions:
iree/compiler/src/iree/compiler/GlobalOptimization/Convert1X1FilterConv2DToMatmul.cpp
Lines 61 to 64 in 691aa4f
This should be possible now that tensor.expand_shape carries the result shape, since the dynamic output sizes are able to be recovered from the expand_shape result sizes. It would also be good to support this dynamic case while adding support for non-unit N dimensions.
The text was updated successfully, but these errors were encountered: