Skip to content

Commit 9d693cb

Browse files
authored
[Codegen][Tuner] improve verifier for the default attribute (#20173)
This PR enhances the verification of the default attribute `iree_codegen.tuning_spec_with_default_entrypoint`. - The `__kernel_config `named sequence operation must include the `iree_codegen.tuning_spec_entrypoint` attribute, on which the verification will be performed. - The `__kernel_config` named sequence operation must contain only a single `foreach_match` operation. --------- Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
1 parent 00e8873 commit 9d693cb

File tree

7 files changed

+410
-31
lines changed

7 files changed

+410
-31
lines changed

compiler/plugins/target/ROCM/test/default_tuning_specs_amdgpu.mlir

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@
3535
// Check that both the user tuning spec and the default spec get linked and
3636
// materialized. The user spec should have precedence over the default one.
3737

38+
// TODO: Re-add the check for iree_codegen.tuning_spec_with_default_entrypoint
39+
// once new linking is added and the output IR can pass verification for the default attribute.
40+
3841
// BOTH-LABEL: module @iree_linked_tuning_spec
39-
// BOTH-SAME: iree_codegen.tuning_spec_with_default_entrypoint
4042
// BOTH-SAME: transform.with_named_sequence
4143
// BOTH-LABEL: module @mmt_tile_and_fuse_spec_0 attributes {transform.with_named_sequence}
4244
// BOTH-LABEL: transform.named_sequence @main

compiler/src/iree/compiler/Codegen/Common/LinkTuningSpecsPass.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ emitLinkedTuningSpec(ModuleOp module, ArrayRef<NamedSequenceOp> specsToLink) {
8383
0, hasConsumedSequences ? kArgConsumedAttrName : kArgReadOnlyAttrName,
8484
builder.getUnitAttr());
8585
newSpec->setAttr(kTuningSpecEntrypointAttrName, builder.getUnitAttr());
86-
module->setAttr(kTuningSpecDefaultEntrypointAttrName, builder.getUnitAttr());
86+
// TODO: Re-enable default attribute as below once new linking lands.
87+
// module->setAttr(kTuningSpecDefaultEntrypointAttrName,
88+
// builder.getUnitAttr());
8789

8890
Region &region = newSpec.getRegion();
8991
Block *body = builder.createBlock(&region, region.begin(),

compiler/src/iree/compiler/Codegen/Common/test/materialize_tuning_specs.mlir

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
// Check that the final tuning spec is as expected when the user tuning spec is provided.
1212

13+
// TODO: Add the check for default attribute (`iree_codegen.tuning_spec_with_default_entrypoint`) here
14+
// once the merging logic supports cases beyond a single `foreach_match` operation.
15+
1316
// CHECK-LABEL: module @iree_linked_tuning_spec
14-
// CHECK-SAME: iree_codegen.tuning_spec_with_default_entrypoint
1517
// CHECK-SAME: transform.with_named_sequence
1618
// CHECK-LABEL: module @user_spec_0 attributes {transform.with_named_sequence}
1719
// CHECK-LABEL: transform.named_sequence @hello
@@ -31,6 +33,7 @@
3133
// SKIPLINK-LABEL: module @user_spec
3234
// SKIPLINK-SAME: iree_codegen.tuning_spec_with_default_entrypoint
3335
// SKIPLINK-SAME: transform.with_named_sequence
36+
// SKIPLINK: transform.print {name = "Hello Tuning Spec"}
3437
// SKIPLINK-NOT: module @{{.+}}
3538
// SKIPLINK: module attributes
3639
// SKIPLINK-SAME: iree_codegen.tuning_spec_mlirbc = dense<{{.+}}> : vector<{{[0-9]+}}xi8>
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
// RUN: iree-opt %s
22

33
module @user_spec attributes { transform.with_named_sequence, iree_codegen.tuning_spec_with_default_entrypoint } {
4-
transform.named_sequence @__kernel_config(%arg0: !transform.any_op {transform.readonly}) -> !transform.any_op
5-
attributes { iree_codegen.tuning_spec_entrypoint } {
6-
transform.print {name = "Hello Tuning Spec", skip_regions}
7-
transform.yield %arg0 : !transform.any_op
4+
transform.named_sequence @match(%arg: !transform.any_op {transform.readonly}) -> (!transform.any_op) {
5+
transform.print {name = "Hello Tuning Spec"}
6+
transform.yield %arg : !transform.any_op
7+
}
8+
9+
transform.named_sequence @apply_op_config(%op: !transform.any_op {transform.readonly}) {
10+
transform.yield
11+
}
12+
13+
transform.named_sequence @__kernel_config(%arg0: !transform.any_op {transform.consumed})
14+
-> (!transform.any_op) attributes { iree_codegen.tuning_spec_entrypoint } {
15+
%res = transform.foreach_match in %arg0
16+
@match -> @apply_op_config
17+
: (!transform.any_op) -> (!transform.any_op)
18+
transform.yield %res : !transform.any_op
819
}
920
}

compiler/src/iree/compiler/Codegen/Common/test/verify_tuning_specs.mlir

+240-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module @foo_module attributes { transform.with_named_sequence } {
1818
// -----
1919

2020
module @foo_module attributes { transform.with_named_sequence } {
21-
// expected-error @+1{{Tuning spec entry point expected to have a single any_op argument}}
21+
// expected-error @+1{{Must take one 'any_op' (required by 'iree_codegen.tuning_spec_entrypoint')}}
2222
transform.named_sequence @foo(%arg0: !transform.any_op {transform.readonly}, %arg1: !transform.any_op {transform.readonly}) -> !transform.any_op
2323
attributes { iree_codegen.tuning_spec_entrypoint } {
2424
transform.yield %arg0 : !transform.any_op
@@ -28,15 +28,15 @@ module @foo_module attributes { transform.with_named_sequence } {
2828
// -----
2929

3030
module @foo_module attributes { transform.with_named_sequence } {
31-
// expected-error @+1{{Tuning spec entry point expected to have a single any_op argument}}
31+
// expected-error @+1{{Must take one 'any_op' (required by 'iree_codegen.tuning_spec_entrypoint')}}
3232
transform.named_sequence @foo(%arg0: i32) -> !transform.any_op
3333
attributes { iree_codegen.tuning_spec_entrypoint } {}
3434
}
3535

3636
// -----
3737

3838
module @foo_module attributes { transform.with_named_sequence } {
39-
// expected-error @+1{{Tuning spec entry point expected to return any_op}}
39+
// expected-error @+1{{Must return one 'any_op' (required by 'iree_codegen.tuning_spec_entrypoint')}}
4040
transform.named_sequence @foo(%arg0: !transform.any_op {transform.readonly}) -> i32
4141
attributes { iree_codegen.tuning_spec_entrypoint } {
4242
%0 = arith.constant 0 : i32
@@ -47,22 +47,256 @@ module @foo_module attributes { transform.with_named_sequence } {
4747
// -----
4848

4949
module @foo_module attributes { transform.with_named_sequence } {
50-
// expected-error @+1{{Tuning spec entry point expected to return any_op}}
50+
// expected-error @+1{{Must return one 'any_op' (required by 'iree_codegen.tuning_spec_entrypoint')}}
5151
transform.named_sequence @foo(%arg0: !transform.any_op {transform.readonly})
5252
attributes { iree_codegen.tuning_spec_entrypoint } {}
5353
}
5454

5555
// -----
5656

57-
// expected-error @+1{{The tuning specification must include a named sequence with the symbol name '__kernel_config'}}
57+
// expected-error @+1{{Missing named sequence '__kernel_config' (required by 'iree_codegen.tuning_spec_with_default_entrypoint')}}
5858
module @iree_default_tuning_spec attributes { iree_codegen.tuning_spec_with_default_entrypoint } {
5959
}
6060

6161
// -----
6262

63-
// expected-error @+1{{The tuning specification must include a named sequence with the symbol name '__kernel_config'}}
63+
// expected-error @+1{{Missing named sequence '__kernel_config' (required by 'iree_codegen.tuning_spec_with_default_entrypoint')}}
6464
module @iree_default_tuning_spec attributes { iree_codegen.tuning_spec_with_default_entrypoint } {
6565
func.func @__kernel_config(%arg0: i32) -> () {
6666
return
6767
}
6868
}
69+
70+
// -----
71+
72+
module @iree_default_tuning_spec attributes { iree_codegen.tuning_spec_with_default_entrypoint } {
73+
// expected-error @+1{{Missing attribute 'iree_codegen.tuning_spec_entrypoint' in named sequence '__kernel_config' (required by 'iree_codegen.tuning_spec_with_default_entrypoint')}}
74+
transform.named_sequence @__kernel_config(%arg0: !transform.any_op {transform.consumed})
75+
-> (!transform.any_op) {
76+
transform.yield %arg0 : !transform.any_op
77+
}
78+
}
79+
80+
// -----
81+
82+
module @iree_default_tuning_spec attributes { iree_codegen.tuning_spec_with_default_entrypoint } {
83+
transform.named_sequence @match(%arg: !transform.any_op) -> (!transform.any_op) {
84+
transform.yield %arg : !transform.any_op
85+
}
86+
87+
transform.named_sequence @apply_op_config(%op: !transform.any_op) {
88+
transform.yield
89+
}
90+
91+
// expected-error @+1{{'__kernel_config' must contain exactly one block (required by 'iree_codegen.tuning_spec_with_default_entrypoint')}}
92+
transform.named_sequence @__kernel_config(%arg0: !transform.any_op)
93+
-> (!transform.any_op) attributes { iree_codegen.tuning_spec_entrypoint }
94+
}
95+
96+
// -----
97+
98+
module @iree_default_tuning_spec attributes { iree_codegen.tuning_spec_with_default_entrypoint } {
99+
transform.named_sequence @match(%arg: !transform.any_op {transform.readonly}) -> (!transform.any_op) {
100+
transform.yield %arg : !transform.any_op
101+
}
102+
103+
transform.named_sequence @apply_op_config(%op: !transform.any_op {transform.readonly}) {
104+
transform.yield
105+
}
106+
107+
// expected-error @+1{{'__kernel_config' must contain exactly two operations (required by 'iree_codegen.tuning_spec_with_default_entrypoint')}}
108+
transform.named_sequence @__kernel_config(%arg0: !transform.any_op {transform.consumed})
109+
-> (!transform.any_op) attributes { iree_codegen.tuning_spec_entrypoint } {
110+
111+
%res_a = transform.foreach_match in %arg0
112+
@match -> @apply_op_config
113+
: (!transform.any_op) -> (!transform.any_op)
114+
%res_b = transform.foreach_match in %res_a
115+
@match -> @apply_op_config
116+
: (!transform.any_op) -> (!transform.any_op)
117+
transform.yield %res_b : !transform.any_op
118+
}
119+
}
120+
121+
// -----
122+
123+
// expected-error @+1{{Expected one named sequence with 'iree_codegen.tuning_spec_entrypoint', but found 2 (required by 'iree_codegen.tuning_spec_with_default_entrypoint')}}
124+
module @iree_default_tuning_spec attributes { iree_codegen.tuning_spec_with_default_entrypoint } {
125+
transform.named_sequence @__kernel_config(%arg0: !transform.any_op {transform.consumed})
126+
-> (!transform.any_op) attributes { iree_codegen.tuning_spec_entrypoint } {
127+
transform.yield %arg0 : !transform.any_op
128+
}
129+
130+
transform.named_sequence @main(%arg0: !transform.any_op {transform.readonly})
131+
-> !transform.any_op attributes { iree_codegen.tuning_spec_entrypoint } {
132+
transform.yield %arg0 : !transform.any_op
133+
}
134+
}
135+
136+
// -----
137+
138+
module @iree_default_tuning_spec attributes { iree_codegen.tuning_spec_with_default_entrypoint } {
139+
transform.named_sequence @match(%arg: !transform.any_op {transform.readonly}) -> (!transform.any_op) {
140+
transform.yield %arg : !transform.any_op
141+
}
142+
143+
transform.named_sequence @apply_op_config(%op: !transform.any_op {transform.readonly}) {
144+
transform.yield
145+
}
146+
147+
// expected-error @+1{{'__kernel_config' must start with 'ForeachMatchOp' (required by 'iree_codegen.tuning_spec_with_default_entrypoint')}}
148+
transform.named_sequence @__kernel_config(%arg0: !transform.any_op {transform.consumed})
149+
-> (!transform.any_op) attributes { iree_codegen.tuning_spec_entrypoint } {
150+
transform.print {name = "Hello"}
151+
transform.yield %arg0 : !transform.any_op
152+
}
153+
}
154+
155+
// -----
156+
157+
// expected-error @+1{{Expected one named sequence with 'iree_codegen.tuning_spec_entrypoint', but found 2 (required by 'iree_codegen.tuning_spec_with_default_entrypoint')}}
158+
module @iree_default_tuning_spec attributes { iree_codegen.tuning_spec_with_default_entrypoint } {
159+
transform.named_sequence @__kernel_config(%arg0: !transform.any_op {transform.consumed})
160+
-> (!transform.any_op) attributes { iree_codegen.tuning_spec_entrypoint } {
161+
transform.yield %arg0 : !transform.any_op
162+
}
163+
164+
module @extra_module attributes { iree_codegen.tuning_spec_entrypoint } {
165+
transform.yield
166+
}
167+
}
168+
169+
// -----
170+
171+
module @iree_default_tuning_spec attributes { transform.with_named_sequence, iree_codegen.tuning_spec_with_default_entrypoint } {
172+
transform.named_sequence @match(%arg: !transform.any_op {transform.readonly})
173+
-> (!transform.any_op, !transform.any_op) {
174+
transform.yield %arg, %arg : !transform.any_op, !transform.any_op
175+
}
176+
177+
transform.named_sequence @apply_op_config(%op1: !transform.any_op {transform.readonly}, %op2: !transform.any_op {transform.readonly})
178+
-> (!transform.any_op) {
179+
transform.yield %op1 : !transform.any_op
180+
}
181+
182+
transform.named_sequence @__kernel_config(%arg0: !transform.any_op {transform.consumed})
183+
-> (!transform.any_op) attributes { iree_codegen.tuning_spec_entrypoint } {
184+
// expected-error @+1 {{'ForeachMatchOp' must return exactly one 'any_op' result (required by 'iree_codegen.tuning_spec_with_default_entrypoint')}}
185+
%res1, %res2 = transform.foreach_match in %arg0
186+
@match -> @apply_op_config
187+
: (!transform.any_op) -> (!transform.any_op, !transform.any_op)
188+
189+
transform.yield %res1 : !transform.any_op
190+
}
191+
}
192+
193+
// -----
194+
195+
module @iree_default_tuning_spec attributes { transform.with_named_sequence, iree_codegen.tuning_spec_with_default_entrypoint } {
196+
transform.named_sequence @match(%arg: !transform.any_op) -> (!transform.any_op) {
197+
transform.yield %arg : !transform.any_op
198+
}
199+
200+
transform.named_sequence @apply_op_config(%op: !transform.any_op) {
201+
transform.yield
202+
}
203+
204+
transform.named_sequence @__kernel_config(%arg0: !transform.any_op)
205+
-> (f32) attributes { iree_codegen.tuning_spec_entrypoint } {
206+
// expected-error @+1 {{'ForeachMatchOp' must return exactly one 'any_op' result (required by 'iree_codegen.tuning_spec_with_default_entrypoint')}}
207+
%res = transform.foreach_match in %arg0
208+
@match -> @apply_op_config
209+
: (!transform.any_op) -> (f32)
210+
211+
transform.yield %res : f32
212+
}
213+
}
214+
215+
// -----
216+
217+
module @iree_default_tuning_spec attributes { iree_codegen.tuning_spec_with_default_entrypoint } {
218+
transform.named_sequence @match(%arg1: !transform.any_op {transform.readonly}, %arg2: !transform.any_op {transform.readonly})
219+
-> (!transform.any_op) {
220+
transform.yield %arg1 : !transform.any_op
221+
}
222+
223+
transform.named_sequence @apply_op_config(%op: !transform.any_op {transform.readonly}) {
224+
transform.yield
225+
}
226+
227+
transform.named_sequence @__kernel_config(%arg0: !transform.any_op {transform.consumed})
228+
-> (!transform.any_op) attributes { iree_codegen.tuning_spec_entrypoint } {
229+
// expected-error @+1 {{'ForeachMatchOp' must take exactly one 'any_op' argument (required by 'iree_codegen.tuning_spec_with_default_entrypoint')}}
230+
%res = transform.foreach_match in %arg0, %arg0
231+
@match -> @apply_op_config
232+
: (!transform.any_op, !transform.any_op) -> (!transform.any_op)
233+
234+
transform.yield %res : !transform.any_op
235+
}
236+
}
237+
238+
// -----
239+
240+
module @iree_default_tuning_spec attributes { iree_codegen.tuning_spec_with_default_entrypoint } {
241+
transform.named_sequence @match(%arg: index) -> (index) {
242+
transform.yield %arg : index
243+
}
244+
245+
transform.named_sequence @apply_op_config(%op: !transform.any_op) {
246+
transform.yield
247+
}
248+
249+
transform.named_sequence @__kernel_config(%arg0: index)
250+
-> (!transform.any_op) attributes { iree_codegen.tuning_spec_entrypoint } {
251+
// expected-error @+1 {{'ForeachMatchOp' must take exactly one 'any_op' argument (required by 'iree_codegen.tuning_spec_with_default_entrypoint')}}
252+
%res = transform.foreach_match in %arg0
253+
@match -> @apply_op_config
254+
: (index) -> (!transform.any_op)
255+
256+
transform.yield %res : !transform.any_op
257+
}
258+
}
259+
260+
// -----
261+
262+
module @iree_default_tuning_spec attributes { iree_codegen.tuning_spec_with_default_entrypoint } {
263+
transform.named_sequence @match(%arg: !transform.any_op) -> (!transform.any_op) {
264+
transform.yield %arg : !transform.any_op
265+
}
266+
267+
transform.named_sequence @apply_op_config(%op: !transform.any_op) {
268+
transform.yield
269+
}
270+
271+
transform.named_sequence @__kernel_config(%arg0: !transform.any_op)
272+
-> (!transform.any_op) attributes { iree_codegen.tuning_spec_entrypoint } {
273+
// expected-error @+1{{'ForeachMatchOp' must not have 'restrict_root' attribute (required by 'iree_codegen.tuning_spec_with_default_entrypoint')}}
274+
%res = transform.foreach_match restrict_root in %arg0
275+
@match -> @apply_op_config
276+
: (!transform.any_op) -> (!transform.any_op)
277+
278+
transform.yield %res : !transform.any_op
279+
}
280+
}
281+
282+
// -----
283+
284+
module @iree_default_tuning_spec attributes { iree_codegen.tuning_spec_with_default_entrypoint } {
285+
transform.named_sequence @match(%arg: !transform.any_op) -> (!transform.any_op) {
286+
transform.yield %arg : !transform.any_op
287+
}
288+
289+
transform.named_sequence @apply_op_config(%op: !transform.any_op) {
290+
transform.yield
291+
}
292+
293+
transform.named_sequence @__kernel_config(%arg0: !transform.any_op)
294+
-> (!transform.any_op) attributes { iree_codegen.tuning_spec_entrypoint } {
295+
// expected-error @+1{{'ForeachMatchOp' must not have 'flatten_results' attribute (required by 'iree_codegen.tuning_spec_with_default_entrypoint')}}
296+
%res = transform.foreach_match flatten_results in %arg0
297+
@match -> @apply_op_config
298+
: (!transform.any_op) -> (!transform.any_op)
299+
300+
transform.yield %res : !transform.any_op
301+
}
302+
}

0 commit comments

Comments
 (0)