Skip to content

Commit c12cc55

Browse files
committed
address comments
1 parent b9b054b commit c12cc55

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎lighthouse/dialects/transform/transform_ext/utils/dependent_reduction_legality.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,11 +553,15 @@ def try_add_mapping(r1_dim: int, e_dim: int) -> bool:
553553
def _check_correction_body(
554554
e: ir.OpView, r1_input_indices: list[int], compute_type: ir.Type
555555
) -> None:
556-
"""Check if body of E's ops has valid data-operand stand-ins (safe values)."""
556+
"""Check E's constants and data-operand stand-ins before cloning its body."""
557557
body = e.regions[0].blocks[0]
558558
accumulator_args = {body.arguments[index] for index in r1_input_indices}
559559
for operation in list(body.operations)[:-1]:
560560
op = opview(operation)
561+
if isinstance(op, arith.ConstantOp) and not isinstance(
562+
op.operation.attributes["value"], ir.FloatAttr
563+
):
564+
raise FusionRejected("E body has a non-floating arith.constant")
561565

562566
for operand in op.operands:
563567
if isinstance(operand, ir.BlockArgument) and operand.owner == body:

‎test/transform/test_dependent_reduction_legality.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,28 @@ def main() -> None:
416416
# CHECK-NEXT: Legal to fuse: E dim 1, tile 32
417417
check_case("mixed precision", MIXED_SOFTMAX)
418418

419+
# CHECK-LABEL: Case: unused integer constant
420+
# CHECK-NEXT: Not legal to fuse: E body has a non-floating arith.constant
421+
check_case(
422+
"unused integer constant",
423+
softmax_with_term(
424+
" %unused = arith.constant 7 : i32\n"
425+
" %e = math.exp %d : f32\n"
426+
" linalg.yield %e : f32"
427+
),
428+
)
429+
430+
# CHECK-LABEL: Case: unused index constant
431+
# CHECK-NEXT: Not legal to fuse: E body has a non-floating arith.constant
432+
check_case(
433+
"unused index constant",
434+
softmax_with_term(
435+
" %unused = arith.constant 7 : index\n"
436+
" %e = math.exp %d : f32\n"
437+
" linalg.yield %e : f32"
438+
),
439+
)
440+
419441
# CHECK-LABEL: Case: nonseparable term
420442
# CHECK-NEXT: Not legal to fuse: E is not multiplicatively separable
421443
check_case(

0 commit comments

Comments
 (0)