Repository navigation
Open
Description
For this IR
func.func @conv_2d_bfloat16_forward_4x30x46x2016_nhwc_1024x1x1x2016_fhwc_nhwf_1x1s_0x0p_1x1d_1g$async_dispatch_0_matmul_like_5520x1024x2016_bf16xbf16xf32() attributes {translation_info = #iree_codegen.translation_info<pipeline = LLVMGPUTileAndFuse workgroup_size = [256, 1, 1] subgroup_size = 64, {gpu_pipeline_options = #iree_gpu.pipeline_options<prefetch_shared_memory = true, no_reduce_shared_memory_bank_conflicts = false, use_igemm_convolution = false>}>} {
%c256 = arith.constant 256 : index
%c512 = arith.constant 512 : index
%c2 = arith.constant 2 : index
%c126 = arith.constant 126 : index
%cst = arith.constant 0.000000e+00 : bf16
%cst_0 = arith.constant 0.000000e+00 : f32
%c0 = arith.constant 0 : index
%0 = hal.interface.binding.subspan layout(<bindings = [#hal.pipeline.binding<storage_buffer, "ReadOnly|Indirect">, #hal.pipeline.binding<storage_buffer, "ReadOnly|Indirect">, #hal.pipeline.binding<storage_buffer, Indirect>], flags = Indirect>) binding(0) alignment(64) offset(%c0) flags("ReadOnly|Indirect") {iree_gpu.use_rocdl_buffer_instructions} : !iree_tensor_ext.dispatch.tensor<readonly:tensor<5520x2016xbf16>>
%1 = hal.interface.binding.subspan layout(<bindings = [#hal.pipeline.binding<storage_buffer, "ReadOnly|Indirect">, #hal.pipeline.binding<storage_buffer, "ReadOnly|Indirect">, #hal.pipeline.binding<storage_buffer, Indirect>], flags = Indirect>) binding(1) alignment(64) offset(%c0) flags("ReadOnly|Indirect") {iree_gpu.use_rocdl_buffer_instructions} : !iree_tensor_ext.dispatch.tensor<readonly:tensor<1024x2016xbf16>>
%2 = hal.interface.binding.subspan layout(<bindings = [#hal.pipeline.binding<storage_buffer, "ReadOnly|Indirect">, #hal.pipeline.binding<storage_buffer, "ReadOnly|Indirect">, #hal.pipeline.binding<storage_buffer, Indirect>], flags = Indirect>) binding(2) alignment(64) offset(%c0) flags(Indirect) {iree_gpu.use_rocdl_buffer_instructions} : !iree_tensor_ext.dispatch.tensor<writeonly:tensor<5520x1024xbf16>>
%3 = iree_tensor_ext.dispatch.tensor.load %0, offsets = [0, 0], sizes = [5520, 2016], strides = [1, 1] : !iree_tensor_ext.dispatch.tensor<readonly:tensor<5520x2016xbf16>> -> tensor<5520x2016xbf16>
%4 = iree_tensor_ext.dispatch.tensor.load %1, offsets = [0, 0], sizes = [1024, 2016], strides = [1, 1] : !iree_tensor_ext.dispatch.tensor<readonly:tensor<1024x2016xbf16>> -> tensor<1024x2016xbf16>
%5 = tensor.empty() : tensor<5520x1024xbf16>
%6 = scf.forall (%arg0, %arg1) in (44, 8) shared_outs(%arg2 = %5) -> (tensor<5520x1024xbf16>) {
%7 = affine.apply affine_map<(d0) -> (d0 * 128)>(%arg1)
%8 = affine.apply affine_map<(d0) -> (d0 * 128)>(%arg0)
%9 = affine.min affine_map<(d0) -> (d0 * -128 + 5520, 128)>(%arg0)
%extracted_slice = tensor.extract_slice %arg2[%8, %7] [%9, 128] [1, 1] : tensor<5520x1024xbf16> to tensor<?x128xbf16>
%10 = affine.min affine_map<(d0) -> (d0 * -128 + 5520, 0, 128)>(%arg0)
%11 = affine.min affine_map<(d0, d1) -> (128, d0 - d1)>(%9, %10)
%12 = bufferization.alloc_tensor() {memory_space = #gpu.address_space<workgroup>} : tensor<128x32xbf16>
%13 = bufferization.alloc_tensor() {memory_space = #gpu.address_space<workgroup>} : tensor<128x32xbf16>
%14 = tensor.empty() : tensor<8x16x8x16xf32>
%15 = scf.forall (%arg3, %arg4, %arg5) in (2, 2, 64) shared_outs(%arg6 = %14) -> (tensor<8x16x8x16xf32>) {
%17:3 = affine.delinearize_index %arg5 into (4, 16) : index, index, index
%18 = affine.linearize_index disjoint [%17#1, %c0] by (4, 4) : index
%19 = tensor.empty() : tensor<4x4x4x1xf32>
%20 = linalg.fill ins(%cst_0 : f32) outs(%19 : tensor<4x4x4x1xf32>) -> tensor<4x4x4x1xf32>
%21 = scf.for %arg7 = %c0 to %c126 step %c2 iter_args(%arg8 = %20) -> (tensor<4x4x4x1xf32>) {
%26 = iree_gpu.barrier_region ins(%13 : tensor<128x32xbf16>) {
^bb0(%arg9: tensor<128x32xbf16>):
%32 = scf.for %arg10 = %c0 to %c512 step %c256 iter_args(%arg11 = %arg9) -> (tensor<128x32xbf16>) {
%33 = affine.apply affine_map<(d0, d1, d2, d3) -> (d0 + d1 + d2 * 128 + d3 * 64)>(%arg10, %arg5, %arg3, %arg4)
%34:2 = affine.delinearize_index %33 into (128, 4) : index, index
%35 = affine.apply affine_map<(d0) -> (d0 * 8)>(%34#1)
%extracted_slice_8 = tensor.extract_slice %arg11[%34#0, %35] [1, 8] [1, 1] : tensor<128x32xbf16> to tensor<1x8xbf16>
%36 = affine.min affine_map<(d0, d1, d2) -> (128, d1 - d2, d0)>(%34#0, %9, %10)
%37 = affine.min affine_map<(d0, d1) -> (1, d0 - d1)>(%11, %36)
%38 = affine.apply affine_map<(d0) -> (-d0 + 1)>(%37)
%39 = affine.apply affine_map<(d0)[s0, s1] -> (d0 * 128 + s0 + s1)>(%arg0)[%36, %10]
%40 = affine.apply affine_map<(d0, d1) -> (d0 * 16 + d1 * 8)>(%arg7, %34#1)
%extracted_slice_9 = tensor.extract_slice %3[%39, %40] [%37, 8] [1, 1] : tensor<5520x2016xbf16> to tensor<?x8xbf16>
%padded = tensor.pad %extracted_slice_9 low[0, 0] high[%38, 0] {
^bb0(%arg12: index, %arg13: index):
tensor.yield %cst : bf16
} : tensor<?x8xbf16> to tensor<1x8xbf16>
%41 = linalg.copy {lowering_config = #iree_gpu.derived_thread_config} ins(%padded : tensor<1x8xbf16>) outs(%extracted_slice_8 : tensor<1x8xbf16>) -> tensor<1x8xbf16>
%inserted_slice = tensor.insert_slice %41 into %arg11[%34#0, %35] [1, 8] [1, 1] : tensor<1x8xbf16> into tensor<128x32xbf16>
scf.yield %inserted_slice : tensor<128x32xbf16>
} {unroll_loop}
iree_gpu.yield %32 : tensor<128x32xbf16>
} : tensor<128x32xbf16>
%27 = iree_gpu.barrier_region ins(%12 : tensor<128x32xbf16>) {
^bb0(%arg9: tensor<128x32xbf16>):
%32 = scf.for %arg10 = %c0 to %c512 step %c256 iter_args(%arg11 = %arg9) -> (tensor<128x32xbf16>) {
%33 = affine.apply affine_map<(d0, d1, d2, d3) -> (d0 + d1 + d2 * 128 + d3 * 64)>(%arg10, %arg5, %arg3, %arg4)
%34:2 = affine.delinearize_index %33 into (128, 4) : index, index
%35 = affine.apply affine_map<(d0) -> (d0 * 8)>(%34#1)
%extracted_slice_8 = tensor.extract_slice %arg11[%34#0, %35] [1, 8] [1, 1] : tensor<128x32xbf16> to tensor<1x8xbf16>
%36 = affine.apply affine_map<(d0)[s0] -> (d0 * 128 + s0)>(%arg1)[%34#0]
%37 = affine.apply affine_map<(d0, d1) -> (d0 * 16 + d1 * 8)>(%arg7, %34#1)
%extracted_slice_9 = tensor.extract_slice %4[%36, %37] [1, 8] [1, 1] : tensor<1024x2016xbf16> to tensor<1x8xbf16>
%38 = linalg.copy {lowering_config = #iree_gpu.derived_thread_config} ins(%extracted_slice_9 : tensor<1x8xbf16>) outs(%extracted_slice_8 : tensor<1x8xbf16>) -> tensor<1x8xbf16>
%inserted_slice = tensor.insert_slice %38 into %arg11[%34#0, %35] [1, 8] [1, 1] : tensor<1x8xbf16> into tensor<128x32xbf16>
scf.yield %inserted_slice : tensor<128x32xbf16>
} {unroll_loop}
iree_gpu.yield %32 : tensor<128x32xbf16>
} : tensor<128x32xbf16>
%28 = affine.apply affine_map<(d0) -> (d0 * 4)>(%arg4)
%29 = affine.apply affine_map<(d0) -> (d0 * 4)>(%arg3)
%expanded = tensor.expand_shape %27 [[0, 1], [2, 3]] output_shape [8, 16, 2, 16] : tensor<128x32xbf16> into tensor<8x16x2x16xbf16>
%extracted_slice_3 = tensor.extract_slice %expanded[%28, %17#2, 0, %18] [4, 1, 2, 4] [1, 1, 1, 1] : tensor<8x16x2x16xbf16> to tensor<4x1x2x4xbf16>
%expanded_4 = tensor.expand_shape %26 [[0, 1], [2, 3]] output_shape [8, 16, 2, 16] : tensor<128x32xbf16> into tensor<8x16x2x16xbf16>
%extracted_slice_5 = tensor.extract_slice %expanded_4[%29, %17#2, 0, %18] [4, 1, 2, 4] [1, 1, 1, 1] : tensor<8x16x2x16xbf16> to tensor<4x1x2x4xbf16>
%30 = tensor.empty() : tensor<4x2x1x4xbf16>
%transposed_6 = linalg.transpose ins(%extracted_slice_5 : tensor<4x1x2x4xbf16>) outs(%30 : tensor<4x2x1x4xbf16>) permutation = [0, 2, 1, 3]
%transposed_7 = linalg.transpose ins(%extracted_slice_3 : tensor<4x1x2x4xbf16>) outs(%30 : tensor<4x2x1x4xbf16>) permutation = [0, 2, 1, 3]
%31 = iree_codegen.inner_tiled ins(%transposed_6, %transposed_7) outs(%arg8) {indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d2)>, affine_map<(d0, d1, d2) -> (d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1)>], iterator_types = [#linalg.iterator_type<parallel>, #linalg.iterator_type<parallel>, #linalg.iterator_type<reduction>], kind = #iree_gpu.mma_layout<MFMA_F32_16x16x16_BF16>, lowering_config = #iree_gpu.lowering_config<{mma_kind = #iree_gpu.mma_layout<MFMA_F32_16x16x16_BF16>, padding = [128, 128, 32], promote_operands = [0, 1], reduction = [0, 0, 2], subgroup = [4, 4, 0], workgroup = [128, 128, 0]}>} : tensor<4x2x1x4xbf16>, tensor<4x2x1x4xbf16> into tensor<4x4x4x1xf32>
scf.yield %31 : tensor<4x4x4x1xf32>
}
%22 = tensor.empty() : tensor<4x4x4x1xf32>
%transposed = linalg.transpose ins(%21 : tensor<4x4x4x1xf32>) outs(%22 : tensor<4x4x4x1xf32>) permutation = [0, 2, 1, 3]
%23 = affine.apply affine_map<(d0) -> (d0 * 4)>(%arg3)
%24 = affine.apply affine_map<(d0) -> (d0 * 4)>(%arg4)
%extracted_slice_2 = tensor.extract_slice %arg6[%23, %18, %24, %17#2] [4, 4, 4, 1] [1, 1, 1, 1] : tensor<8x16x8x16xf32> to tensor<4x4x4x1xf32>
%25 = linalg.copy ins(%transposed : tensor<4x4x4x1xf32>) outs(%extracted_slice_2 : tensor<4x4x4x1xf32>) -> tensor<4x4x4x1xf32>
scf.forall.in_parallel {
tensor.parallel_insert_slice %25 into %arg6[%23, %18, %24, %17#2] [4, 4, 4, 1] [1, 1, 1, 1] : tensor<4x4x4x1xf32> into tensor<8x16x8x16xf32>
}
} {mapping = [#gpu.thread<linear_dim_2>, #gpu.thread<linear_dim_1>, #gpu.thread<linear_dim_0>]}
%collapsed = tensor.collapse_shape %15 [[0, 1], [2, 3]] : tensor<8x16x8x16xf32> into tensor<128x128xf32>
%extracted_slice_1 = tensor.extract_slice %collapsed[0, 0] [%9, 128] [1, 1] : tensor<128x128xf32> to tensor<?x128xf32>
%16 = linalg.generic {indexing_maps = [affine_map<(d0, d1) -> (d0, d1)>, affine_map<(d0, d1) -> (d0, d1)>], iterator_types = ["parallel", "parallel"]} ins(%extracted_slice_1 : tensor<?x128xf32>) outs(%extracted_slice : tensor<?x128xbf16>) {
^bb0(%in: f32, %out: bf16):
%17 = arith.truncf %in : f32 to bf16
linalg.yield %17 : bf16
} -> tensor<?x128xbf16>
scf.forall.in_parallel {
tensor.parallel_insert_slice %16 into %arg2[%8, %7] [%9, 128] [1, 1] : tensor<?x128xbf16> into tensor<5520x1024xbf16>
}
} {mapping = [#iree_codegen.workgroup_mapping<y>, #iree_codegen.workgroup_mapping<x>]}
iree_tensor_ext.dispatch.tensor.store %6, %2, offsets = [0, 0], sizes = [5520, 1024], strides = [1, 1] : tensor<5520x1024xbf16> -> !iree_tensor_ext.dispatch.tensor<writeonly:tensor<5520x1024xbf16>>
return
}
Run
iree-opt --pass-pipeline="builtin.module(func.func(iree-codegen-combine-layout-transformation))" test.mlir
The elementwise generic is not fusing into the thread loop. This issue is causing the no c promotion path for unaligned GEMMs/Convs to fail as it creates a third allocation.
Metadata
Metadata
Assignees
Labels
No labels
Activity
nirvedhmeshram commentedon Aug 8, 2025
This revert had no effect on this a005576
nirvedhmeshram commentedon Aug 8, 2025
Here are also steps for a full repro
Input IR
compile command