|
| 1 | +module attributes {transform.with_named_sequence} { |
| 2 | +//===----------------------------------------------------------------------===// |
| 3 | +// Tuning infra |
| 4 | +//===----------------------------------------------------------------------===// |
| 5 | + |
| 6 | + transform.named_sequence @apply_op_config(%arg0: !transform.any_op {transform.readonly}, %arg1: !transform.any_param {transform.readonly}) { |
| 7 | + transform.annotate %arg0 "compilation_info" = %arg1 : !transform.any_op, !transform.any_param |
| 8 | + transform.yield |
| 9 | + } |
| 10 | + |
| 11 | + |
| 12 | +// TUNING_SPEC_BEGIN DO NOT REMOVE |
| 13 | + |
| 14 | +//===----------------------------------------------------------------------===// |
| 15 | +// Matmul tuning |
| 16 | +//===----------------------------------------------------------------------===// |
| 17 | + |
| 18 | + transform.named_sequence @match_contraction_4608x21504x3072_bf16xbf16xf32(%arg0: !transform.any_op {transform.readonly}) -> (!transform.any_op, !transform.any_param) { |
| 19 | + %inputs, %outputs = transform.iree.match.cast_compatible_dag_from_root %arg0 { |
| 20 | + ^bb0(%arg1: tensor<4608x3072xbf16>, %arg2: tensor<21504x3072xbf16>, %arg3: tensor<4608x21504xf32>): |
| 21 | + %1 = linalg.generic {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 = ["parallel", "parallel", "reduction"]} ins(%arg1, %arg2 : tensor<4608x3072xbf16>, tensor<21504x3072xbf16>) outs(%arg3 : tensor<4608x21504xf32>) { |
| 22 | + ^bb0(%in: bf16, %in_0: bf16, %out: f32): |
| 23 | + %2 = arith.extf %in : bf16 to f32 |
| 24 | + %3 = arith.extf %in_0 : bf16 to f32 |
| 25 | + %4 = arith.mulf %2, %3 : f32 |
| 26 | + %5 = arith.addf %out, %4 : f32 |
| 27 | + linalg.yield %5 : f32 |
| 28 | + } -> tensor<4608x21504xf32> |
| 29 | + } : (!transform.any_op) -> (!transform.any_value, !transform.any_value) |
| 30 | + %0 = transform.param.constant #iree_codegen.compilation_info<lowering_config = #iree_gpu.lowering_config<{mma_kind = #iree_gpu.mma_layout<MFMA_F32_16x16x16_BF16>, promote_operands = [0, 1], reduction = [0, 0, 2], subgroup = [6, 4, 0], subgroup_m_count = 4 : i64, subgroup_n_count = 2 : i64, workgroup = [384, 128, 0]}>, translation_info = <pipeline = LLVMGPUTileAndFuse workgroup_size = [512, 1, 1] subgroup_size = 64, {gpu_pipeline_options = #iree_gpu.pipeline_options<prefetch_shared_memory = true, no_reduce_shared_memory_bank_conflicts = false>, llvm_func_attrs = {"amdgpu-waves-per-eu" = "2"}}>> -> !transform.any_param |
| 31 | + transform.yield %arg0, %0 : !transform.any_op, !transform.any_param |
| 32 | + } |
| 33 | + |
| 34 | + transform.named_sequence @match_contraction_4608x3072x4608_bf16xbf16xf32(%arg0: !transform.any_op {transform.readonly}) -> (!transform.any_op, !transform.any_param) { |
| 35 | + %inputs, %outputs = transform.iree.match.cast_compatible_dag_from_root %arg0 { |
| 36 | + ^bb0(%arg1: tensor<15360x4608xbf16>, %arg2: tensor<3072x15360xbf16>, %arg3: tensor<4608x3072xf32>): |
| 37 | + %1 = linalg.generic {indexing_maps = [affine_map<(d0, d1, d2) -> (d2, d0)>, affine_map<(d0, d1, d2) -> (d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1)>], iterator_types = ["parallel", "parallel", "reduction"]} ins(%arg1, %arg2 : tensor<15360x4608xbf16>, tensor<3072x15360xbf16>) outs(%arg3 : tensor<4608x3072xf32>) { |
| 38 | + ^bb0(%in: bf16, %in_0: bf16, %out: f32): |
| 39 | + %2 = arith.extf %in : bf16 to f32 |
| 40 | + %3 = arith.extf %in_0 : bf16 to f32 |
| 41 | + %4 = arith.mulf %2, %3 : f32 |
| 42 | + %5 = arith.addf %out, %4 : f32 |
| 43 | + linalg.yield %5 : f32 |
| 44 | + } -> tensor<4608x3072xf32> |
| 45 | + } : (!transform.any_op) -> (!transform.any_value, !transform.any_value) |
| 46 | + %0 = transform.param.constant #iree_codegen.compilation_info<lowering_config = #iree_gpu.lowering_config<{mma_kind = #iree_gpu.mma_layout<MFMA_F32_16x16x16_BF16>, promote_operands = [0, 1], reduction = [0, 0, 2], subgroup = [4, 4, 0], subgroup_m_count = 4 : i64, subgroup_n_count = 1 : i64, workgroup = [256, 64, 0]}>, 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>, llvm_func_attrs = {"amdgpu-waves-per-eu" = "2"}}>> -> !transform.any_param |
| 47 | + transform.yield %arg0, %0 : !transform.any_op, !transform.any_param |
| 48 | + } |
| 49 | + |
| 50 | + transform.named_sequence @match_contraction_4096x12288x3072_bf16xbf16xf32(%arg0: !transform.any_op {transform.readonly}) -> (!transform.any_op, !transform.any_param) { |
| 51 | + %inputs, %outputs = transform.iree.match.cast_compatible_dag_from_root %arg0 { |
| 52 | + ^bb0(%arg1: tensor<4096x3072xbf16>, %arg2: tensor<12288x3072xbf16>, %arg3: tensor<4096x12288xf32>): |
| 53 | + %1 = linalg.generic {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 = ["parallel", "parallel", "reduction"]} ins(%arg1, %arg2 : tensor<4096x3072xbf16>, tensor<12288x3072xbf16>) outs(%arg3 : tensor<4096x12288xf32>) { |
| 54 | + ^bb0(%in: bf16, %in_0: bf16, %out: f32): |
| 55 | + %2 = arith.extf %in : bf16 to f32 |
| 56 | + %3 = arith.extf %in_0 : bf16 to f32 |
| 57 | + %4 = arith.mulf %2, %3 : f32 |
| 58 | + %5 = arith.addf %out, %4 : f32 |
| 59 | + linalg.yield %5 : f32 |
| 60 | + } -> tensor<4096x12288xf32> |
| 61 | + } : (!transform.any_op) -> (!transform.any_value, !transform.any_value) |
| 62 | + %0 = transform.param.constant #iree_codegen.compilation_info<lowering_config = #iree_gpu.lowering_config<{mma_kind = #iree_gpu.mma_layout<MFMA_F32_16x16x16_BF16>, promote_operands = [0, 1], reduction = [0, 0, 6], subgroup = [2, 4, 0], subgroup_m_count = 4 : i64, subgroup_n_count = 2 : i64, workgroup = [128, 128, 0]}>, translation_info = <pipeline = LLVMGPUTileAndFuse workgroup_size = [512, 1, 1] subgroup_size = 64, {gpu_pipeline_options = #iree_gpu.pipeline_options<prefetch_shared_memory = true, no_reduce_shared_memory_bank_conflicts = false>, llvm_func_attrs = {"amdgpu-waves-per-eu" = "2"}}>> -> !transform.any_param |
| 63 | + transform.yield %arg0, %0 : !transform.any_op, !transform.any_param |
| 64 | + } |
| 65 | + |
| 66 | + transform.named_sequence @match_contraction_4096x3072x12288_bf16xbf16xf32(%arg0: !transform.any_op {transform.readonly}) -> (!transform.any_op, !transform.any_param) { |
| 67 | + %inputs, %outputs = transform.iree.match.cast_compatible_dag_from_root %arg0 { |
| 68 | + ^bb0(%arg1: tensor<4096x12288xbf16>, %arg2: tensor<3072x12288xbf16>, %arg3: tensor<4096x3072xf32>): |
| 69 | + %1 = linalg.generic {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 = ["parallel", "parallel", "reduction"]} ins(%arg1, %arg2 : tensor<4096x12288xbf16>, tensor<3072x12288xbf16>) outs(%arg3 : tensor<4096x3072xf32>) { |
| 70 | + ^bb0(%in: bf16, %in_0: bf16, %out: f32): |
| 71 | + %2 = arith.extf %in : bf16 to f32 |
| 72 | + %3 = arith.extf %in_0 : bf16 to f32 |
| 73 | + %4 = arith.mulf %2, %3 : f32 |
| 74 | + %5 = arith.addf %out, %4 : f32 |
| 75 | + linalg.yield %5 : f32 |
| 76 | + } -> tensor<4096x3072xf32> |
| 77 | + } : (!transform.any_op) -> (!transform.any_value, !transform.any_value) |
| 78 | + %0 = transform.param.constant #iree_codegen.compilation_info<lowering_config = #iree_gpu.lowering_config<{mma_kind = #iree_gpu.mma_layout<MFMA_F32_16x16x16_BF16>, promote_operands = [0, 1], reduction = [0, 0, 6], subgroup = [4, 2, 0], subgroup_m_count = 2 : i64, subgroup_n_count = 4 : i64, workgroup = [128, 128, 0]}>, translation_info = <pipeline = LLVMGPUTileAndFuse workgroup_size = [512, 1, 1] subgroup_size = 64, {gpu_pipeline_options = #iree_gpu.pipeline_options<prefetch_shared_memory = true, no_reduce_shared_memory_bank_conflicts = false>, llvm_func_attrs = {"amdgpu-waves-per-eu" = "2"}}>> -> !transform.any_param |
| 79 | + transform.yield %arg0, %0 : !transform.any_op, !transform.any_param |
| 80 | + } |
| 81 | + |
| 82 | + transform.named_sequence @match_contraction_72x4096x3072_bf16xbf16xf32(%arg0: !transform.any_op {transform.readonly}) -> (!transform.any_op, !transform.any_param) { |
| 83 | + %inputs, %outputs = transform.iree.match.cast_compatible_dag_from_root %arg0 { |
| 84 | + ^bb0(%arg1: tensor<4096x3072xbf16>, %arg2: tensor<72x128x3072xbf16>, %arg3: tensor<72x4096x128xf32>): |
| 85 | + %1 = linalg.generic {indexing_maps = [affine_map<(d0, d1, d2, d3) -> (d1, d3)>, affine_map<(d0, d1, d2, d3) -> (d0, d2, d3)>, affine_map<(d0, d1, d2, d3) -> (d0, d1, d2)>], iterator_types = ["parallel", "parallel", "parallel", "reduction"]} ins(%arg1, %arg2 : tensor<4096x3072xbf16>, tensor<72x128x3072xbf16>) outs(%arg3 : tensor<72x4096x128xf32>) { |
| 86 | + ^bb0(%in: bf16, %in_0: bf16, %out: f32): |
| 87 | + %2 = arith.extf %in : bf16 to f32 |
| 88 | + %3 = arith.extf %in_0 : bf16 to f32 |
| 89 | + %4 = arith.mulf %2, %3 : f32 |
| 90 | + %5 = arith.addf %out, %4 : f32 |
| 91 | + linalg.yield %5 : f32 |
| 92 | + } -> tensor<72x4096x128xf32> |
| 93 | + } : (!transform.any_op) -> (!transform.any_value, !transform.any_value) |
| 94 | + %0 = transform.param.constant #iree_codegen.compilation_info<lowering_config = #iree_gpu.lowering_config<{mma_kind = #iree_gpu.mma_layout<MFMA_F32_16x16x16_BF16>, promote_operands = [0, 1], reduction = [0, 0, 0, 2], subgroup = [4, 2, 2, 0], subgroup_m_count = 8 : i64, subgroup_n_count = 1 : i64, workgroup = [4, 256, 32, 0]}>, translation_info = <pipeline = LLVMGPUTileAndFuse workgroup_size = [512, 1, 1] subgroup_size = 64, {gpu_pipeline_options = #iree_gpu.pipeline_options<prefetch_shared_memory = true, no_reduce_shared_memory_bank_conflicts = false>, llvm_func_attrs = {"amdgpu-waves-per-eu" = "2"}}>> -> !transform.any_param |
| 95 | + transform.yield %arg0, %0 : !transform.any_op, !transform.any_param |
| 96 | + } |
| 97 | + |
| 98 | + transform.named_sequence @match_contraction_4096x3072x3072_bf16xbf16xf32(%arg0: !transform.any_op {transform.readonly}) -> (!transform.any_op, !transform.any_param) { |
| 99 | + %inputs, %outputs = transform.iree.match.cast_compatible_dag_from_root %arg0 { |
| 100 | + ^bb0(%arg1: tensor<4096x3072xbf16>, %arg2: tensor<3072x3072xbf16>, %arg3: tensor<4096x3072xf32>): |
| 101 | + %1 = linalg.generic {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 = ["parallel", "parallel", "reduction"]} ins(%arg1, %arg2 : tensor<4096x3072xbf16>, tensor<3072x3072xbf16>) outs(%arg3 : tensor<4096x3072xf32>) { |
| 102 | + ^bb0(%in: bf16, %in_0: bf16, %out: f32): |
| 103 | + %2 = arith.extf %in : bf16 to f32 |
| 104 | + %3 = arith.extf %in_0 : bf16 to f32 |
| 105 | + %4 = arith.mulf %2, %3 : f32 |
| 106 | + %5 = arith.addf %out, %4 : f32 |
| 107 | + linalg.yield %5 : f32 |
| 108 | + } -> tensor<4096x3072xf32> |
| 109 | + } : (!transform.any_op) -> (!transform.any_value, !transform.any_value) |
| 110 | + %0 = transform.param.constant #iree_codegen.compilation_info<lowering_config = #iree_gpu.lowering_config<{mma_kind = #iree_gpu.mma_layout<MFMA_F32_16x16x16_BF16>, promote_operands = [0, 1], reduction = [0, 0, 2], subgroup = [4, 6, 0], subgroup_m_count = 2 : i64, subgroup_n_count = 2 : i64, workgroup = [128, 192, 0]}>, 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>, llvm_func_attrs = {"amdgpu-waves-per-eu" = "2"}}>> -> !transform.any_param |
| 111 | + transform.yield %arg0, %0 : !transform.any_op, !transform.any_param |
| 112 | + } |
| 113 | + |
| 114 | + transform.named_sequence @match_contraction_512x12288x3072_bf16xbf16xf32(%arg0: !transform.any_op {transform.readonly}) -> (!transform.any_op, !transform.any_param) { |
| 115 | + %inputs, %outputs = transform.iree.match.cast_compatible_dag_from_root %arg0 { |
| 116 | + ^bb0(%arg1: tensor<512x3072xbf16>, %arg2: tensor<12288x3072xbf16>, %arg3: tensor<512x12288xf32>): |
| 117 | + %1 = linalg.generic {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 = ["parallel", "parallel", "reduction"]} ins(%arg1, %arg2 : tensor<512x3072xbf16>, tensor<12288x3072xbf16>) outs(%arg3 : tensor<512x12288xf32>) { |
| 118 | + ^bb0(%in: bf16, %in_0: bf16, %out: f32): |
| 119 | + %2 = arith.extf %in : bf16 to f32 |
| 120 | + %3 = arith.extf %in_0 : bf16 to f32 |
| 121 | + %4 = arith.mulf %2, %3 : f32 |
| 122 | + %5 = arith.addf %out, %4 : f32 |
| 123 | + linalg.yield %5 : f32 |
| 124 | + } -> tensor<512x12288xf32> |
| 125 | + } : (!transform.any_op) -> (!transform.any_value, !transform.any_value) |
| 126 | + %0 = transform.param.constant #iree_codegen.compilation_info<lowering_config = #iree_gpu.lowering_config<{mma_kind = #iree_gpu.mma_layout<MFMA_F32_16x16x16_BF16>, promote_operands = [0, 1], reduction = [0, 0, 6], subgroup = [4, 1, 0], subgroup_m_count = 1 : i64, subgroup_n_count = 4 : i64, workgroup = [64, 64, 0]}>, 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>, llvm_func_attrs = {"amdgpu-waves-per-eu" = "2"}}>> -> !transform.any_param |
| 127 | + transform.yield %arg0, %0 : !transform.any_op, !transform.any_param |
| 128 | + } |
| 129 | + |
| 130 | + transform.named_sequence @match_contraction_512x3072x12288_bf16xbf16xf32(%arg0: !transform.any_op {transform.readonly}) -> (!transform.any_op, !transform.any_param) { |
| 131 | + %inputs, %outputs = transform.iree.match.cast_compatible_dag_from_root %arg0 { |
| 132 | + ^bb0(%arg1: tensor<512x12288xbf16>, %arg2: tensor<3072x12288xbf16>, %arg3: tensor<512x3072xf32>): |
| 133 | + %1 = linalg.generic {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 = ["parallel", "parallel", "reduction"]} ins(%arg1, %arg2 : tensor<512x12288xbf16>, tensor<3072x12288xbf16>) outs(%arg3 : tensor<512x3072xf32>) { |
| 134 | + ^bb0(%in: bf16, %in_0: bf16, %out: f32): |
| 135 | + %2 = arith.extf %in : bf16 to f32 |
| 136 | + %3 = arith.extf %in_0 : bf16 to f32 |
| 137 | + %4 = arith.mulf %2, %3 : f32 |
| 138 | + %5 = arith.addf %out, %4 : f32 |
| 139 | + linalg.yield %5 : f32 |
| 140 | + } -> tensor<512x3072xf32> |
| 141 | + } : (!transform.any_op) -> (!transform.any_value, !transform.any_value) |
| 142 | + %0 = transform.param.constant #iree_codegen.compilation_info<lowering_config = #iree_gpu.lowering_config<{mma_kind = #iree_gpu.mma_layout<MFMA_F32_16x16x16_BF16>, promote_operands = [0, 1], reduction = [0, 0, 6], subgroup = [4, 2, 0], subgroup_m_count = 1 : i64, subgroup_n_count = 3 : i64, workgroup = [64, 96, 0]}>, translation_info = <pipeline = LLVMGPUTileAndFuse workgroup_size = [192, 1, 1] subgroup_size = 64, {gpu_pipeline_options = #iree_gpu.pipeline_options<prefetch_shared_memory = true, no_reduce_shared_memory_bank_conflicts = false>, llvm_func_attrs = {"amdgpu-waves-per-eu" = "2"}}>> -> !transform.any_param |
| 143 | + transform.yield %arg0, %0 : !transform.any_op, !transform.any_param |
| 144 | + } |
| 145 | + |
| 146 | +// TUNING_SPEC_END DO NOT REMOVE |
| 147 | + |
| 148 | +//===----------------------------------------------------------------------===// |
| 149 | +// Entry point |
| 150 | +//===----------------------------------------------------------------------===// |
| 151 | + |
| 152 | + transform.named_sequence @__kernel_config(%vairant_op: !transform.any_op {transform.consumed}) { |
| 153 | + transform.foreach_match in %vairant_op |
| 154 | + |
| 155 | + // TUNING_MATCH_BEGIN DO NOT REMOVE |
| 156 | + @match_contraction_4608x21504x3072_bf16xbf16xf32 -> @apply_op_config // 588 |
| 157 | + , @match_contraction_4608x3072x4608_bf16xbf16xf32 -> @apply_op_config // 603 |
| 158 | + , @match_contraction_4096x12288x3072_bf16xbf16xf32 -> @apply_op_config // 40 |
| 159 | + , @match_contraction_4096x3072x12288_bf16xbf16xf32 -> @apply_op_config // 41 |
| 160 | + , @match_contraction_72x4096x3072_bf16xbf16xf32 -> @apply_op_config // 19 |
| 161 | + , @match_contraction_4096x3072x3072_bf16xbf16xf32 -> @apply_op_config // 38 |
| 162 | + , @match_contraction_512x12288x3072_bf16xbf16xf32 -> @apply_op_config // 44 |
| 163 | + , @match_contraction_512x3072x12288_bf16xbf16xf32 -> @apply_op_config // 45 |
| 164 | + |
| 165 | + // TUNING_MATCH_END DO NOT REMOVE |
| 166 | + |
| 167 | + : (!transform.any_op) -> !transform.any_op |
| 168 | + transform.yield |
| 169 | + } |
| 170 | +} |
0 commit comments