Repository navigation
Closed
Labels
codegen/llvmLLVM code generation compiler backend
Description
The current implementation yields two tensors when tiling on parallel loops, see the lit test. (I will replace the link with the file after the change is landed to main.)
It causes an additional stack allocation. To repro:
Run: iree-opt --pass-pipeline='builtin.module(iree-llvmcpu-select-lowering-strategy, func.func(iree-llvmcpu-lower-executable-target))' /repro.mlir. Then you will find an memref.alloca op at the result IR.
#executable_target_embedded_elf_x86_64 = #hal.executable.target<"llvm-cpu", "embedded-elf-x86_64", {cpu = "generic", cpu_features = "", data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", iree.encoding.resolver = #iree_cpu.cpu_encoding_layout<>, max_stack_allocation_size = 32768 : i64, native_vector_size = 16 : i64, target_triple = "x86_64-unknown-unknown-eabi-elf", ukernels = "none"}>
#map = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>
#map1 = affine_map<(d0, d1, d2, d3) -> (d0, d2)>
#pipeline_layout = #hal.pipeline.layout<constants = 10, bindings = [#hal.pipeline.binding<storage_buffer, "ReadOnly|Indirect">, #hal.pipeline.binding<storage_buffer, "ReadOnly|Indirect">, #hal.pipeline.binding<storage_buffer, "ReadOnly|Indirect">, #hal.pipeline.binding<storage_buffer, Indirect>], flags = Indirect>
module {
func.func @mmt4d_bias_relu_dispatch_0_mmt4d_DxDxDx16x16x1_f32() attributes {hal.executable.target = #executable_target_embedded_elf_x86_64} {
%c0 = arith.constant 0 : index
%c32_i64 = arith.constant 32 : i64
%cst = arith.constant 0.000000e+00 : f32
%0 = hal.interface.constant.load layout(#pipeline_layout) ordinal(0) : i32
%1 = hal.interface.constant.load layout(#pipeline_layout) ordinal(1) : i32
%2 = hal.interface.constant.load layout(#pipeline_layout) ordinal(2) : i32
%3 = hal.interface.constant.load layout(#pipeline_layout) ordinal(3) : i32
%4 = hal.interface.constant.load layout(#pipeline_layout) ordinal(4) : i32
%5 = hal.interface.constant.load layout(#pipeline_layout) ordinal(5) : i32
%6 = hal.interface.constant.load layout(#pipeline_layout) ordinal(6) : i32
%7 = hal.interface.constant.load layout(#pipeline_layout) ordinal(7) : i32
%8 = hal.interface.constant.load layout(#pipeline_layout) ordinal(8) : i32
%9 = hal.interface.constant.load layout(#pipeline_layout) ordinal(9) : i32
%10 = arith.extui %0 : i32 to i64
%11 = arith.extui %1 : i32 to i64
%12 = arith.shli %11, %c32_i64 : i64
%13 = arith.ori %10, %12 : i64
%14 = arith.index_castui %13 : i64 to index
%15 = arith.extui %2 : i32 to i64
%16 = arith.extui %3 : i32 to i64
%17 = arith.shli %16, %c32_i64 : i64
%18 = arith.ori %15, %17 : i64
%19 = arith.index_castui %18 : i64 to index
%20 = arith.extui %4 : i32 to i64
%21 = arith.extui %5 : i32 to i64
%22 = arith.shli %21, %c32_i64 : i64
%23 = arith.ori %20, %22 : i64
%24 = arith.index_castui %23 : i64 to index
%25 = arith.extui %6 : i32 to i64
%26 = arith.extui %7 : i32 to i64
%27 = arith.shli %26, %c32_i64 : i64
%28 = arith.ori %25, %27 : i64
%29 = arith.index_castui %28 : i64 to index
%30 = arith.extui %8 : i32 to i64
%31 = arith.extui %9 : i32 to i64
%32 = arith.shli %31, %c32_i64 : i64
%33 = arith.ori %30, %32 : i64
%34 = arith.index_castui %33 : i64 to index
%35:5 = util.assume.int
%14<umin = 0, umax = 9007199254740991>,
%19<umin = 0, umax = 9007199254740991>,
%24<umin = 0, umax = 9007199254740991>,
%29<umin = 0, umax = 9007199254740991>,
%34<umin = 0, umax = 9007199254740991>
: index, index, index, index, index
%36 = iree_tensor_ext.dispatch.workload.ordinal %35#0, 0 : index
%37 = iree_tensor_ext.dispatch.workload.ordinal %35#1, 1 : index
%38 = iree_tensor_ext.dispatch.workload.ordinal %35#2, 2 : index
%39 = iree_tensor_ext.dispatch.workload.ordinal %35#3, 3 : index
%40 = iree_tensor_ext.dispatch.workload.ordinal %35#4, 4 : index
%41 = hal.interface.binding.subspan layout(#pipeline_layout) binding(0) alignment(64) offset(%c0) flags("ReadOnly|Indirect") : !iree_tensor_ext.dispatch.tensor<readonly:tensor<?x?x16x1xf32>>{%39, %36}
%42 = hal.interface.binding.subspan layout(#pipeline_layout) binding(1) alignment(64) offset(%c0) flags("ReadOnly|Indirect") : !iree_tensor_ext.dispatch.tensor<readonly:tensor<?x?x16x1xf32>>{%37, %40}
%43 = hal.interface.binding.subspan layout(#pipeline_layout) binding(2) alignment(64) offset(%c0) flags("ReadOnly|Indirect") : !iree_tensor_ext.dispatch.tensor<readonly:tensor<?x16xf32>>{%38}
%44 = hal.interface.binding.subspan layout(#pipeline_layout) binding(3) alignment(64) offset(%c0) flags(Indirect) : !iree_tensor_ext.dispatch.tensor<writeonly:tensor<?x?x16x16xf32>>{%39, %40}
%45 = iree_tensor_ext.dispatch.tensor.load %41, offsets = [0, 0, 0, 0], sizes = [%39, %36, 16, 1], strides = [1, 1, 1, 1] : !iree_tensor_ext.dispatch.tensor<readonly:tensor<?x?x16x1xf32>>{%39, %36} -> tensor<?x?x16x1xf32>
%46 = iree_tensor_ext.dispatch.tensor.load %42, offsets = [0, 0, 0, 0], sizes = [%37, %40, 16, 1], strides = [1, 1, 1, 1] : !iree_tensor_ext.dispatch.tensor<readonly:tensor<?x?x16x1xf32>>{%37, %40} -> tensor<?x?x16x1xf32>
%47 = iree_tensor_ext.dispatch.tensor.load %43, offsets = [0, 0], sizes = [%38, 16], strides = [1, 1] : !iree_tensor_ext.dispatch.tensor<readonly:tensor<?x16xf32>>{%38} -> tensor<?x16xf32>
%48 = tensor.empty(%39, %40) : tensor<?x?x16x16xf32>
%49 = linalg.fill ins(%cst : f32) outs(%48 : tensor<?x?x16x16xf32>) -> tensor<?x?x16x16xf32>
%50 = linalg.mmt4d ins(%45, %46 : tensor<?x?x16x1xf32>, tensor<?x?x16x1xf32>) outs(%49 : tensor<?x?x16x16xf32>) -> tensor<?x?x16x16xf32>
%51 = linalg.generic {indexing_maps = [#map, #map1, #map], iterator_types = ["parallel", "parallel", "parallel", "parallel"]} ins(%50, %47 : tensor<?x?x16x16xf32>, tensor<?x16xf32>) outs(%48 : tensor<?x?x16x16xf32>) {
^bb0(%in: f32, %in_0: f32, %out: f32):
%52 = arith.addf %in, %in_0 : f32
%53 = arith.maximumf %52, %cst : f32
linalg.yield %53 : f32
} -> tensor<?x?x16x16xf32>
iree_tensor_ext.dispatch.tensor.store %51, %44, offsets = [0, 0, 0, 0], sizes = [%39, %40, 16, 16], strides = [1, 1, 1, 1] : tensor<?x?x16x16xf32> -> !iree_tensor_ext.dispatch.tensor<writeonly:tensor<?x?x16x16xf32>>{%39, %40}
return
}
}
There is a path showing that mmt4d fusion codegen does not need any stack allocation, when we use TileAndFuse path with preset configuration.
Replace the path with TileAndFuse in mmt4d pipeline, and run iree-opt --pass-pipeline='builtin.module(func.func(iree-llvmcpu-lower-executable-target))' ~/repro2.mlir
#config = #iree_codegen.lowering_config<tile_sizes = [[1, 2, 0, 0, 0, 0], [1, 1, 0, 16, 16, 0], [0, 0, 1, 0, 0, 1]]>
#config1 = #iree_codegen.lowering_config<tile_sizes = [[1, 2, 0, 0], [1, 1, 16, 16], [0, 0, 0, 0], [0, 0, 0, 0]]>
#executable_target_embedded_elf_x86_64 = #hal.executable.target<"llvm-cpu", "embedded-elf-x86_64", {cpu = "generic", cpu_features = "", data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", iree.encoding.resolver = #iree_cpu.cpu_encoding_layout<>, max_stack_allocation_size = 32768 : i64, native_vector_size = 16 : i64, target_triple = "x86_64-unknown-unknown-eabi-elf", ukernels = "none"}>
#map = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>
#map1 = affine_map<(d0, d1, d2, d3) -> (d0, d2)>
#pipeline_layout = #hal.pipeline.layout<constants = 10, bindings = [#hal.pipeline.binding<storage_buffer, "ReadOnly|Indirect">, #hal.pipeline.binding<storage_buffer, "ReadOnly|Indirect">, #hal.pipeline.binding<storage_buffer, "ReadOnly|Indirect">, #hal.pipeline.binding<storage_buffer, Indirect>], flags = Indirect>
#translation = #iree_codegen.translation_info<pipeline = Mmt4dTilingExpert>
module {
func.func @mmt4d_bias_relu_fusion_dispatch_0_generic_DxDx16x16_f32() attributes {hal.executable.target = #executable_target_embedded_elf_x86_64, translation_info = #translation} {
%c0 = arith.constant 0 : index
%c32_i64 = arith.constant 32 : i64
%cst = arith.constant 0.000000e+00 : f32
%0 = hal.interface.constant.load layout(#pipeline_layout) ordinal(0) : i32
%1 = hal.interface.constant.load layout(#pipeline_layout) ordinal(1) : i32
%2 = hal.interface.constant.load layout(#pipeline_layout) ordinal(2) : i32
%3 = hal.interface.constant.load layout(#pipeline_layout) ordinal(3) : i32
%4 = hal.interface.constant.load layout(#pipeline_layout) ordinal(4) : i32
%5 = hal.interface.constant.load layout(#pipeline_layout) ordinal(5) : i32
%6 = hal.interface.constant.load layout(#pipeline_layout) ordinal(6) : i32
%7 = hal.interface.constant.load layout(#pipeline_layout) ordinal(7) : i32
%8 = hal.interface.constant.load layout(#pipeline_layout) ordinal(8) : i32
%9 = hal.interface.constant.load layout(#pipeline_layout) ordinal(9) : i32
%10 = arith.extui %0 : i32 to i64
%11 = arith.extui %1 : i32 to i64
%12 = arith.shli %11, %c32_i64 : i64
%13 = arith.ori %10, %12 : i64
%14 = arith.index_castui %13 : i64 to index
%15 = arith.extui %2 : i32 to i64
%16 = arith.extui %3 : i32 to i64
%17 = arith.shli %16, %c32_i64 : i64
%18 = arith.ori %15, %17 : i64
%19 = arith.index_castui %18 : i64 to index
%20 = arith.extui %4 : i32 to i64
%21 = arith.extui %5 : i32 to i64
%22 = arith.shli %21, %c32_i64 : i64
%23 = arith.ori %20, %22 : i64
%24 = arith.index_castui %23 : i64 to index
%25 = arith.extui %6 : i32 to i64
%26 = arith.extui %7 : i32 to i64
%27 = arith.shli %26, %c32_i64 : i64
%28 = arith.ori %25, %27 : i64
%29 = arith.index_castui %28 : i64 to index
%30 = arith.extui %8 : i32 to i64
%31 = arith.extui %9 : i32 to i64
%32 = arith.shli %31, %c32_i64 : i64
%33 = arith.ori %30, %32 : i64
%34 = arith.index_castui %33 : i64 to index
%35 = iree_tensor_ext.dispatch.workload.ordinal %14, 0 : index
%36 = iree_tensor_ext.dispatch.workload.ordinal %19, 1 : index
%37 = iree_tensor_ext.dispatch.workload.ordinal %24, 2 : index
%38 = iree_tensor_ext.dispatch.workload.ordinal %29, 3 : index
%39 = iree_tensor_ext.dispatch.workload.ordinal %34, 4 : index
%40 = hal.interface.binding.subspan layout(#pipeline_layout) binding(0) alignment(64) offset(%c0) flags(ReadOnly) : !iree_tensor_ext.dispatch.tensor<readonly:tensor<?x?x16x1xf32>>{%38, %35}
%41 = hal.interface.binding.subspan layout(#pipeline_layout) binding(1) alignment(64) offset(%c0) flags(ReadOnly) : !iree_tensor_ext.dispatch.tensor<readonly:tensor<?x?x16x1xf32>>{%39, %36}
%42 = hal.interface.binding.subspan layout(#pipeline_layout) binding(2) alignment(64) offset(%c0) flags(ReadOnly) : !iree_tensor_ext.dispatch.tensor<readonly:tensor<?x16xf32>>{%37}
%43 = hal.interface.binding.subspan layout(#pipeline_layout) binding(3) alignment(64) offset(%c0) : !iree_tensor_ext.dispatch.tensor<writeonly:tensor<?x?x16x16xf32>>{%38, %39}
%44 = iree_tensor_ext.dispatch.tensor.load %40, offsets = [0, 0, 0, 0], sizes = [%38, %35, 16, 1], strides = [1, 1, 1, 1] : !iree_tensor_ext.dispatch.tensor<readonly:tensor<?x?x16x1xf32>>{%38, %35} -> tensor<?x?x16x1xf32>
%45 = iree_tensor_ext.dispatch.tensor.load %41, offsets = [0, 0, 0, 0], sizes = [%39, %36, 16, 1], strides = [1, 1, 1, 1] : !iree_tensor_ext.dispatch.tensor<readonly:tensor<?x?x16x1xf32>>{%39, %36} -> tensor<?x?x16x1xf32>
%46 = iree_tensor_ext.dispatch.tensor.load %42, offsets = [0, 0], sizes = [%37, 16], strides = [1, 1] : !iree_tensor_ext.dispatch.tensor<readonly:tensor<?x16xf32>>{%37} -> tensor<?x16xf32>
%47 = tensor.empty(%38, %39) : tensor<?x?x16x16xf32>
%48 = linalg.fill ins(%cst : f32) outs(%47 : tensor<?x?x16x16xf32>) -> tensor<?x?x16x16xf32>
%49 = linalg.mmt4d {lowering_config = #config} ins(%44, %45 : tensor<?x?x16x1xf32>, tensor<?x?x16x1xf32>) outs(%48 : tensor<?x?x16x16xf32>) -> tensor<?x?x16x16xf32>
%50 = linalg.generic {indexing_maps = [#map, #map1, #map], iterator_types = ["parallel", "parallel", "parallel", "parallel"]} ins(%49, %46 : tensor<?x?x16x16xf32>, tensor<?x16xf32>) outs(%47 : tensor<?x?x16x16xf32>) attrs = {lowering_config = #config1} {
^bb0(%in: f32, %in_0: f32, %out: f32):
%51 = arith.addf %in, %in_0 : f32
%52 = arith.maximumf %51, %cst : f32
linalg.yield %52 : f32
} -> tensor<?x?x16x16xf32>
iree_tensor_ext.dispatch.tensor.store %50, %43, offsets = [0, 0, 0, 0], sizes = [%38, %39, 16, 16], strides = [1, 1, 1, 1] : tensor<?x?x16x16xf32> -> !iree_tensor_ext.dispatch.tensor<writeonly:tensor<?x?x16x16xf32>>{%38, %39}
return
}
}Metadata
Metadata
Assignees
Labels
codegen/llvmLLVM code generation compiler backend
Activity
egebeysel commentedon May 13, 2025
Hi, I'm also hitting the same issue. Correct me if I'm wrong, but I believe the redundant stack buffer allocations over here are an artifact of (iterative) consumer fusion generating loops with multiple results, where some of them are unused. I added an IR below for this. They then get bufferized into stack allocations. Switching the
TileRootAndFuseProducerConsumertoTileAndFuseactually does get rid of the redundant stack buffer allocations, since - I believe - it works with producer fusion instead of producer+consumer. Although on the below example, I guess due to the unpack op in the middle and the current tile size selection mechanism, we get a rather suboptimal tiling that results in redundant computations, see thetensor<1x1x1xf32>extracted from the unpack and used for the generic.The above would be the result of running
TileRootAndFuseProducerConsumeron the same IR above, before theTileAndFuse:As I stated above, I believe these unused results of the tiled and fused loop get bufferized to large stack buffer allocations. I was wondering if the plan is to switch the CPU pipeline to use
TileAndFuseinstead ofTileRootAndFuseProducerConsumer(or if the plan is to support/utilize both consumer+producer fusion or stick to producer fusion), or if the iterative consumer fusion mechanism in the latter pass might also be adjusted to not result in redundant stack allocations. I guess we could cleanup the unused results of the loop (and possibly add tensor.empty() ops in the innermost loops for the output buffers of compute ops) to achieve this. Do you think that would be sensible to do?Also, since the above dispatch occurs in the DT-fusion path, I was also curious if there were any plans to improve DT/codegen for these - so that they would not end up with redundant computations :) It's probably not exactly the correct place for this one, though I had some observations and ideas for this part and would love to hear your thoughts/plans as well :)
EDIT: I guess the problem I mentioned with the redundant computations is the same issue as in: #20786 (comment) - the extract slice op of the generic.
pashu123 commentedon May 14, 2025
I see two problems: 1. The tile selection logic for tensor.unpack is wrong. (If you fix that, tile and fuse pipeline would work fine) 2. Yes, you're right, consumer fusion creates extra buffers that need to be fixed for tileRootFuseConsumerProducerPipeline. I think we want to avoid using tileAndFuse because we don't want extra config propagation strategy.
hanhanW commentedon May 15, 2025
As mentioned in the other issue #20785, we want to get rid of lowering config propagation. It implies that we will switch to
TileRootAndFuseProducerConsumer.The issue mainly demonstrates that it should be doable in the pass. I think something is off/missing in the pass, and we need to fix it.
pashu123 commentedon May 15, 2025
@hanhanW and I had an offline discussion about the issue. The current problem is that we don't have control over intermediate yields during consumer fusion, and they are always attached as an iter_arg. For tileConsumerFuseProducer (Producer Fusion) we have controls to enable/disable the intermediate yields, see
iree/compiler/src/iree/compiler/Codegen/LLVMCPU/LLVMCPUTileRootAndFuseProducerConsumer.cpp
Line 102 in 65b6541
To tackle this, we have two options:
Use scf.forall fusion for parallel iterators. It's easy to enable this in the TileRootFuseConsumerProducer pass, we only have to set
tilingOptions.setLoopType(scf::SCFTilingOptions::LoopType::ForallOp);hereiree/compiler/src/iree/compiler/Codegen/LLVMCPU/LLVMCPUTileRootAndFuseProducerConsumer.cpp
Line 95 in 65b6541
onlyFuseProducerInputOperands. We can only set this if it's a parallel tiling. For reduction tiling we don't fuse the consumers, so it's not a problemiree/compiler/src/iree/compiler/Codegen/LLVMCPU/LLVMCPUTileRootAndFuseProducerConsumer.cpp
Line 207 in 65b6541
scf.forallnaturally gets rid of intermediate iter_args because it follows what's finally stored in the scf.forall.in_parallel (https://mlir.llvm.org/docs/Dialects/SCFDialect/#scfforallin_parallel-scfinparallelop) block and removes all other iter_args.We can then lower
scf.foralltoscf.forand we have the upstream pattern for this https://github.com/llvm/llvm-project/blob/main/mlir/lib/Dialect/SCF/Transforms/ForallToFor.cpp (Caveat: Don't lower scf.forall that have workgroup ids attached -- they are handled differently)Analyze
scf.forto remove the not used independent iter_arg or add the control function in the consumer fusion.I would take the first route; it makes IR clearer in terms of semantics—we have
scf.forall, so it's parallel tiling.egebeysel commentedon May 15, 2025
Hey, thanks for your responses!
Get rid of as in not have it at all and use the same mechanisms (or modified versions) used for setting the lowering config on the first place on-the-fly?
I also have some example in which a
generic -> packdispatch fails to fuse thegenericpack on the workgroup level, hence failing compilation with "large vector sizes". I'll also post that one as well tomorrow.But generally, you say that although the tile selection logic and the lowering config propagation might cause some issues, it's better to actually tackle them at the points where they actually do cause the failures and not burden the lowering configs even more, do I understand that correctly?I actually do have a prototype for the second route, but the first one also seems to be more clear to me to be honest.
egebeysel commentedon May 16, 2025
The example I was talking about above does not happen just now, but rather if we switch the
TileAndDistributeToWorkgroupsUsingForallOpPassto use the root op instead of the last compute op over here.At first, I thought this one was caused by the tile selection logic, but I think it's rather consumer fusion and the odd shapes, please correct me if I'm wrong here. I guess the consumer fusion could maybe be improved to handle these cases as well, since producer fusion starting from the pack op seems to be able to fuse the generic as well. One other question I had was about the selection criteria for the root operation. What's the reason that element-wise ops have precedence over packs/unpacks? Would giving precedence to pack/unpack ops be a feasible way to force producer fusion in these cases? Would forcing producer fusion in such cases even make sense or would it be (more) feasible to improve consumer fusion? I'd love to hear your thoughts on that one as well :)
I'll also open another issue for this one next week, since I believe this isn't entirely relevant to this one, but does concern consumer fusion.
hanhanW commentedon May 16, 2025
Yes, we use the same mechanism to set the lowering_config and translation_info on root op. We only disable the propagation, which drops some "hints" for other ops. (We can set the hints if needed. I just don't see an example for now.)
I'll need to refresh my memory. :) The short answer is mostly because of legacy. The thing that I need to rethink is pack/unpack ops are more like "storing the tiled results to a different position". The core computation is still the same, so the root op does not change in this context. However, I've been thinking to break this rule in
element->packcases because the transposition needs to be efficient. I guess I proposed the idea in some casual chat before, but I don't remember the details now. The switch is not a bad decision, IMO. We need to reason it.The other thinking is that we should explore if we can improve the indexing mapping on CPU or not, but it requires some POC. Unfortunately, I don't have enough cycles to invest this part. So it is waht it is today.
Side note is that @Max191 has been pushing this on GPU side. We recently learned that we can explore the early bufferization approach for codegen, while still keep the core computation ops on tensors. It uses MapScatter op, that helps the indices remapping. We are still building the transformations for the op, so it is not ready yet.
iree/compiler/src/iree/compiler/Dialect/LinalgExt/IR/LinalgExtOps.td
Lines 316 to 344 in e66fc15
There were potential issues on CPU side, when last time I reviewed the early bufferization idea though. My study note was outdated, so I'm not going to open the pandora box here. :)
We seem to have a similar issue here: #20723
I don't have cycles to take a look at it, so I don't know what's happening. IMO, there is a bug somewhere, and we need to fix it. I'm not convinced that the fusion can't happen atm. It is a bug to me, and someone needs to fix it.
egebeysel commentedon May 19, 2025
Do you mean special-casing on that order, or in general giving precedence to pack (possibly also unpack) ops over elementwise ops? I agree with the fact that the core of the computation being the element-wise ops and the pack/unpacks being more like utility ops so to say, but does being the root op have any semantics rather than sort of being the starting point for tiling+fusing? Also, I know that it's theoretically possible to have
pack->genericcases, but is that really a pattern that is observed often? Because with the fusion data-tiling path, I guess one almost never observes such dispatches.Nevertheless, I also agree that consumer fusion should be (as) symmetric (as possible) to producer fusion and that it should be able to fuse as well. I'd be happy to investigate this further.
Is there an RFC kind of document, an example or even a Discord thread I can read for this one? It's not super easy to deduce the general idea from the operation only and I'd appreciate some pointers :)
I'd also be happy to invest some time in this one, if you would have time to explain what exactly you would want to improve and what you expect to change with that. But I guess I would also prioritize the blockers first.
I'd also like to take a stab at this option if @pashu123 is not working on it already :)
egebeysel commentedon May 19, 2025
Btw. I also just took a look at this one, and I think this sort of dispatch is also something that makes me think that the pack operation might have to have some precedence over some other ops. There, you have something in the lines of:
Regardless of the fact that the pack op not having a lowering config attached to it, if the pooling op had precedence over the pack and the tiling started from that one, fusion gets blocked once you tile the outermost dimension M with tile size 1, since the pack op operates on M=8 and cannot use the intermediate
1x32x1x1xf32result from the pooling op. On that regard, I would assume that either that information of "Hey, if you want to fuse me in, you would need the outermost tile size to be 8!" to be propagated to the tile sizes of the pooling op, or the tiling to start with the pack as root and fuse in the pooling. I know that the pooling is not an element-wise, but still, ending up with these tile sizes points to something missing IMO. Please do correct me if I'm missing something over here.cc @qedawkins, because I asked something in #20723 about this as well.
qedawkins commentedon May 19, 2025
Correct, today this is the only way we can set configs that will work, e.g. #20455 (reshapes and packs have the same problem), but that's a WaR. The correct fix is just to add support for the fusion, however that's not possible with the current incarnations of
scf.forall+TilingInterface. That's what this WIP branch is supposed to fix, but I have been context switched away from it.hanhanW commentedon May 19, 2025
It depends on whether you want to do local propagation within a dispatch.
@AaronStGeorge is going to look at this. @AaronStGeorge this is the issue that we talked about in our 1:1. Please take a look, thanks!
EDIT: to be more specific, see #20792 (comment) comment. Feel free to reach out to me or @pashu123 if you have any question.
44 remaining items
[LLVMCPU] Add option to `LLVMCPUTileRootAndFuseProducerConsumer` for …
[CPU] Use option to tile with `scf.forall` in TileRootAndFuseProducer…
[CPU] Use option to tile with `scf.forall` in TileRootAndFuseProducer…
[LLVMCPU] Add option to `LLVMCPUTileRootAndFuseProducerConsumer` for …
[CPU] Use option to tile with `scf.forall` in TileRootAndFuseProducer…
[CPU] Add option to `LLVMCPUTileRootAndFuseProducerConsumer` to tilin…
[CPU] Use option to tile with `scf.forall` in TileRootAndFuseProducer…
[CPU] Use option to tile with `scf.forall` in TileRootAndFuseProducer…
hanhanW commentedon Jun 26, 2025
Confirmed that it is fixed by #20961 #20962 #21009 #21198
[Codegen][NFC] Create tiling utilities file (#20961)
[Codegen] Create `scf.forall` -> `scf.for` pass (#20962)
[CPU] Add option to `LLVMCPUTileRootAndFuseProducerConsumer` to tilin…
[CPU] Use option to tile with `scf.forall` in TileRootAndFuseProducer…