Skip to content

Commit

Permalink
Merge branch 'main' into amyachev/sync8
Browse files Browse the repository at this point in the history
  • Loading branch information
whitneywhtsang committed Feb 5, 2025
2 parents 13b4e92 + 2eff7d8 commit 897d7f0
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -977,12 +977,17 @@ void LayoutRematerialization::rewriteSlice(SetVector<Value> &slice,
SetVector<Operation *> opsToRewrite;
// Keep track of yield operands that need to be duplicated.
DenseMap<Operation *, SmallVector<int>> yieldOperandsMap;
// Keep these around to remove them from the slice after our collection pass
// This ensures we don't duplicate them during an for rewrite or causing the
// for/yield to fall out of sync
SetVector<Value> valuesWithExistingRemat;
for (Value v : slice) {
auto layoutIt = layout.find(v);
assert(layoutIt != layout.end());
// If we already have a remat value for this value, use it.
if (Value remat = getRematValue(v, layoutIt->second)) {
mapping.map(v, remat);
valuesWithExistingRemat.insert(v);
continue;
}
if (v.getDefiningOp()) {
Expand All @@ -1006,6 +1011,7 @@ void LayoutRematerialization::rewriteSlice(SetVector<Value> &slice,
}
}
}
slice.set_subtract(valuesWithExistingRemat);
opsToRewrite = multiRootTopologicalSort(opsToRewrite);

// replaceAllUsesWith calls delayed until after initial rewrite.
Expand Down

0 comments on commit 897d7f0

Please sign in to comment.