Skip to content

Commit 143db48

Browse files
jschuhmachermbknust
authored andcommitted
[mlir][VectorToGPU] Reconsider cached slices after rejected candidates
A rejected elementwise candidate can visit a contraction through a loop induction variable without belonging to that contraction's convertible slice. Only skip seeds already selected for conversion, while retaining the backward/forward slice caches. Fixes regression from d287e55d0302. Assisted-by: Codex
1 parent f5b7a17 commit 143db48

3 files changed

Lines changed: 50 additions & 2 deletions

File tree

‎mlir/lib/Conversion/VectorToGPU/VectorToGPU.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ static SetVector<Operation *> getOpToConvert(mlir::Operation *op) {
280280
if (!isa<vector::ContractionOp>(nestedOp) &&
281281
!elementwiseSupportsMMAMatrixType(nestedOp))
282282
return;
283-
if (backwardSliceCache.contains(nestedOp))
283+
if (opToConvert.contains(nestedOp))
284284
return;
285285

286286
SetVector<Operation *> dependentOps;

‎mlir/lib/Conversion/VectorToNVGPU/VectorToNVGPU.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static SetVector<Operation *> getOpToConvert(mlir::Operation *op) {
220220
if (!isa<vector::ContractionOp>(nestedOp) &&
221221
!elementwiseSupportsMMAMatrixType(nestedOp))
222222
return;
223-
if (backwardSliceCache.contains(nestedOp))
223+
if (opToConvert.contains(nestedOp))
224224
return;
225225

226226
SetVector<Operation *> dependentOps;

‎mlir/test/Conversion/VectorToGPU/vector-to-mma-ops.mlir‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,3 +814,51 @@ func.func @masked_matmul_km_nk_nm(%arg0: vector<16x16xf16>, %arg1: vector<16x16x
814814
%D = vector.mask %mask { vector.contract {indexing_maps = [#map1, #map4, #map5], iterator_types = ["parallel", "parallel", "reduction"], kind = #vector.kind<add>} %arg0, %arg1, %arg2 : vector<16x16xf16>, vector<16x16xf16> into vector<16x16xf16> } : vector<16x16x16xi1> -> vector<16x16xf16>
815815
return %D : vector<16x16xf16>
816816
}
817+
818+
// -----
819+
820+
// A rejected elementwise slice may visit a convertible contraction through the
821+
// loop induction variable without making its conversion invalid.
822+
// CHECK-LABEL: func.func @mma_after_rejected_elementwise_slice
823+
// CHECK: gpu.subgroup_mma_constant_matrix
824+
// CHECK: scf.for
825+
// CHECK: vector.gather
826+
// CHECK: gpu.subgroup_mma_compute
827+
// CHECK: gpu.subgroup_mma_store_matrix
828+
func.func @mma_after_rejected_elementwise_slice(%0: memref<32x32xf32>, %1: memref<32x32xf32>, %2: memref<32x32xf32>) {
829+
%c0 = arith.constant 0 : index
830+
%cst = arith.constant dense<0.000000e+00> : vector<16x16xf32>
831+
%cst_mask = arith.constant dense<true> : vector<4x4xi1>
832+
%cst_pt = arith.constant dense<0.000000e+00> : vector<4x4xf32>
833+
%c16 = arith.constant 16 : index
834+
%c32 = arith.constant 32 : index
835+
%cst_0 = arith.constant 0.000000e+00 : f32
836+
%cst_1 = arith.constant dense<[0, 1, 2, 3]> : vector<4xindex>
837+
%cst_2 = arith.constant dense<1> : vector<4x4xindex>
838+
%alloc = memref.alloc() alignment = 64 : memref<32x32xf32>
839+
%3 = gpu.thread_id x
840+
%4 = gpu.thread_id y
841+
%5 = affine.apply affine_map<()[s0] -> (s0 * 16)>()[%4]
842+
%6 = affine.apply affine_map<()[s0] -> ((s0 floordiv 32) * 16)>()[%3]
843+
%7 = scf.for %arg0 = %c0 to %c32 step %c16 iter_args(%arg1 = %cst) -> (vector<16x16xf32>) {
844+
%10 = vector.broadcast %arg0 : index to vector<4xindex>
845+
%11 = arith.addi %10, %cst_1 : vector<4xindex>
846+
%12 = vector.broadcast %11 : vector<4xindex> to vector<4x4xindex>
847+
%13 = arith.addi %12, %cst_2 : vector<4x4xindex>
848+
%14 = vector.gather %0[%c0, %c0] [%13], %cst_mask, %cst_pt : memref<32x32xf32>, vector<4x4xindex>, vector<4x4xi1>, vector<4x4xf32> into vector<4x4xf32>
849+
vector.transfer_write %14, %alloc[%c0, %c0] {in_bounds = [true, true]} : vector<4x4xf32>, memref<32x32xf32>
850+
gpu.barrier memfence [#gpu.address_space<workgroup>]
851+
%15 = affine.apply affine_map<(d0)[s0] -> (d0 + s0)>(%c0)[%5]
852+
%16 = affine.apply affine_map<(d0)[s0] -> (d0 + s0)>(%c0)[%arg0]
853+
%17 = vector.transfer_read %alloc[%15, %16], %cst_0 {in_bounds = [true, true]} : memref<32x32xf32>, vector<16x16xf32>
854+
%18 = affine.apply affine_map<(d0)[s0] -> (d0 + s0)>(%c0)[%6]
855+
%19 = affine.apply affine_map<(d0)[s0] -> (d0 + s0)>(%c0)[%arg0]
856+
%20 = vector.transfer_read %1[%19, %18], %cst_0 {in_bounds = [true, true]} : memref<32x32xf32>, vector<16x16xf32>
857+
%21 = vector.contract {indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d2)>, affine_map<(d0, d1, d2) -> (d2, d1)>, affine_map<(d0, d1, d2) -> (d0, d1)>], iterator_types = ["parallel", "parallel", "reduction"], kind = #vector.kind<add>} %17, %20, %arg1 : vector<16x16xf32>, vector<16x16xf32> into vector<16x16xf32>
858+
scf.yield %21 : vector<16x16xf32>
859+
}
860+
%8 = affine.apply affine_map<(d0)[s0] -> (d0 + s0)>(%c0)[%5]
861+
%9 = affine.apply affine_map<(d0)[s0] -> (d0 + s0)>(%c0)[%6]
862+
vector.transfer_write %7, %2[%8, %9] {in_bounds = [true, true]} : vector<16x16xf32>, memref<32x32xf32>
863+
return
864+
}

0 commit comments

Comments
 (0)