Skip to content

Commit

Permalink
Remove a spike of memory usage in ScrubDisposablePass. (#2978)
Browse files Browse the repository at this point in the history
ScrubDisposablePass consumed a lot of memory only for a moment.
This was because disposalElementsAttr was kept after converting to denseElementsAttr.
This PR removes the spike by deleting disposalElementsAttr just after each conversion.
---------

Signed-off-by: Haruki Imai <[email protected]>
  • Loading branch information
imaihal authored Oct 24, 2024
1 parent 012f33c commit 91a72e6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Dialect/ONNX/ElementsAttr/DisposablePool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,18 @@ void DisposablePool::scrub(ModuleOp moduleOp, OpAttrDictionary opsAttrs) {
return llvm::make_range(batchBegin, batchEnd);
};
// Parallel worker body: Fetch and process batches until there are no more.
auto work = [&fetchBatch](size_t threadNumber) {
auto work = [&fetchBatch, &translationMutex](size_t threadNumber) {
for (;;) {
auto batch = fetchBatch();
if (batch.empty())
break;
for (auto &[id, translation] : batch) {
auto &[disposable, dense] = translation;
dense = disposable.toDenseElementsAttr();
// TODO: Consider calling disposable.dispose() here to free up memory
// on the go to make memory available to create the next
// DenseElementsAttr. In that case should we lock mutex?
{
const std::lock_guard<std::mutex> lock(translationMutex);
disposable.dispose();
}
}
}
};
Expand Down

0 comments on commit 91a72e6

Please sign in to comment.