Skip to content

Commit ef56d04

Browse files
committed
address comments
1 parent 452faf7 commit ef56d04

2 files changed

Lines changed: 42 additions & 39 deletions

File tree

‎lighthouse/dialects/transform/transform_ext/ops/update_address_space.py‎

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,46 +32,50 @@ def apply(
3232
state: transform.TransformState,
3333
) -> DiagnosedSilenceableFailure:
3434
# Get the target operations to transform
35-
target_op = state.get_payload_ops(op.target)[0]
35+
target_ops = state.get_payload_ops(op.target)
3636
# Get the address space value from the attribute
3737
address_space_value = ir.IntegerAttr(op.address_space).value
3838
new_ops = []
39+
for target_op in target_ops:
40+
# Verify this is a memref.alloca operation
41+
if target_op.OPERATION_NAME != "memref.alloca":
42+
return DiagnosedSilenceableFailure.emit_silenceable_error(
43+
f"Expected memref.alloca operation, got {target_op.OPERATION_NAME}"
44+
)
3945

40-
# Verify this is a memref.alloca operation
41-
if target_op.OPERATION_NAME != "memref.alloca":
42-
return DiagnosedSilenceableFailure.emit_silenceable_error(
43-
f"Expected memref.alloca operation, got {target_op.OPERATION_NAME}"
46+
# Get the current result type (should be a MemRefType)
47+
old_result_type = target_op.results[0].type
48+
memref_type = ir.MemRefType(old_result_type)
49+
# Create a new memref type with the specified address space
50+
new_memref_type = ir.MemRefType.get(
51+
memref_type.shape,
52+
memref_type.element_type,
53+
layout=memref_type.layout,
54+
memory_space=ir.Attribute.parse(str(address_space_value)),
4455
)
4556

46-
# Get the current result type (should be a MemRefType)
47-
old_result_type = target_op.results[0].type
48-
memref_type = ir.MemRefType(old_result_type)
49-
# Create a new memref type with the specified address space
50-
new_memref_type = ir.MemRefType.get(
51-
memref_type.shape,
52-
memref_type.element_type,
53-
layout=memref_type.layout,
54-
memory_space=ir.Attribute.parse(f"{address_space_value}"),
55-
)
56-
57-
# Replace the operation with a new one that has the updated type
58-
with ir.InsertionPoint(target_op):
59-
# Get the operands from the original alloca (dynamic sizes and symbols)
60-
dynamic_sizes = list(
61-
target_op.operands[: target_op.attributes["operandSegmentSizes"][0]]
62-
)
63-
symbol_operands = list(
64-
target_op.operands[target_op.attributes["operandSegmentSizes"][0] :]
65-
)
66-
# Create a new alloca with the updated type
67-
new_alloca = memref.alloca(
68-
new_memref_type, dynamic_sizes, symbol_operands
69-
)
70-
# Replace all uses of the old operation with the new one
71-
# FIXME: This won't handle operations that consume the memref type and
72-
# return a new memref (such as subview).
73-
rewriter.replace_op(target_op, [new_alloca])
74-
new_ops.append(new_alloca.owner)
57+
# Replace the operation with a new one that has the updated type
58+
with ir.InsertionPoint(target_op):
59+
# Get the operands from the original alloca (dynamic sizes and symbols)
60+
dynamic_sizes = list(
61+
target_op.operands[
62+
: target_op.attributes["operandSegmentSizes"][0]
63+
]
64+
)
65+
symbol_operands = list(
66+
target_op.operands[
67+
target_op.attributes["operandSegmentSizes"][0] :
68+
]
69+
)
70+
# Create a new alloca with the updated type
71+
new_alloca = memref.alloca(
72+
new_memref_type, dynamic_sizes, symbol_operands
73+
)
74+
# Replace all uses of the old operation with the new one
75+
# FIXME: This won't handle operations that consume the memref type and
76+
# return a new memref (such as subview).
77+
rewriter.replace_op(target_op, [new_alloca])
78+
new_ops.append(new_alloca.owner)
7579

7680
# Set the results to the new operations
7781
results.set_ops(op.updated_op, new_ops)

‎lighthouse/schedule/xegpu/softmax_schedule.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def bundle_xegpu_softmax_schedule(
122122

123123
reduction_step_size = parameters["reduction_step_size"]
124124

125-
# Tile the division op and fuse the sub+exp producer into it
125+
# Tile the division op first.
126126
_, div_loop = structured.TileUsingForOp(
127127
div_op, sizes=[0, reduction_step_size]
128128
).results
@@ -135,7 +135,7 @@ def bundle_xegpu_softmax_schedule(
135135
containing_op=div_loop,
136136
)
137137

138-
# Tile the sum reduction and fuse the sub+exp producer into it
138+
# Tile the sum reduction.
139139
_, _, _, sum_loop = structured.structured_tile_reduction_using_for(
140140
[anytype],
141141
anytype,
@@ -262,9 +262,8 @@ def bundle_xegpu_softmax_schedule(
262262
gpu_mod_ops = match_and_split(mod, ops={"gpu.module"})
263263
for gpu_mod in gpu_mod_ops:
264264
gpu_func = match(gpu_mod, ops={"gpu.func"})
265-
allocas = match_and_split(gpu_func, ops={"memref.alloca"})
266-
for alloca in allocas:
267-
transform_ext.update_address_space(alloca, address_space=3)
265+
allocas = match(gpu_func, ops={"memref.alloca"})
266+
transform_ext.update_address_space(allocas, address_space=3)
268267
gpu_func = apply_registered_pass(gpu_func, "convert-vector-to-xegpu")
269268
transform.apply_cse(gpu_func)
270269

0 commit comments

Comments
 (0)