Repository navigation
Introduce a "vector.contract custom kernels" pass - #7778
Conversation
d0ddc85 to
657f03d
Compare
MaheshRavishankar
left a comment
There was a problem hiding this comment.
I left a few comments. Most of them are minor.
My main comment though is that this is flattening to 1D too early. It'd be good to leave it non-1D at this stage and linearize it later. You can add a separate pass before lowering to LLVM for this if you want.
c0bc750 to
b535bd8
Compare
Done. |
99b39d1 to
9e4e9bc
Compare
3adb49c to
4c5f54e
Compare
MaheshRavishankar
left a comment
There was a problem hiding this comment.
Nice! Mostly concerned about an LLVM dependency, but otherwise this looks good.
| "//iree/compiler/Dialect/Flow/IR", | ||
| "//iree/compiler/Dialect/HAL/IR", | ||
| "//iree/compiler/Dialect/HAL/IR:HALDialect", | ||
| "//iree/compiler/Dialect/HAL/Target/LLVM:LLVMTargetOptions", |
There was a problem hiding this comment.
I am not sure this is needed here. Just noting this here as I review this PR. Will come back to this once I get through the review.
There was a problem hiding this comment.
removed, all i needed was llvm/ADT/Triple.h.
| populateLinalgToVectorVectorizeMMT4dPatterns(context, vectorizeOpsPattenrs); | ||
| if (failed(applyPatternsAndFoldGreedily(funcOp, | ||
| std::move(vectorizeOpsPattenrs)))) { | ||
| RewritePatternSet patterns(context); |
There was a problem hiding this comment.
I see this pattern used in two places. We need to decide which path we are going to take for MMT4D. Lot of this is kept around based on decision made here. Ideally we need this along only a single pipeline.
There was a problem hiding this comment.
Right, I updated this PR to only use the newer LLVMCPUTileFustAndVectorizeLinalgTensorOps.cpp:
--- a/iree/compiler/Codegen/LLVMCPU/KernelDispatch.cpp
+++ b/iree/compiler/Codegen/LLVMCPU/KernelDispatch.cpp
@@ -87,12 +87,9 @@ static Optional<llvm::Triple> getTargetTriple(FuncOp entryPointFn) {
static DispatchLoweringPassPipeline getDispatchLoweringPassPipeline(
FuncOp entryPointFn, Operation *op) {
return TypeSwitch<Operation *, DispatchLoweringPassPipeline>(op)
- .Case<linalg::ContractionOpInterface>([&](auto op) {
+ .Case<linalg::ContractionOpInterface, linalg::Mmt4DOp>([&](auto op) {
return DispatchLoweringPassPipeline::CPUTileFuseAndVectorize;
})
- .Case<linalg::Mmt4DOp>([&](auto op) {
- return DispatchLoweringPassPipeline::CPUTensorToVectors;
- })and I dropped the changes to the old pipeline.
This fixes the codegen for the 2d vector transfers that we need to do in matmul kernels targeting 2D (matrix) simd operations, for instance allowing PR iree-org#7778 to achieve nice codegen such as: ``` 11a14: ad 05 00 f1 subs x13, x13, #1 11a18: f8 66 c1 ac ldp q24, q25, [x23], iree-org#32 11a1c: 7a 6f c1 ac ldp q26, q27, [x27], iree-org#32 11a20: 41 e3 98 4f sdot v1.4s, v26.16b, v24.4b[0] 11a24: 60 e3 98 4f sdot v0.4s, v27.16b, v24.4b[0] 11a28: 43 e3 b8 4f sdot v3.4s, v26.16b, v24.4b[1] 11a2c: 62 e3 b8 4f sdot v2.4s, v27.16b, v24.4b[1] 11a30: 46 eb 98 4f sdot v6.4s, v26.16b, v24.4b[2] 11a34: 64 eb 98 4f sdot v4.4s, v27.16b, v24.4b[2] 11a38: 53 eb b8 4f sdot v19.4s, v26.16b, v24.4b[3] 11a3c: 70 eb b8 4f sdot v16.4s, v27.16b, v24.4b[3] 11a40: 54 e3 99 4f sdot v20.4s, v26.16b, v25.4b[0] 11a44: 71 e3 99 4f sdot v17.4s, v27.16b, v25.4b[0] 11a48: 57 e3 b9 4f sdot v23.4s, v26.16b, v25.4b[1] 11a4c: 76 e3 b9 4f sdot v22.4s, v27.16b, v25.4b[1] 11a50: 55 eb 99 4f sdot v21.4s, v26.16b, v25.4b[2] 11a54: 72 eb 99 4f sdot v18.4s, v27.16b, v25.4b[2] 11a58: 47 eb b9 4f sdot v7.4s, v26.16b, v25.4b[3] 11a5c: 65 eb b9 4f sdot v5.4s, v27.16b, v25.4b[3] 11a60: a1 fd ff 54 b.ne 0x11a14 <.text+0x11a8> ```
MaheshRavishankar
left a comment
There was a problem hiding this comment.
Ok, I dont think I have more to review on this. Thanks for pushing on this and working through the whole host of first user issues here!
This fixes the codegen for the 2d vector transfers that we need to do in matmul kernels targeting 2D (matrix) simd operations, for instance allowing PR iree-org#7778 to achieve nice codegen such as: ``` 11a14: ad 05 00 f1 subs x13, x13, #1 11a18: f8 66 c1 ac ldp q24, q25, [x23], iree-org#32 11a1c: 7a 6f c1 ac ldp q26, q27, [x27], iree-org#32 11a20: 41 e3 98 4f sdot v1.4s, v26.16b, v24.4b[0] 11a24: 60 e3 98 4f sdot v0.4s, v27.16b, v24.4b[0] 11a28: 43 e3 b8 4f sdot v3.4s, v26.16b, v24.4b[1] 11a2c: 62 e3 b8 4f sdot v2.4s, v27.16b, v24.4b[1] 11a30: 46 eb 98 4f sdot v6.4s, v26.16b, v24.4b[2] 11a34: 64 eb 98 4f sdot v4.4s, v27.16b, v24.4b[2] 11a38: 53 eb b8 4f sdot v19.4s, v26.16b, v24.4b[3] 11a3c: 70 eb b8 4f sdot v16.4s, v27.16b, v24.4b[3] 11a40: 54 e3 99 4f sdot v20.4s, v26.16b, v25.4b[0] 11a44: 71 e3 99 4f sdot v17.4s, v27.16b, v25.4b[0] 11a48: 57 e3 b9 4f sdot v23.4s, v26.16b, v25.4b[1] 11a4c: 76 e3 b9 4f sdot v22.4s, v27.16b, v25.4b[1] 11a50: 55 eb 99 4f sdot v21.4s, v26.16b, v25.4b[2] 11a54: 72 eb 99 4f sdot v18.4s, v27.16b, v25.4b[2] 11a58: 47 eb b9 4f sdot v7.4s, v26.16b, v25.4b[3] 11a5c: 65 eb b9 4f sdot v5.4s, v27.16b, v25.4b[3] 11a60: a1 fd ff 54 b.ne 0x11a14 <.text+0x11a8> ```
cc3e9bc to
9c147eb
Compare
This fixes the codegen for the 2d vector transfers that we need to do in matmul kernels targeting 2D (matrix) simd operations, for instance allowing PR #7778 to achieve nice codegen such as: ``` 11a14: ad 05 00 f1 subs x13, x13, #1 11a18: f8 66 c1 ac ldp q24, q25, [x23], #32 11a1c: 7a 6f c1 ac ldp q26, q27, [x27], #32 11a20: 41 e3 98 4f sdot v1.4s, v26.16b, v24.4b[0] 11a24: 60 e3 98 4f sdot v0.4s, v27.16b, v24.4b[0] 11a28: 43 e3 b8 4f sdot v3.4s, v26.16b, v24.4b[1] 11a2c: 62 e3 b8 4f sdot v2.4s, v27.16b, v24.4b[1] 11a30: 46 eb 98 4f sdot v6.4s, v26.16b, v24.4b[2] 11a34: 64 eb 98 4f sdot v4.4s, v27.16b, v24.4b[2] 11a38: 53 eb b8 4f sdot v19.4s, v26.16b, v24.4b[3] 11a3c: 70 eb b8 4f sdot v16.4s, v27.16b, v24.4b[3] 11a40: 54 e3 99 4f sdot v20.4s, v26.16b, v25.4b[0] 11a44: 71 e3 99 4f sdot v17.4s, v27.16b, v25.4b[0] 11a48: 57 e3 b9 4f sdot v23.4s, v26.16b, v25.4b[1] 11a4c: 76 e3 b9 4f sdot v22.4s, v27.16b, v25.4b[1] 11a50: 55 eb 99 4f sdot v21.4s, v26.16b, v25.4b[2] 11a54: 72 eb 99 4f sdot v18.4s, v27.16b, v25.4b[2] 11a58: 47 eb b9 4f sdot v7.4s, v26.16b, v25.4b[3] 11a5c: 65 eb b9 4f sdot v5.4s, v27.16b, v25.4b[3] 11a60: a1 fd ff 54 b.ne 0x11a14 <.text+0x11a8> ```
This is refurbishing Ahmed Taei's existing VectorContractToAArch64InlineAsmOp pass, repurposing it to implementing matrix-times-matrix-transposed kernels, and generalizing it to create a good insertion point for any other vector.contract custom "handwritten" kernel, using either inline assembly or intrinsics.
9c147eb to
f5a33cc
Compare
|
Thanks for powering through and getting this landed Benoit ❤️ |
|
Thanks for the tireless help and attention to detail! It's going to be a lot more exciting from here on. |
This is refurbishing @asaadaldien's existing
VectorContractToAArch64InlineAsmOp pass, repurposing it to implementing
matrix-times-matrix-transposed kernels, and generalizing it to create a
good insertion point for any other vector.contract custom "handwritten"
kernel, using either inline assembly or intrinsics.