You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I also found that there are some issues in canonicalization pass. Some tensor.cast op will be created, and raising errors like error: 'tensor.cast' op operand type 'tensor<1x513xi16>' and result type 'tensor<513xi16>' are cast incompatible.
The issue in step one is that we are lacking a tensor_reshape like operation. I tried tensor::CastOp and it complains about 'tensor<1xf32>' and result type 'tensor' are cast incompatible. One workaround is to cast it twice, but I don’t think this is the way to go.
side question:
I can not trigger the pattern with simpler example. I ran mlir-opt -canonicalize a.mlir, but it seems that it never enter the pattern. It did not dump anything. Is there a way to trigger it?
Definitely doing this as a cast is invalid. (you hit the same error message, but the issue is different).
From my experimentation this is all coming from concatenate and slice operations that are inserting/taking unit-dim slices. The way to go is to have rank-reducing versions of these generated to begin with. Then you could insert a linalg.tensor_reshape for those.
The rank-reducing versions are not handled properly in IREE, and there are some canonicalization patterns missing in different places to make thse work correctly. Here is the WIP changes to core I plan to work on this week MaheshRavishankar/llvm-project@1eae450 . I can assign this bug to myself, it will take a few steps to plumb this through.
I skimmed through that discourse thread but given the discussion I
pattern-matched it as a "mhlo semantics problem".
The CastOp is meant for the ? <-> static casting case, tha canonicalization
pattern is missing the rank-reduction case.
For the rank-reducing case, there is linalg.tensor_reshape but it lives in
Linalg.
One solution would be to move linalg.reshape_tensor to the tensor dialect,
another one would be to move the canonicalization pattern in linalg.
It seems like the first solution is better because, despite
subtensor/subtensor_insert being linalg ops that have moved to other
dialects, they can be technically separated from linalg.
` but I don't think that we should replace it with linalg.reshape_tensor and
there is no tensor.reshape. `
Could you elaborate on why not ?
I see the obvious layering issue but I don't see something else offhand.
From my experimentation this is all coming from concatenate and slice operations
that are inserting/taking unit-dim slices. The way to go is to have
rank-reducing versions of these generated to begin with. Then you could
insert a linalg.tensor_reshape for those.
Is it mhlo slice or something else (IIRC I killed linalg.slice a while
back).
Makes sense that the problem did not appear until now in core if
IREE-specific rewrites expose the problematic behavior.
Still it seems like a core canonicalization issue that does not look at
whether the cast will be valid?
On Mon, Apr 12, 2021 at 3:02 PM MaheshRavishankar ***@***.***> wrote:
Definitely doing this as a cast is invalid. (you hit the same error
message, but the issue is different).
From my experimentation this is all coming from concatenate and slice
operations that are inserting/taking unit-dim slices. The way to go is to
have rank-reducing versions of these generated to begin with. Then you
could insert a linalg.tensor_reshape for those.
The rank-reducing versions are not handled properly in IREE, and there are
some canonicalization patterns missing in different places to make thse
work correctly. Here is the WIP changes to core I plan to work on this week
***@***.***
<MaheshRavishankar/llvm-project@1eae450>
. I can assign this bug to myself, it will take a few steps to plumb this
through.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5385 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACNNU5DHVGNWUFCNTXLTYODTIM7SZANCNFSM42VNTYPA>
.
Re @nicolasvasilache I was trying to say that linalg.tensor_reshape lives in Linalg, so I don't think that we should replace tensor.cast directly. Having a reshape op in tensor dialect looks really good to me.
Is it mhlo slice or something else (IIRC I killed linalg.slice a while back).
I think it is mhlo.slice and it will be lowered to subtensor op.
Still it seems like a core canonicalization issue that does not look at whether the cast will be valid?
Yes, you are right. it unconditionally creates a cast op when the operand type and result type mismatch.
+ @pifon2a
Ok so it is prob. time that we think of unifying linalg.tensor_reshape +
linalg.reshape with the memref variant that is called memref.reshape.
Let's chat tomorrow CET ?
Do you mind involving some folks from IREE too, or we could discuss in the codegen meeting tomorrow (9 AM PDT).
I think the issue of combining linalg.tensor_reshape and linalg.reshape is orthogonal. If memref.reshape is essentially linalg.reshape but in memref dialect then thats fine.
Activity
hanhanW commentedon Apr 12, 2021
I did some study on this, it looks like subtensor op has a canonicalization pattern to do it when the types are not match.
It failed (in my case) because the source type and result type do not have the same rank. Dumping IRs from the pattern could see
@MaheshRavishankar suggested that it should be tensor_reshape, but I don't think that we should replace it with
linalg.reshape_tensorand there is notensor.reshape. This is definitely a bug in the pattern because it would create an invalid cast op. I actually hit a similar issue before: https://llvm.discourse.group/t/lack-of-support-when-lowering-mhlo-reduce-to-linalg/2674cc @nicolasvasilache
side question:
I can not trigger the pattern with simpler example. I ran
mlir-opt -canonicalize a.mlir, but it seems that it never enter the pattern. It did not dump anything. Is there a way to trigger it?MaheshRavishankar commentedon Apr 12, 2021
Definitely doing this as a cast is invalid. (you hit the same error message, but the issue is different).
From my experimentation this is all coming from
concatenateandsliceoperations that are inserting/taking unit-dim slices. The way to go is to have rank-reducing versions of these generated to begin with. Then you could insert alinalg.tensor_reshapefor those.The rank-reducing versions are not handled properly in IREE, and there are some canonicalization patterns missing in different places to make thse work correctly. Here is the WIP changes to core I plan to work on this week MaheshRavishankar/llvm-project@1eae450 . I can assign this bug to myself, it will take a few steps to plumb this through.
nicolasvasilache commentedon Apr 12, 2021
nicolasvasilache commentedon Apr 12, 2021
hanhanW commentedon Apr 12, 2021
Thanks @MaheshRavishankar , my case is actually coming from mhlo.dynamic-slice. The pattern was landed early today: tensorflow/mlir-hlo@a3fc99e
Re @nicolasvasilache I was trying to say that
linalg.tensor_reshapelives in Linalg, so I don't think that we should replacetensor.castdirectly. Having a reshape op in tensor dialect looks really good to me.I think it is
mhlo.sliceand it will be lowered tosubtensorop.Yes, you are right. it unconditionally creates a cast op when the operand type and result type mismatch.
nicolasvasilache commentedon Apr 12, 2021
pifon2a commentedon Apr 12, 2021
MaheshRavishankar commentedon Apr 12, 2021
Do you mind involving some folks from IREE too, or we could discuss in the codegen meeting tomorrow (9 AM PDT).
I think the issue of combining
linalg.tensor_reshapeandlinalg.reshapeis orthogonal. Ifmemref.reshapeis essentiallylinalg.reshapebut inmemrefdialect then thats fine.Create ops with static shapes in PadTensorOpConversion if they're static
Create ops with static shapes in PadTensorOpConversion if they're sta…
MaheshRavishankar commentedon Apr 27, 2021
Fixed by dbd43a7
MaheshRavishankar commentedon Apr 27, 2021
Reopening (closed wrong bug)
MaheshRavishankar commentedon Apr 28, 2021
Should be fixed by this commit llvm/llvm-project@41849a9.
@hanhanW please verify and close after the change comes in through the integrate process.
MaheshRavishankar commentedon May 5, 2021
Closing this. rank-reducing subtensors/subtensor_insert support is implemented now.