Skip to content

Commit

Permalink
Make MSA more deterministic.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 629852083
  • Loading branch information
tensorflower-gardener authored and copybara-github committed May 1, 2024
1 parent 69f3233 commit 83f1074
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion xla/service/memory_space_assignment/algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3514,10 +3514,17 @@ void MsaAlgorithm::FinalizeAllocations(
}
}
}
// The colocation_map is a hash table using a pointer as a key. Process its
// values in some sorted order to get deterministic results.
std::vector<std::pair<const AliasedOffset*, std::vector<Allocation*>>>
sorted_colocations(colocation_map.begin(), colocation_map.end());
absl::c_sort(sorted_colocations, [](const auto& a, const auto& b) {
return a.first->offset < b.first->offset;
});
// The allocations that have the same AliasedOffset need to be colocated.
// Export these to repack_allocation_blocks_ so that we can repack them to
// reduce fragmentation.
for (auto& colocation : colocation_map) {
for (auto& colocation : sorted_colocations) {
std::vector<AllocationBlock*> colocations;
for (Allocation* colocated_allocation : colocation.second) {
repack_allocation_blocks_.push_back(MakeRepackAllocationBlock(
Expand Down

0 comments on commit 83f1074

Please sign in to comment.