• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: mlir-opt -test-gpu-rewrite %s | FileCheck %s
2
3// NOTE: Assertions have been autogenerated by utils/generate-test-checks.py
4// CHECK: gpu.module @kernels {
5gpu.module @kernels {
6
7  // CHECK-LABEL: gpu.func @kernel(
8  // CHECK-SAME: [[VAL_0:%.*]]: f32) workgroup([[VAL_1:%.*]] : memref<32xf32, 3>) kernel {
9  gpu.func @kernel(%arg0 : f32) kernel {
10    // CHECK:   [[VAL_2:%.*]] = constant 31 : i32
11    // CHECK:   [[VAL_3:%.*]] = constant 0 : i32
12    // CHECK:   [[VAL_4:%.*]] = constant 0 : index
13    // CHECK:   [[VAL_5:%.*]] = constant 32 : i32
14    // CHECK:   [[VAL_6:%.*]] = constant 1 : i32
15    // CHECK:   [[VAL_7:%.*]] = constant 2 : i32
16    // CHECK:   [[VAL_8:%.*]] = constant 4 : i32
17    // CHECK:   [[VAL_9:%.*]] = constant 8 : i32
18    // CHECK:   [[VAL_10:%.*]] = constant 16 : i32
19    // CHECK:   [[VAL_11:%.*]] = "gpu.block_dim"() {dimension = "x"} : () -> index
20    // CHECK:   [[VAL_12:%.*]] = index_cast [[VAL_11]] : index to i32
21    // CHECK:   [[VAL_13:%.*]] = "gpu.block_dim"() {dimension = "y"} : () -> index
22    // CHECK:   [[VAL_14:%.*]] = index_cast [[VAL_13]] : index to i32
23    // CHECK:   [[VAL_15:%.*]] = "gpu.block_dim"() {dimension = "z"} : () -> index
24    // CHECK:   [[VAL_16:%.*]] = index_cast [[VAL_15]] : index to i32
25    // CHECK:   [[VAL_17:%.*]] = "gpu.thread_id"() {dimension = "x"} : () -> index
26    // CHECK:   [[VAL_18:%.*]] = index_cast [[VAL_17]] : index to i32
27    // CHECK:   [[VAL_19:%.*]] = "gpu.thread_id"() {dimension = "y"} : () -> index
28    // CHECK:   [[VAL_20:%.*]] = index_cast [[VAL_19]] : index to i32
29    // CHECK:   [[VAL_21:%.*]] = "gpu.thread_id"() {dimension = "z"} : () -> index
30    // CHECK:   [[VAL_22:%.*]] = index_cast [[VAL_21]] : index to i32
31    // CHECK:   [[VAL_23:%.*]] = muli [[VAL_22]], [[VAL_14]] : i32
32    // CHECK:   [[VAL_24:%.*]] = addi [[VAL_23]], [[VAL_20]] : i32
33    // CHECK:   [[VAL_25:%.*]] = muli [[VAL_24]], [[VAL_12]] : i32
34    // CHECK:   [[VAL_26:%.*]] = muli [[VAL_12]], [[VAL_14]] : i32
35    // CHECK:   [[VAL_27:%.*]] = addi [[VAL_25]], [[VAL_18]] : i32
36    // CHECK:   [[VAL_28:%.*]] = muli [[VAL_26]], [[VAL_16]] : i32
37    // CHECK:   [[VAL_29:%.*]] = and [[VAL_27]], [[VAL_2]] : i32
38    // CHECK:   [[VAL_30:%.*]] = cmpi "eq", [[VAL_29]], [[VAL_3]] : i32
39    // CHECK:   [[VAL_31:%.*]] = subi [[VAL_27]], [[VAL_29]] : i32
40    // CHECK:   [[VAL_32:%.*]] = subi [[VAL_28]], [[VAL_31]] : i32
41    // CHECK:   [[VAL_33:%.*]] = cmpi "slt", [[VAL_32]], [[VAL_5]] : i32
42    // CHECK:   cond_br [[VAL_33]], ^bb1, ^bb17
43    // CHECK: ^bb1:
44    // CHECK:   [[VAL_34:%.*]], [[VAL_35:%.*]] = gpu.shuffle [[VAL_0]], [[VAL_6]], [[VAL_32]] xor : f32
45    // CHECK:   cond_br [[VAL_35]], ^bb2, ^bb3
46    // CHECK: ^bb2:
47    // CHECK:   [[VAL_36:%.*]] = cmpf "ugt", [[VAL_0]], [[VAL_34]] : f32
48    // CHECK:   [[VAL_37:%.*]] = select [[VAL_36]], [[VAL_0]], [[VAL_34]] : f32
49    // CHECK:   br ^bb4([[VAL_37]] : f32)
50    // CHECK: ^bb3:
51    // CHECK:   br ^bb4([[VAL_0]] : f32)
52    // CHECK: ^bb4([[VAL_38:%.*]]: f32):
53    // CHECK:   [[VAL_39:%.*]], [[VAL_40:%.*]] = gpu.shuffle [[VAL_38]], [[VAL_7]], [[VAL_32]] xor : f32
54    // CHECK:   cond_br [[VAL_40]], ^bb5, ^bb6
55    // CHECK: ^bb5:
56    // CHECK:   [[VAL_41:%.*]] = cmpf "ugt", [[VAL_38]], [[VAL_39]] : f32
57    // CHECK:   [[VAL_42:%.*]] = select [[VAL_41]], [[VAL_38]], [[VAL_39]] : f32
58    // CHECK:   br ^bb7([[VAL_42]] : f32)
59    // CHECK: ^bb6:
60    // CHECK:   br ^bb7([[VAL_38]] : f32)
61    // CHECK: ^bb7([[VAL_43:%.*]]: f32):
62    // CHECK:   [[VAL_44:%.*]], [[VAL_45:%.*]] = gpu.shuffle [[VAL_43]], [[VAL_8]], [[VAL_32]] xor : f32
63    // CHECK:   cond_br [[VAL_45]], ^bb8, ^bb9
64    // CHECK: ^bb8:
65    // CHECK:   [[VAL_46:%.*]] = cmpf "ugt", [[VAL_43]], [[VAL_44]] : f32
66    // CHECK:   [[VAL_47:%.*]] = select [[VAL_46]], [[VAL_43]], [[VAL_44]] : f32
67    // CHECK:   br ^bb10([[VAL_47]] : f32)
68    // CHECK: ^bb9:
69    // CHECK:   br ^bb10([[VAL_43]] : f32)
70    // CHECK: ^bb10([[VAL_48:%.*]]: f32):
71    // CHECK:   [[VAL_49:%.*]], [[VAL_50:%.*]] = gpu.shuffle [[VAL_48]], [[VAL_9]], [[VAL_32]] xor : f32
72    // CHECK:   cond_br [[VAL_50]], ^bb11, ^bb12
73    // CHECK: ^bb11:
74    // CHECK:   [[VAL_51:%.*]] = cmpf "ugt", [[VAL_48]], [[VAL_49]] : f32
75    // CHECK:   [[VAL_52:%.*]] = select [[VAL_51]], [[VAL_48]], [[VAL_49]] : f32
76    // CHECK:   br ^bb13([[VAL_52]] : f32)
77    // CHECK: ^bb12:
78    // CHECK:   br ^bb13([[VAL_48]] : f32)
79    // CHECK: ^bb13([[VAL_53:%.*]]: f32):
80    // CHECK:   [[VAL_54:%.*]], [[VAL_55:%.*]] = gpu.shuffle [[VAL_53]], [[VAL_10]], [[VAL_32]] xor : f32
81    // CHECK:   cond_br [[VAL_55]], ^bb14, ^bb15
82    // CHECK: ^bb14:
83    // CHECK:   [[VAL_56:%.*]] = cmpf "ugt", [[VAL_53]], [[VAL_54]] : f32
84    // CHECK:   [[VAL_57:%.*]] = select [[VAL_56]], [[VAL_53]], [[VAL_54]] : f32
85    // CHECK:   br ^bb16([[VAL_57]] : f32)
86    // CHECK: ^bb15:
87    // CHECK:   br ^bb16([[VAL_53]] : f32)
88    // CHECK: ^bb16([[VAL_58:%.*]]: f32):
89    // CHECK:   br ^bb18([[VAL_58]] : f32)
90    // CHECK: ^bb17:
91    // CHECK:   [[VAL_59:%.*]], [[VAL_60:%.*]] = gpu.shuffle [[VAL_0]], [[VAL_6]], [[VAL_5]] xor : f32
92    // CHECK:   [[VAL_61:%.*]] = cmpf "ugt", [[VAL_0]], [[VAL_59]] : f32
93    // CHECK:   [[VAL_62:%.*]] = select [[VAL_61]], [[VAL_0]], [[VAL_59]] : f32
94    // CHECK:   [[VAL_63:%.*]], [[VAL_64:%.*]] = gpu.shuffle [[VAL_62]], [[VAL_7]], [[VAL_5]] xor : f32
95    // CHECK:   [[VAL_65:%.*]] = cmpf "ugt", [[VAL_62]], [[VAL_63]] : f32
96    // CHECK:   [[VAL_66:%.*]] = select [[VAL_65]], [[VAL_62]], [[VAL_63]] : f32
97    // CHECK:   [[VAL_67:%.*]], [[VAL_68:%.*]] = gpu.shuffle [[VAL_66]], [[VAL_8]], [[VAL_5]] xor : f32
98    // CHECK:   [[VAL_69:%.*]] = cmpf "ugt", [[VAL_66]], [[VAL_67]] : f32
99    // CHECK:   [[VAL_70:%.*]] = select [[VAL_69]], [[VAL_66]], [[VAL_67]] : f32
100    // CHECK:   [[VAL_71:%.*]], [[VAL_72:%.*]] = gpu.shuffle [[VAL_70]], [[VAL_9]], [[VAL_5]] xor : f32
101    // CHECK:   [[VAL_73:%.*]] = cmpf "ugt", [[VAL_70]], [[VAL_71]] : f32
102    // CHECK:   [[VAL_74:%.*]] = select [[VAL_73]], [[VAL_70]], [[VAL_71]] : f32
103    // CHECK:   [[VAL_75:%.*]], [[VAL_76:%.*]] = gpu.shuffle [[VAL_74]], [[VAL_10]], [[VAL_5]] xor : f32
104    // CHECK:   [[VAL_77:%.*]] = cmpf "ugt", [[VAL_74]], [[VAL_75]] : f32
105    // CHECK:   [[VAL_78:%.*]] = select [[VAL_77]], [[VAL_74]], [[VAL_75]] : f32
106    // CHECK:   br ^bb18([[VAL_78]] : f32)
107    // CHECK: ^bb18([[VAL_79:%.*]]: f32):
108    // CHECK:   cond_br [[VAL_30]], ^bb19, ^bb20
109    // CHECK: ^bb19:
110    // CHECK:   [[VAL_80:%.*]] = divi_signed [[VAL_27]], [[VAL_5]] : i32
111    // CHECK:   [[VAL_81:%.*]] = index_cast [[VAL_80]] : i32 to index
112    // CHECK:   store [[VAL_79]], [[VAL_1]]{{\[}}[[VAL_81]]] : memref<32xf32, 3>
113    // CHECK:   br ^bb21
114    // CHECK: ^bb20:
115    // CHECK:   br ^bb21
116    // CHECK: ^bb21:
117    // CHECK:   gpu.barrier
118    // CHECK:   [[VAL_82:%.*]] = addi [[VAL_28]], [[VAL_2]] : i32
119    // CHECK:   [[VAL_83:%.*]] = divi_signed [[VAL_82]], [[VAL_5]] : i32
120    // CHECK:   [[VAL_84:%.*]] = cmpi "slt", [[VAL_27]], [[VAL_83]] : i32
121    // CHECK:   cond_br [[VAL_84]], ^bb22, ^bb41
122    // CHECK: ^bb22:
123    // CHECK:   [[VAL_85:%.*]] = index_cast [[VAL_27]] : i32 to index
124    // CHECK:   [[VAL_86:%.*]] = load [[VAL_1]]{{\[}}[[VAL_85]]] : memref<32xf32, 3>
125    // CHECK:   [[VAL_87:%.*]] = cmpi "slt", [[VAL_83]], [[VAL_5]] : i32
126    // CHECK:   cond_br [[VAL_87]], ^bb23, ^bb39
127    // CHECK: ^bb23:
128    // CHECK:   [[VAL_88:%.*]], [[VAL_89:%.*]] = gpu.shuffle [[VAL_86]], [[VAL_6]], [[VAL_83]] xor : f32
129    // CHECK:   cond_br [[VAL_89]], ^bb24, ^bb25
130    // CHECK: ^bb24:
131    // CHECK:   [[VAL_90:%.*]] = cmpf "ugt", [[VAL_86]], [[VAL_88]] : f32
132    // CHECK:   [[VAL_91:%.*]] = select [[VAL_90]], [[VAL_86]], [[VAL_88]] : f32
133    // CHECK:   br ^bb26([[VAL_91]] : f32)
134    // CHECK: ^bb25:
135    // CHECK:   br ^bb26([[VAL_86]] : f32)
136    // CHECK: ^bb26([[VAL_92:%.*]]: f32):
137    // CHECK:   [[VAL_93:%.*]], [[VAL_94:%.*]] = gpu.shuffle [[VAL_92]], [[VAL_7]], [[VAL_83]] xor : f32
138    // CHECK:   cond_br [[VAL_94]], ^bb27, ^bb28
139    // CHECK: ^bb27:
140    // CHECK:   [[VAL_95:%.*]] = cmpf "ugt", [[VAL_92]], [[VAL_93]] : f32
141    // CHECK:   [[VAL_96:%.*]] = select [[VAL_95]], [[VAL_92]], [[VAL_93]] : f32
142    // CHECK:   br ^bb29([[VAL_96]] : f32)
143    // CHECK: ^bb28:
144    // CHECK:   br ^bb29([[VAL_92]] : f32)
145    // CHECK: ^bb29([[VAL_97:%.*]]: f32):
146    // CHECK:   [[VAL_98:%.*]], [[VAL_99:%.*]] = gpu.shuffle [[VAL_97]], [[VAL_8]], [[VAL_83]] xor : f32
147    // CHECK:   cond_br [[VAL_99]], ^bb30, ^bb31
148    // CHECK: ^bb30:
149    // CHECK:   [[VAL_100:%.*]] = cmpf "ugt", [[VAL_97]], [[VAL_98]] : f32
150    // CHECK:   [[VAL_101:%.*]] = select [[VAL_100]], [[VAL_97]], [[VAL_98]] : f32
151    // CHECK:   br ^bb32([[VAL_101]] : f32)
152    // CHECK: ^bb31:
153    // CHECK:   br ^bb32([[VAL_97]] : f32)
154    // CHECK: ^bb32([[VAL_102:%.*]]: f32):
155    // CHECK:   [[VAL_103:%.*]], [[VAL_104:%.*]] = gpu.shuffle [[VAL_102]], [[VAL_9]], [[VAL_83]] xor : f32
156    // CHECK:   cond_br [[VAL_104]], ^bb33, ^bb34
157    // CHECK: ^bb33:
158    // CHECK:   [[VAL_105:%.*]] = cmpf "ugt", [[VAL_102]], [[VAL_103]] : f32
159    // CHECK:   [[VAL_106:%.*]] = select [[VAL_105]], [[VAL_102]], [[VAL_103]] : f32
160    // CHECK:   br ^bb35([[VAL_106]] : f32)
161    // CHECK: ^bb34:
162    // CHECK:   br ^bb35([[VAL_102]] : f32)
163    // CHECK: ^bb35([[VAL_107:%.*]]: f32):
164    // CHECK:   [[VAL_108:%.*]], [[VAL_109:%.*]] = gpu.shuffle [[VAL_107]], [[VAL_10]], [[VAL_83]] xor : f32
165    // CHECK:   cond_br [[VAL_109]], ^bb36, ^bb37
166    // CHECK: ^bb36:
167    // CHECK:   [[VAL_110:%.*]] = cmpf "ugt", [[VAL_107]], [[VAL_108]] : f32
168    // CHECK:   [[VAL_111:%.*]] = select [[VAL_110]], [[VAL_107]], [[VAL_108]] : f32
169    // CHECK:   br ^bb38([[VAL_111]] : f32)
170    // CHECK: ^bb37:
171    // CHECK:   br ^bb38([[VAL_107]] : f32)
172    // CHECK: ^bb38([[VAL_112:%.*]]: f32):
173    // CHECK:   br ^bb40([[VAL_112]] : f32)
174    // CHECK: ^bb39:
175    // CHECK:   [[VAL_113:%.*]], [[VAL_114:%.*]] = gpu.shuffle [[VAL_86]], [[VAL_6]], [[VAL_5]] xor : f32
176    // CHECK:   [[VAL_115:%.*]] = cmpf "ugt", [[VAL_86]], [[VAL_113]] : f32
177    // CHECK:   [[VAL_116:%.*]] = select [[VAL_115]], [[VAL_86]], [[VAL_113]] : f32
178    // CHECK:   [[VAL_117:%.*]], [[VAL_118:%.*]] = gpu.shuffle [[VAL_116]], [[VAL_7]], [[VAL_5]] xor : f32
179    // CHECK:   [[VAL_119:%.*]] = cmpf "ugt", [[VAL_116]], [[VAL_117]] : f32
180    // CHECK:   [[VAL_120:%.*]] = select [[VAL_119]], [[VAL_116]], [[VAL_117]] : f32
181    // CHECK:   [[VAL_121:%.*]], [[VAL_122:%.*]] = gpu.shuffle [[VAL_120]], [[VAL_8]], [[VAL_5]] xor : f32
182    // CHECK:   [[VAL_123:%.*]] = cmpf "ugt", [[VAL_120]], [[VAL_121]] : f32
183    // CHECK:   [[VAL_124:%.*]] = select [[VAL_123]], [[VAL_120]], [[VAL_121]] : f32
184    // CHECK:   [[VAL_125:%.*]], [[VAL_126:%.*]] = gpu.shuffle [[VAL_124]], [[VAL_9]], [[VAL_5]] xor : f32
185    // CHECK:   [[VAL_127:%.*]] = cmpf "ugt", [[VAL_124]], [[VAL_125]] : f32
186    // CHECK:   [[VAL_128:%.*]] = select [[VAL_127]], [[VAL_124]], [[VAL_125]] : f32
187    // CHECK:   [[VAL_129:%.*]], [[VAL_130:%.*]] = gpu.shuffle [[VAL_128]], [[VAL_10]], [[VAL_5]] xor : f32
188    // CHECK:   [[VAL_131:%.*]] = cmpf "ugt", [[VAL_128]], [[VAL_129]] : f32
189    // CHECK:   [[VAL_132:%.*]] = select [[VAL_131]], [[VAL_128]], [[VAL_129]] : f32
190    // CHECK:   br ^bb40([[VAL_132]] : f32)
191    // CHECK: ^bb40([[VAL_133:%.*]]: f32):
192    // CHECK:   store [[VAL_133]], [[VAL_1]]{{\[}}[[VAL_4]]] : memref<32xf32, 3>
193    // CHECK:   br ^bb42
194    // CHECK: ^bb41:
195    // CHECK:   br ^bb42
196    // CHECK: ^bb42:
197    // CHECK:   gpu.barrier
198    %sum = "gpu.all_reduce"(%arg0) ({}) {op = "max"} : (f32) -> (f32)
199    gpu.return
200  }
201
202}
203