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
{{ message }}
Repository navigation
[DT][CPU] Some casting ops are not fused with mmt4d kernels #15826
We set encodings on CastOpInterface ops, so we can fuse in cast ops to mmt4d dispatch. However, we only fuse cast ops when they are not "group dequantization" ops. It does not happen when it is something like arith.truncf %lhs f32 to f16 + f16.f16.f16 matmul. This results in additional dispatches. We are having pack dispatch, arith.truncf dispatch and mmt4d dispatch. We should either fix it in set_encoding or dispatch formation. In the former solution, we will have arith.truncf + pack dispatch and mmt4d dispatch. In the latter solution, we will have [optional consumers] + pack dispatch and arith.truncf + mmt4d dispatch.
To repro:
Run iree-compile --output-format=vm-bytecode --iree-hal-target-backends=llvm-cpu --iree-llvmcpu-target-cpu=cascadelake --iree-llvmcpu-target-triple=x86_64-unknown-linux-gnu ~/repro.mlir -o /tmp/a.vmfb
@Max191@MaheshRavishankar and I had an offline discussion about the issue. If we fuse the truncf with mmt4d op and the ukernel is not supported for the type, we will pay costs for load/store before calling ukernels.
We should not set encodings on all the casting ops. We should do it only for casting ops that widen bitwidth. In this context, the truncf op will be fused with its producers (i.e., generics). So we no longer see the issue that we set encodings on cast ops but not fuse them with mmt4d ops.
There are two sub-tasks to address the issue:
Do not set encoding on casting ops that reduce bitwidth.
Fuse those cast ops with mmt4d kernels.
@Max191 given that you've touched these files recently, can you help fix the issue?
I think #15760 is also related to this so I have a question:
We want to extend i8 to f32 on LHS/RHS in some cases so even if we don't have the corresponding ukernels, we can still use f32 ukernels with LHS/RHS extended.
My current idea is to fuse cast ops with the pack op (and potentially its producer, so generic + truncf + pack) and we can hide the overhead. IIUC in this issue we are actually trying to fuse cast ops with the mmt4d ukernel? How would that work as from my understanding we can't actually fuse truncf with ukernel call in the same dispatch?
I think #15760 is also related to this so I have a question:
We want to extend i8 to f32 on LHS/RHS in some cases so even if we don't have the corresponding ukernels, we can still use f32 ukernels with LHS/RHS extended.
My current idea is to fuse cast ops with the pack op (and potentially its producer, so generic + truncf + pack) and we can hide the overhead. IIUC in this issue we are actually trying to fuse cast ops with the mmt4d ukernel? How would that work as from my understanding we can't actually fuse truncf with ukernel call in the same dispatch?
Hey sorry that I wrote the tasks in a opposite case. I updated the comment. We don't want to set encodings on truncf, so the op order is truncf + pack. In this context, we will create generic + pack dispatch.
Activity
hanhanW commentedon Dec 7, 2023
@Max191 @MaheshRavishankar and I had an offline discussion about the issue. If we fuse the truncf with mmt4d op and the ukernel is not supported for the type, we will pay costs for load/store before calling ukernels.
We should not set encodings on all the casting ops. We should do it only for casting ops that widen bitwidth. In this context, the truncf op will be fused with its producers (i.e., generics). So we no longer see the issue that we set encodings on cast ops but not fuse them with mmt4d ops.
There are two sub-tasks to address the issue:
@Max191 given that you've touched these files recently, can you help fix the issue?
(FYI @bjacob )
pzread commentedon Dec 7, 2023
I think #15760 is also related to this so I have a question:
We want to extend i8 to f32 on LHS/RHS in some cases so even if we don't have the corresponding ukernels, we can still use f32 ukernels with LHS/RHS extended.
My current idea is to fuse cast ops with the pack op (and potentially its producer, so
generic + truncf + pack) and we can hide the overhead. IIUC in this issue we are actually trying to fuse cast ops with the mmt4d ukernel? How would that work as from my understanding we can't actually fusetruncfwith ukernel call in the same dispatch?hanhanW commentedon Dec 7, 2023
Hey sorry that I wrote the tasks in a opposite case. I updated the comment. We don't want to set encodings on
truncf, so the op order istruncf + pack. In this context, we will creategeneric + packdispatch.[GlobalOpti] Avoid SetEncoding on non-extending CastOpInterface ops (#…
[GlobalOpti] Avoid SetEncoding on non-extending CastOpInterface ops (i…