Repository navigation
Conversation
…degen.
Moves the two `iree_codegen.inner_tiled` rewrite patterns and their
populate functions out of `Codegen/Dialect/GPU/Transforms/` into
`Codegen/Dialect/Codegen/Transforms/LowerInnerTiled.cpp`:
- `LowerInnerTiledPattern` (replaces an iter-bound-empty `inner_tiled`
with the per-intrinsic ops emitted by its kind's
`buildUnderlyingOperations`)
- `DropInnerTiledUnitDimsPattern` (folds unit iteration bounds and
pulls the corresponding extract/broadcast pairs out of the loop)
Both patterns operate on `IREE::Codegen::InnerTiledOp` and dispatch
through the kind's interface, so there is nothing GPU-specific about
them. Lifting them lets CPU pass authors share the same lowering logic
without a `Codegen/Dialect/GPU/...` include.
Renames the populate functions accordingly:
- `IREE::GPU::populateIREEGPULowerInnerTiledPatterns`
-> `IREE::Codegen::populateLowerInnerTiledPatterns`
- `IREE::GPU::populateIREEGPUDropUnitDimsPatterns`
-> `IREE::Codegen::populateDropInnerTiledUnitDimsPatterns`
The `kShapeCastToIntrinsic` / `kShapeCastFromIntrinsic` and
`kDropUnitDims` / `kAddUnitDims` HoistableConversionOp tag constants
move with the patterns. The remaining tag pair on the GPU side
(`kUnrollAccDistribute` / `kUnrollAccReassemble`) stays in
`Codegen/Dialect/GPU/Transforms/Transforms.cpp` since it's still only
used by the GPU unroll path.
Updates the existing in-tree callers in `LowerIREEGPUOps.cpp`,
`IREEGPUExtensions.cpp`, and `UnrollToIntrinsics.cpp`, and adjusts
BUILD.bazel/CMakeLists.txt deps so GPU's transform libraries depend on
`IREECodegenTransforms`.
Strict NFC; no functional or behavioral change.
Signed-off-by: Benoit Jacob <[email protected]>
Progress towards #24323
Lowers vector-semantics `iree_codegen.inner_tiled` ops on the CPU side
by running two pattern sets in sequence on the function body:
1. `IREE::Codegen::populateDropInnerTiledUnitDimsPatterns` drops the
(now-unit) iter domain so the lowered op has empty iter bounds,
satisfying the precondition of (2).
2. `IREE::Codegen::populateLowerInnerTiledPatterns` replaces the
iter-free vector-semantics inner_tiled with the per-intrinsic
`llvm.call_intrinsic` ops emitted by
`DataTiledMMAAttr::buildUnderlyingOperations`.
Both pattern sets were lifted out of `Codegen/Dialect/GPU/Transforms/`
into `Codegen/Dialect/Codegen/Transforms/` in the previous (NFC) commit
so CPU can share them with GPU. They are interface-driven and pick up
CPU's `IREE::CPU::DataTiledMMAAttr` transparently via its
`buildUnderlyingOperations` implementation.
The pass expects vector-semantics input, which the upstream
`GenericVectorizationPass` produces via the
`InnerTiledOpVectorizationModel` `VectorizableOpInterface` external
model already in tree. Schedule the new pass right after
`GenericVectorizationPass` in `addMmt4dTilingExpertPassPipeline`, where
data-tiled-MMA dispatches will land once the next commit teaches the
lowering strategy to route them through that pipeline. The pass is a
no-op when the function has no inner_tiled ops.
Adds a focused lit test
`compiler/src/iree/compiler/Codegen/LLVMCPU/test/lower_inner_tiled.mlir`
that feeds a single-tile AVX-512 1x16x1 f32 vector-semantics
inner_tiled and asserts the surviving `llvm.fma.v16f32` call.
Signed-off-by: Benoit Jacob <[email protected]>
Progress towards #24323
krzysz00
left a comment
There was a problem hiding this comment.
Two notes, but this looks mostly like stampable code movement, so approved after notes
| IREE::Codegen::populateLowerInnerTiledPatterns(patterns); | ||
| if (failed(applyPatternsGreedily(getOperation(), std::move(patterns)))) { | ||
| return signalPassFailure(); | ||
| } |
There was a problem hiding this comment.
I think you'll want to run the hoistable conversions code after this
| Runs three pattern sets in sequence on the function body: | ||
| (1) `populateVectorizeInnerTiledPatterns`: lift tensor-semantics | ||
| inner_tiled ops to vector semantics. | ||
| (2) `populateIREEGPUDropUnitDimsPatterns`: drop the (now-unit) iteration |
There was a problem hiding this comment.
Do we want to drop the "GPU" from these now?
| Runs three pattern sets in sequence on the function body: | ||
| (1) `populateVectorizeInnerTiledPatterns`: lift tensor-semantics | ||
| inner_tiled ops to vector semantics. | ||
| (2) `populateIREEGPUDropUnitDimsPatterns`: drop the (now-unit) iteration | ||
| domain so the lowered op has empty iter bounds. | ||
| (3) `populateIREEGPULowerInnerTiledPatterns`: replace the vector- | ||
| semantics, iter-domain-free inner_tiled with the per-intrinsic | ||
| `llvm.call_intrinsic` ops emitted by | ||
| `DataTiledMMAAttr::buildUnderlyingOperations`. | ||
| Despite the `IREEGPU` names, patterns (2) and (3) are interface-driven and | ||
| work for any `InnerTileDescAttrInterface` kind, including CPU's | ||
| `IREE::CPU::DataTiledMMAAttr`. |
There was a problem hiding this comment.
seems to be outdated? GPU should not be mentioned at all in this pass.
| // Expects vector-semantics `iree_codegen.inner_tiled` produced by the | ||
| // generic vectorization pass via the `VectorizableOpInterface` external | ||
| // model in `compiler/src/iree/compiler/Codegen/Interfaces/`. |
There was a problem hiding this comment.
This should be part of pass description, and we should not mention GenericVectorization or how the op is vectorized at all IMO. The pass itself does not care that. What it expects is vectorized inner tiled. Let's drop the vectorization mechanism and move it into description?
btw, how about naming the pass as "LLVMCPULowerVectorizedInnerTiledPass`?
|
|
||
| // `iree-llvmcpu-lower-inner-tiled` runs two pattern sets in sequence on a | ||
| // vector-semantics `iree_codegen.inner_tiled` (the kind produced by | ||
| // GenericVectorization via the VectorizableOpInterface external model): |
There was a problem hiding this comment.
Same here, this is leaking layering assumption which is redundant to this pass.
| // Lower any iree_codegen.inner_tiled ops produced by the data-tiled MMA | ||
| // path. GenericVectorization above lifts them to vector-semantics via the | ||
| // VectorizableOpInterface external model; this pass then drops their unit | ||
| // iter dims and emits the per-intrinsic ops via | ||
| // `DataTiledMMAAttr::buildUnderlyingOperations`. If the dispatch has no | ||
| // inner_tiled ops the pass is a no-op. |
There was a problem hiding this comment.
I think we can say that this is similar to ukernel path, but it is more powerful because of fusion. I don't have fresh memory for the lowering patterns. IIRC, it should also unroll the inner tiled op which has the same behavior as your ukernels?
Open question: do we do the lowering after bufferization? The inner tiled captures the memref semantics well, which seems to have less burden in the pipeline. My first thinking for the pass is about "high level vector lowering", because it is lowering a "virtual vector" to IRs that is closer to LLVM dialect (low-level dialect). Thus, it belongs to the LLVMCPUVirtualVectorLoweringPass in buildLLVMCPUVectorLoweringPipeline IMO.
Do we just add the patterns to the pass? And we can add tests to virtual_vector_lowering.mlir in this context.
There was a problem hiding this comment.
I think you are right @hanhanW . Let me close this PR and redo this like you suggest.
Lowers vector-semantics
iree_codegen.inner_tiledops on the CPU sideby running two pattern sets in sequence on the function body:
IREE::Codegen::populateDropInnerTiledUnitDimsPatternsdrops the(now-unit) iter domain so the lowered op has empty iter bounds,
satisfying the precondition of (2).
IREE::Codegen::populateLowerInnerTiledPatternsreplaces theiter-free vector-semantics inner_tiled with the per-intrinsic
llvm.call_intrinsicops emitted byDataTiledMMAAttr::buildUnderlyingOperations.Both pattern sets were lifted out of
Codegen/Dialect/GPU/Transforms/into
Codegen/Dialect/Codegen/Transforms/in #24351so CPU can share them with GPU. They are interface-driven and pick up
CPU's
IREE::CPU::DataTiledMMAAttrtransparently via itsbuildUnderlyingOperationsimplementation.The pass expects vector-semantics input, which the upstream
GenericVectorizationPassproduces via theInnerTiledOpVectorizationModelVectorizableOpInterfaceexternalmodel already in tree. Schedule the new pass right after
GenericVectorizationPassinaddMmt4dTilingExpertPassPipeline, wheredata-tiled-MMA dispatches will land once the next commit teaches the
lowering strategy to route them through that pipeline. The pass is a
no-op when the function has no inner_tiled ops.
Adds a focused lit test
compiler/src/iree/compiler/Codegen/LLVMCPU/test/lower_inner_tiled.mlirthat feeds a single-tile AVX-512 1x16x1 f32 vector-semantics
inner_tiled and asserts the surviving
llvm.fma.v16f32call.Progress towards #24323