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
Add support for fusing generic ops that have reduction loop #4219
The second parallel loop of the first op can be combined with the reduction loop of the second op. After computing the result of the first op, do the reduction computation.
I think the concern here is "do we want to fuse these operations?" The reason is that we will lose the parallel opportunity for the second loop in the first op. If that is a big chunk and is element-wise operation, we probably still want to fully utilize cores. And do the reduction later.
One way to look at this is as map -> reduce fusion. Typically this is done when the reduction is also executed in parallel (using tree reduction), but when the reduction is serialized, I agree there is a problem.
For the most case though, I dont think its common to see cases with just a single "reduction" iterator type. We usually see ["parallel", "parallel", ..., "reduce"]. In that case we can loose some degree of parallelism, but might still have enough to justify the fusion.
My suggestion is to implement the fusion (for more general case where the consumer might have mix of "parallel" and "reduction" iterator types). We can then make a decision in IREE if we want to use this pattern or not.
I think its fair to say we can rule out fusion producers that have "reduction" with their consumers. That will probably be done through tile + fuse cause it needs imperfectly nested loops.
Activity
hanhanW commentedon Dec 16, 2020
I feel the
#map0and#map1could rewrite to 2D form. Then, we can fuse the op into:The second parallel loop of the first op can be combined with the reduction loop of the second op. After computing the result of the first op, do the reduction computation.
After converting to memref, then to the loop:
I think the concern here is "do we want to fuse these operations?" The reason is that we will lose the parallel opportunity for the second loop in the first op. If that is a big chunk and is element-wise operation, we probably still want to fully utilize cores. And do the reduction later.
E.g.,
However, we can still support the fusion, and leave the decision to analysis pass.
@nicolasvasilache
MaheshRavishankar commentedon Dec 16, 2020
One way to look at this is as
map -> reducefusion. Typically this is done when the reduction is also executed in parallel (using tree reduction), but when the reduction is serialized, I agree there is a problem.For the most case though, I dont think its common to see cases with just a single "reduction" iterator type. We usually see ["parallel", "parallel", ..., "reduce"]. In that case we can loose some degree of parallelism, but might still have enough to justify the fusion.
My suggestion is to implement the fusion (for more general case where the consumer might have mix of "parallel" and "reduction" iterator types). We can then make a decision in IREE if we want to use this pattern or not.
I think its fair to say we can rule out fusion producers that have "reduction" with their consumers. That will probably be done through tile + fuse cause it needs imperfectly nested loops.
hanhanW commentedon Jan 5, 2021
I just found that the case is supported at some point. I think this is because we have "init_tensor" for linalg ops that only have parallel loops, so it's magically supported. Added a test in https://reviews.llvm.org/D94093
hanhanW commentedon Jan 5, 2021
The fused result is:
MaheshRavishankar commentedon Jan 5, 2021
Cool! Do you mind making sure the necessary checks are added upstream?
hanhanW commentedon Jan 22, 2021
Sorry that I missed the issue...
Yes, the necessary checks were added. They can only be fused iff producer doesn't have "reduction" loops as we've discussed:
https://github.com/llvm/llvm-project/blob/4edb63bbbe338b890119a307bc323c24d0a1afc7/mlir/lib/Dialect/Linalg/Transforms/FusionOnTensors.cpp#L30-L51