Skip to content

Commit 83f1074

Browse files
Make MSA more deterministic.
PiperOrigin-RevId: 629852083
1 parent 69f3233 commit 83f1074

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

xla/service/memory_space_assignment/algorithm.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3514,10 +3514,17 @@ void MsaAlgorithm::FinalizeAllocations(
35143514
}
35153515
}
35163516
}
3517+
// The colocation_map is a hash table using a pointer as a key. Process its
3518+
// values in some sorted order to get deterministic results.
3519+
std::vector<std::pair<const AliasedOffset*, std::vector<Allocation*>>>
3520+
sorted_colocations(colocation_map.begin(), colocation_map.end());
3521+
absl::c_sort(sorted_colocations, [](const auto& a, const auto& b) {
3522+
return a.first->offset < b.first->offset;
3523+
});
35173524
// The allocations that have the same AliasedOffset need to be colocated.
35183525
// Export these to repack_allocation_blocks_ so that we can repack them to
35193526
// reduce fragmentation.
3520-
for (auto& colocation : colocation_map) {
3527+
for (auto& colocation : sorted_colocations) {
35213528
std::vector<AllocationBlock*> colocations;
35223529
for (Allocation* colocated_allocation : colocation.second) {
35233530
repack_allocation_blocks_.push_back(MakeRepackAllocationBlock(

0 commit comments

Comments
 (0)