Skip to content

Commit c386918

Browse files
committed
reduction schedule: fix number of threads
1 parent 2f4e098 commit c386918

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎lighthouse/schedule/xegpu/reduction_schedule.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ def bundle_xegpu_reduction_schedule(
119119
reduction_tile = layer_params["reduction_tile"]
120120
subgroup_size = layer_params["subgroup_size"]
121121

122+
assert sum(wg_tile) > 0, "wg_tile must have at least one non-zero value"
123+
assert sum(sg_tile) > 0, "sg_tile must have at least one non-zero value"
124+
assert sum(reduction_tile) > 0, (
125+
"reduction_tile must have at least one non-zero value"
126+
)
127+
122128
assert len(wg_tile) == len(sg_tile) == len(reduction_tile), (
123129
"wg_tile, sg_tile, and reduction_tile must have the same number of dimensions"
124130
)
@@ -292,9 +298,12 @@ def tile_and_fuse_reduction(reduction_op, tile_sizes):
292298
# set the number of threads for the gpu.launch operation
293299
launch_op = match_and_split(func, ops={"gpu.launch"})
294300
num_subgroups = 1
295-
for wg, sg in zip(wg_tile, sg_tile):
301+
_wg_tile = wg_subtile if apply_wg_subtile else wg_tile
302+
for i, (wg, red, sg) in enumerate(zip(_wg_tile, reduction_tile, sg_tile)):
296303
if wg > 0 and sg > 0:
297304
num_subgroups *= wg // sg
305+
if red > 0 and sg > 0:
306+
num_subgroups *= red // sg
298307
num_threads = num_subgroups * subgroup_size
299308
xegpu.set_gpu_launch_threads(launch_op[0], threads=[num_threads, 1, 1])
300309

@@ -320,7 +329,6 @@ def tile_and_fuse_reduction(reduction_op, tile_sizes):
320329
store_nd_ops = match(gpu_func, ops={"xegpu.store_nd"})
321330
store_matrix_ops = match(gpu_func, ops={"xegpu.store_matrix"})
322331
sg_layout = [1] * ndims
323-
_wg_tile = wg_subtile if apply_wg_subtile else wg_tile
324332
for i, (wg, red, sg) in enumerate(zip(_wg_tile, reduction_tile, sg_tile)):
325333
if red > 0 and sg > 0:
326334
sg_layout[i] = int(red // sg)

0 commit comments

Comments
 (0)