Skip to content

Commit

Permalink
Fix reductions with side outputs that are unrelated to any reduction.
Browse files Browse the repository at this point in the history
This is a bit of a strange case, but apparently it can happen.

PiperOrigin-RevId: 675154250
  • Loading branch information
jreiffers authored and Google-ML-Automation committed Sep 16, 2024
1 parent fb30e14 commit efab41b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions xla/service/gpu/fusions/mlir/elemental_hlo_to_mlir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,9 @@ ValueRange EmitLoopNestImpl(
};
scf::LoopNest loop_nest =
scf::buildLoopNest(b, b.getLoc(), lbs, ubs, steps, iter_args_inits, bb);
if (loop_nest.results.empty()) {
return {};
}
ValueRange result_range =
loop_nest.results.front().getDefiningOp()->getResults();
CHECK_EQ(result_range.size(), loop_nest.results.size())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: test_correctness %s
// RUN: fusion_to_mlir %s | FileCheck %s

region {
param_0 = f32[] parameter(0)
param_1 = f32[] parameter(1)
ROOT add = f32[] add(param_0, param_1)
}

fused_computation {
p0 = f32[512,1280] parameter(0)
constant = f32[] constant(0)
reduce = f32[1280] reduce(p0, constant), dimensions={0}, to_apply=region
p1 = f32[512,1280] parameter(1)
ROOT tuple = (f32[1280], f32[512,1280]) tuple(reduce, p1)
}

// The two outputs are completely unrelated, so they're put in separate groups.
// CHECK: scf.index_switch

0 comments on commit efab41b

Please sign in to comment.