|
| 1 | +// RUN: mlir-opt --xegpu-wg-to-sg-distribute -split-input-file %s | FileCheck %s |
| 2 | + |
| 3 | +gpu.module @test_elementwise_ops { |
| 4 | + // CHECK-LABEL: unary_ops |
| 5 | + gpu.func @unary_ops(%a: memref<24x32xf32>) { |
| 6 | + %tdesc_a = xegpu.create_nd_tdesc %a[0, 0] : memref<24x32xf32> |
| 7 | + -> !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 8 | + %load_a = xegpu.load_nd %tdesc_a |
| 9 | + : !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 10 | + -> vector<24x32xf32> |
| 11 | + // CHECK: math.exp {{.*}} {layout_result_0 = #xegpu.layout<lane_layout = [2, 8], lane_data = [1, 1]>} : vector<12x8xf32> |
| 12 | + %exp = math.exp %load_a |
| 13 | + {layout_result_0 = #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>} |
| 14 | + : vector<24x32xf32> |
| 15 | + // CHECK: arith.negf {{.*}} {layout_result_0 = #xegpu.layout<lane_layout = [2, 8], lane_data = [1, 1]>} : vector<12x8xf32> |
| 16 | + %negf = arith.negf %load_a |
| 17 | + {layout_result_0 = #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>} |
| 18 | + : vector<24x32xf32> |
| 19 | + gpu.return |
| 20 | + } |
| 21 | + |
| 22 | + // CHECK-LABEL: binary_ops |
| 23 | + gpu.func @binary_ops(%a: memref<24x32xf32>, %b: memref<24x32xf32>) { |
| 24 | + %tdesc_a = xegpu.create_nd_tdesc %a[0, 0] : memref<24x32xf32> |
| 25 | + -> !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 26 | + %tdesc_b = xegpu.create_nd_tdesc %b[0, 0] : memref<24x32xf32> |
| 27 | + -> !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 28 | + %load_a = xegpu.load_nd %tdesc_a |
| 29 | + : !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 30 | + -> vector<24x32xf32> |
| 31 | + %load_b = xegpu.load_nd %tdesc_b |
| 32 | + : !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 33 | + -> vector<24x32xf32> |
| 34 | + // CHECK: arith.addf {{.*}}, {{.*}} {layout_result_0 = #xegpu.layout<lane_layout = [2, 8], lane_data = [1, 1]>} |
| 35 | + // CHECK-SAME: : vector<12x8xf32> |
| 36 | + %addf = arith.addf %load_a, %load_b |
| 37 | + {layout_result_0 = #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>} |
| 38 | + : vector<24x32xf32> |
| 39 | + // CHECK: math.powf {{.*}}, {{.*}} {layout_result_0 = #xegpu.layout<lane_layout = [2, 8], lane_data = [1, 1]>} |
| 40 | + // CHECK-SAME: : vector<12x8xf32> |
| 41 | + %powf = math.powf %load_a, %load_b |
| 42 | + {layout_result_0 = #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>} |
| 43 | + : vector<24x32xf32> |
| 44 | + gpu.return |
| 45 | + } |
| 46 | + |
| 47 | + // CHECK-LABEL: ternary_ops |
| 48 | + gpu.func @ternary_ops(%a: memref<24x32xf32>, %b: memref<24x32xf32>, %c: memref<24x32xi1>) { |
| 49 | + %tdesc_a = xegpu.create_nd_tdesc %a[0, 0] : memref<24x32xf32> |
| 50 | + -> !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 51 | + %tdesc_b = xegpu.create_nd_tdesc %b[0, 0] : memref<24x32xf32> |
| 52 | + -> !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 53 | + %tdesc_c = xegpu.create_nd_tdesc %c[0, 0] : memref<24x32xi1> |
| 54 | + -> !xegpu.tensor_desc<24x32xi1, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 55 | + %load_a = xegpu.load_nd %tdesc_a |
| 56 | + : !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 57 | + -> vector<24x32xf32> |
| 58 | + %load_b = xegpu.load_nd %tdesc_b |
| 59 | + : !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 60 | + -> vector<24x32xf32> |
| 61 | + %load_c = xegpu.load_nd %tdesc_c |
| 62 | + : !xegpu.tensor_desc<24x32xi1, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 63 | + -> vector<24x32xi1> |
| 64 | + // CHECK: arith.select {{.*}}, {{.*}}, {{.*}} {layout_result_0 = #xegpu.layout<lane_layout = [2, 8], lane_data = [1, 1]>} |
| 65 | + // CHECK-SAME: : vector<12x8xi1>, vector<12x8xf32> |
| 66 | + %select = arith.select %load_c, %load_a, %load_b |
| 67 | + {layout_result_0 = #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>} |
| 68 | + : vector<24x32xi1>, vector<24x32xf32> |
| 69 | + // CHECK: math.fma {{.*}}, {{.*}}, {{.*}} {layout_result_0 = #xegpu.layout<lane_layout = [2, 8], lane_data = [1, 1]>} |
| 70 | + // CHECK-SAME: : vector<12x8xf32> |
| 71 | + %fma = math.fma %load_a, %load_b, %load_a |
| 72 | + {layout_result_0 = #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>} |
| 73 | + : vector<24x32xf32> |
| 74 | + gpu.return |
| 75 | + } |
| 76 | + |
| 77 | + // CHECK-LABEL: type_conversion_ops |
| 78 | + gpu.func @type_conversion_ops(%a: memref<24x32xf32>, %b: memref<24x32xi32>) { |
| 79 | + %tdesc_a = xegpu.create_nd_tdesc %a[0, 0] : memref<24x32xf32> |
| 80 | + -> !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 81 | + %tdesc_b = xegpu.create_nd_tdesc %b[0, 0] : memref<24x32xi32> |
| 82 | + -> !xegpu.tensor_desc<24x32xi32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 83 | + %load_a = xegpu.load_nd %tdesc_a |
| 84 | + : !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 85 | + -> vector<24x32xf32> |
| 86 | + %load_b = xegpu.load_nd %tdesc_b |
| 87 | + : !xegpu.tensor_desc<24x32xi32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 88 | + -> vector<24x32xi32> |
| 89 | + // CHECK: arith.truncf {{.*}} {layout_result_0 = #xegpu.layout<lane_layout = [2, 8], lane_data = [1, 1]>} |
| 90 | + // CHECK-SAME: : vector<12x8xf32> to vector<12x8xf16> |
| 91 | + %truncf = arith.truncf %load_a |
| 92 | + {layout_result_0 = #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>} |
| 93 | + : vector<24x32xf32> to vector<24x32xf16> |
| 94 | + // CHECK: arith.bitcast {{.*}} {layout_result_0 = #xegpu.layout<lane_layout = [2, 8], lane_data = [1, 1]>} |
| 95 | + // CHECK-SAME: : vector<12x8xi32> to vector<12x8xf32> |
| 96 | + %bitcast = arith.bitcast %load_b |
| 97 | + {layout_result_0 = #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>} |
| 98 | + : vector<24x32xi32> to vector<24x32xf32> |
| 99 | + gpu.return |
| 100 | + } |
| 101 | + |
| 102 | + // CHECK-LABEL: comparison_ops |
| 103 | + gpu.func @comparison_ops(%a: memref<24x32xf32>, %b: memref<24x32xf32>, %c: memref<24x32xi32>, %d: memref<24x32xi32>) { |
| 104 | + %tdesc_a = xegpu.create_nd_tdesc %a[0, 0] : memref<24x32xf32> |
| 105 | + -> !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 106 | + %tdesc_b = xegpu.create_nd_tdesc %b[0, 0] : memref<24x32xf32> |
| 107 | + -> !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 108 | + %tdesc_c = xegpu.create_nd_tdesc %c[0, 0] : memref<24x32xi32> |
| 109 | + -> !xegpu.tensor_desc<24x32xi32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 110 | + %tdesc_d = xegpu.create_nd_tdesc %d[0, 0] : memref<24x32xi32> |
| 111 | + -> !xegpu.tensor_desc<24x32xi32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 112 | + %load_a = xegpu.load_nd %tdesc_a |
| 113 | + : !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 114 | + -> vector<24x32xf32> |
| 115 | + %load_b = xegpu.load_nd %tdesc_b |
| 116 | + : !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 117 | + -> vector<24x32xf32> |
| 118 | + %load_c = xegpu.load_nd %tdesc_c |
| 119 | + : !xegpu.tensor_desc<24x32xi32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 120 | + -> vector<24x32xi32> |
| 121 | + %load_d = xegpu.load_nd %tdesc_d |
| 122 | + : !xegpu.tensor_desc<24x32xi32, #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>> |
| 123 | + -> vector<24x32xi32> |
| 124 | + // CHECK: arith.cmpf ult, {{.*}}, {{.*}} {layout_result_0 = #xegpu.layout<lane_layout = [2, 8], lane_data = [1, 1]>} |
| 125 | + // CHECK-SAME: : vector<12x8xf32> |
| 126 | + %cmpf = arith.cmpf ult, %load_a, %load_b |
| 127 | + {layout_result_0 = #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>} |
| 128 | + : vector<24x32xf32> |
| 129 | + // CHECK: arith.cmpi eq, {{.*}}, {{.*}} {layout_result_0 = #xegpu.layout<lane_layout = [2, 8], lane_data = [1, 1]>} |
| 130 | + // CHECK-SAME: : vector<12x8xi32> |
| 131 | + %cmpi = arith.cmpi eq, %load_c, %load_d |
| 132 | + {layout_result_0 = #xegpu.layout<sg_layout = [2, 4], sg_data = [12, 8], lane_layout = [2, 8], lane_data = [1, 1]>} |
| 133 | + : vector<24x32xi32> |
| 134 | + gpu.return |
| 135 | + } |
| 136 | + |
| 137 | + // 1 to N decomposition of elementwise operations |
| 138 | + // CHECK-LABEL: elementwise_ops_rr_assignment |
| 139 | + gpu.func @elementwise_ops_rr_assignment(%a: memref<24x32xf32>, %b: memref<24x32xf32>) { |
| 140 | + %tdesc_a = xegpu.create_nd_tdesc %a[0, 0] : memref<24x32xf32> |
| 141 | + -> !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [4, 4], sg_data = [2, 2], lane_layout = [2, 2], lane_data = [1, 1]>> |
| 142 | + %tdesc_b = xegpu.create_nd_tdesc %b[0, 0] : memref<24x32xf32> |
| 143 | + -> !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [4, 4], sg_data = [2, 2], lane_layout = [2, 2], lane_data = [1, 1]>> |
| 144 | + %load_a = xegpu.load_nd %tdesc_a |
| 145 | + : !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [4, 4], sg_data = [2, 2], lane_layout = [2, 2], lane_data = [1, 1]>> |
| 146 | + -> vector<24x32xf32> |
| 147 | + %load_b = xegpu.load_nd %tdesc_b |
| 148 | + : !xegpu.tensor_desc<24x32xf32, #xegpu.layout<sg_layout = [4, 4], sg_data = [2, 2], lane_layout = [2, 2], lane_data = [1, 1]>> |
| 149 | + -> vector<24x32xf32> |
| 150 | + // CHECK-COUNT-12: arith.negf {{.*}} {layout_result_0 = #xegpu.layout<lane_layout = [2, 2], lane_data = [1, 1]>} |
| 151 | + // CHECK-SAME-COUNT-12: : vector<2x2xf32> |
| 152 | + // CHECK-NOT: arith.negf |
| 153 | + %negf = arith.negf %load_a |
| 154 | + {layout_result_0 = #xegpu.layout<sg_layout = [4, 4], sg_data = [2, 2], lane_layout = [2, 2], lane_data = [1, 1]>} |
| 155 | + : vector<24x32xf32> |
| 156 | + // CHECK-COUNT-12: math.powf {{.*}}, {{.*}} {layout_result_0 = #xegpu.layout<lane_layout = [2, 2], lane_data = [1, 1]>} |
| 157 | + // CHECK-SAME-COUNT-12: : vector<2x2xf32> |
| 158 | + // CHECK-NOT: math.powf |
| 159 | + %powf = math.powf %load_a, %load_b |
| 160 | + {layout_result_0 = #xegpu.layout<sg_layout = [4, 4], sg_data = [2, 2], lane_layout = [2, 2], lane_data = [1, 1]>} |
| 161 | + : vector<24x32xf32> |
| 162 | + gpu.return |
| 163 | + } |
| 164 | +} |
0 commit comments