Skip to content

Fix chunking non outermost dims and insert new generic for cross-chunk accumulation to avoid fp numerical mismatch - #149

Open
acgatea1 wants to merge 6 commits into
torch-spyre:mainfrom
acgatea1:fix_chunking_non_outermost_dims_and_fp_numerical_mismatch
Open

Fix chunking non outermost dims and insert new generic for cross-chunk accumulation to avoid fp numerical mismatch#149
acgatea1 wants to merge 6 commits into
torch-spyre:mainfrom
acgatea1:fix_chunking_non_outermost_dims_and_fp_numerical_mismatch

Conversation

@acgatea1

Copy link
Copy Markdown
Collaborator
  • [ReductionDimChunking] — Restrict chunking to the outermost reduction dim, skipping the inner reduction dim, to avoid incorrectly chunking dims that are handled separately by SplitReductionInnerOuterDim.

  • [ReductionLoopExposure] — When cross-chunk accumulation is needed (partial FIFO path), move seed initialization from a conditional scf.if before the loop to an unconditional tensor.empty. After the loop, emit a combine scf.if that on the first chunk passes the loop result through, and on subsequent chunks reads the previous partial from the FIFO and adds it via a parallel linalg.generic. The write_to_fifo guard (scf.if all-ivs-last) inside the loop is preserved unchanged.

  • [MapReductionPartials] — Handle the new combine scf.if pattern that appears as G2's input after ReductionLoopExposure. Lower it to a result-less scf.if (then-branch empty, else-branch memref read_from_fifo + buffer linalg.generic add into the G1 alloc), then wire the alloc directly as G2's ins. Add LIT test outer_inner_dim_with_partial.mlir covering the full outer+inner absmax-with-partial flow.

Passes internal tests

… reduction dim)

Signed-off-by: Alex Gatea <alexgatea@ibm.com>
…o add the accumulator with the partial FIFO value

Signed-off-by: Alex Gatea <alexgatea@ibm.com>
…-partial scf.if

Signed-off-by: Alex Gatea <alexgatea@ibm.com>
Signed-off-by: Alex Gatea <alexgatea@ibm.com>
Comment thread test/Transforms/ReductionDimChunking/outermost_dim_only.mlir Outdated
Comment thread test/Transforms/ReductionLoopExposure/muil_fifo_dest.mlir
…icit --num-chunks allows multi-dim

Signed-off-by: Alex Gatea <alexgatea@ibm.com>
@acgatea1
acgatea1 force-pushed the fix_chunking_non_outermost_dims_and_fp_numerical_mismatch branch from 9de0e3d to 46c1609 Compare September 10, 2026 19:51
@acgatea1
acgatea1 requested a review from msdataei September 10, 2026 19:52

@msdataei msdataei left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

// CHECK: scf.if %[[IS_FIRST:.*]] {
// CHECK-NEXT: } else {
// CHECK-NEXT: %[[RD1:.*]] = ktdf.read_from_fifo %[[PRIV1]]#1 : <"L1LU" -> "SFU", 64xf16> -> memref<1x64xf16>
// CHECK-NEXT: linalg.generic {indexing_maps = [#[[$MAP2]], #[[$MAP2]]], iterator_types = ["parallel", "parallel"]} ins(%[[RD1]] : memref<1x64xf16>) outs(%[[ALLOC]] : memref<1x64xf16, "SFU_REG">)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good that we are using the same allocation as above linalg.generic.

@msdataei

Copy link
Copy Markdown
Contributor

This PR addresses part of the problem explained in this issue #54. What the max chunk size in each case is a separate problem. FYI @lupalby

Signed-off-by: Alex Gatea <alexgatea@ibm.com>
Comment on lines +1012 to +1014
sum_val = arith::AddFOp::create(b, b_loc, in_val, out_val);
} else {
sum_val = arith::AddIOp::create(b, b_loc, in_val, out_val);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should derive the reduction op from the input to this pass (not assume sum).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also add a test with a non-sum reduction (eg. max)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants