1616 match_and_split ,
1717 PipelineInterrupt ,
1818)
19- from lighthouse .schedule .xegpu .helper import bundle_xegpu_to_binary
2019
20+ from lighthouse .schedule import schedule_boilerplate
2121from lighthouse .dialects import smt_ext
2222from lighthouse .dialects .transform import smt_ext as td_smt_ext
2323from lighthouse .dialects .transform .tune_ext import knob , KnobValue
@@ -104,66 +104,39 @@ def params_with_constraints_imposed(
104104 }
105105
106106
107- def get_schedule_module (
107+ def mlp_schedule (
108108 params : list [dict [str , int | None ]],
109109 stop_at_stage : str = "" ,
110110) -> ir .Module :
111- """Generate transform schedule module."""
111+ """Generate transform schedule module for MLP payload ."""
112112 assert params is not None and len (params ) > 0 , "params must be provided."
113- mod = ir .Module .create ()
114- mod .operation .attributes ["transform.with_named_sequence" ] = ir .UnitAttr .get ()
115- with ir .InsertionPoint (mod .body ):
116- named_sequence = transform .named_sequence (
117- "__transform_main" ,
118- [transform .AnyOpType .get ()], # input types
119- [], # output types
120- arg_attrs = [{"transform.readonly" : ir .UnitAttr .get ()}],
113+ with schedule_boilerplate () as (schedule , named_seq ):
114+ # match the payload module
115+ anytype = transform .AnyOpType .get ()
116+ func = match (named_seq .bodyTarget , ops = {"func.func" })
117+ payload_mod = transform .get_parent_op (
118+ anytype ,
119+ func ,
120+ op_name = "builtin.module" ,
121+ deduplicate = True ,
121122 )
122- with ir .InsertionPoint (named_sequence .body ):
123- # match the payload module
124- anytype = transform .AnyOpType .get ()
125- func = match (named_sequence .bodyTarget , ops = {"func.func" })
126- payload_mod = transform .get_parent_op (
127- anytype ,
128- func ,
129- op_name = "builtin.module" ,
130- deduplicate = True ,
123+ for i , layer_params in enumerate (params ):
124+ layer_params |= params_with_constraints_imposed (
125+ layer_params , knob_name_prefix = f"layer_{ i } _"
131126 )
132- for i , layer_params in enumerate (params ):
133- layer_params |= params_with_constraints_imposed (
134- layer_params , knob_name_prefix = f"layer_{ i } _"
135- )
136127
137- xegpu_mlp_transform_schedule (
128+ try :
129+ bundle_xegpu_mlp_schedule (
138130 payload_mod ,
139131 params = params ,
140132 stop_at_stage = stop_at_stage ,
141133 )
134+ except PipelineInterrupt :
135+ pass
136+ finally :
137+ transform .yield_ ()
142138
143- return mod
144-
145-
146- def xegpu_mlp_transform_schedule (
147- mod : ir .Value [transform .AnyOpType ],
148- params : list [dict [str , int | KnobValue ]],
149- stop_at_stage : str = "" ,
150- ):
151- """Transform schedule for MLP-like payload."""
152- try :
153- mod = bundle_xegpu_mlp_schedule (
154- mod ,
155- params = params ,
156- stop_at_stage = stop_at_stage ,
157- )
158-
159- mod = bundle_xegpu_to_binary (
160- mod ,
161- stop_at_stage = stop_at_stage ,
162- )
163- except PipelineInterrupt :
164- pass
165- finally :
166- transform .yield_ ()
139+ return schedule
167140
168141
169142def bundle_xegpu_mlp_schedule (
@@ -183,51 +156,49 @@ def bundle_xegpu_mlp_schedule(
183156
184157 # tile each layer separately
185158 for matmul_op , layer_params in zip (matmul_ops , params ):
159+ # tunable parameters: wg and k tiling
160+ wg_tile = [layer_params ["wg_m" ], layer_params ["wg_n" ]]
161+ k_tile = layer_params ["k_tile" ]
162+
186163 # find the last tileable consumer of the matmul
187164 consumers = transform_ext .get_tileable_consumers (matmul_op )
188165 leaf_consumer_op = transform_ext .extract_handle (consumers , - 1 )
189166
190- # tunable parameters: wg level tiling
191- wg_tile = [layer_params ["wg_m" ], layer_params ["wg_n" ]]
192- k_tile = layer_params ["k_tile" ]
193-
194- _ , wg_loop = structured .FuseOp (
195- leaf_consumer_op , tile_sizes = wg_tile , use_forall = True
196- ).results
197- transform .apply_cse (mod )
198- canonicalize (mod )
167+ # wg tiling
168+ _ , [wg_loop ], _ = lh_transform .tile (
169+ leaf_consumer_op ,
170+ tile_sizes = wg_tile ,
171+ fuse_producers = True ,
172+ use_forall = True ,
173+ apply_cleanup = False ,
174+ )
199175
200176 # k loop tiling
201177 wg_matmul = match (wg_loop , ops = {"linalg.matmul" })
202- wgk_matmul , k_loop = structured .TileUsingForOp (
203- wg_matmul , sizes = [0 , 0 , k_tile ]
204- ).results
178+ _ , [k_loop ], _ = lh_transform .tile (wg_matmul , tile_sizes = [0 , 0 , k_tile ])
205179
206180 func = transform .get_parent_op (
207181 anytype ,
208182 k_loop ,
209183 op_name = "func.func" ,
210184 deduplicate = True ,
211185 )
212- transform .apply_cse (func )
213- canonicalize (func )
186+ lh_transform .cleanup (func )
214187
215188 if stop_at_stage == "tiled" :
216189 raise PipelineInterrupt ()
217190
218191 # vectorize
219- # FIXME use structured.structured_vectorize_children_and_apply_patterns
220- func = structured . VectorizeChildrenAndApplyPatternsOp (
192+ func = structured .structured_vectorize_children_and_apply_patterns (
193+ transform . any_op_t (),
221194 func ,
222195 fold_type_extensions_into_contract = True ,
223- ). result
196+ )
224197
225198 # hoist loop invariant vector read/store ops
226199 k_loop = match (func , ops = {"scf.for" })
227- loop .HoistLoopInvariantSubsetsOp (k_loop )
228-
229- transform .apply_cse (func )
230- canonicalize (func )
200+ lh_transform .loop_hoisting (k_loop )
201+ lh_transform .cleanup (func )
231202
232203 if stop_at_stage == "vectorized" :
233204 raise PipelineInterrupt ()
0 commit comments