Skip to content

Commit

Permalink
Delete DisposableElementsAttr for each batch with lock
Browse files Browse the repository at this point in the history
Signed-off-by: Haruki Imai <[email protected]>
  • Loading branch information
imaihal committed Oct 22, 2024
1 parent 31340b6 commit fd7c1ad
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Dialect/ONNX/ElementsAttr/DisposablePool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,26 @@ 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();
disposable.dispose();
// TODO: In that case should we lock mutex?
}

// Delete DisposableElementsAttr for each batch with lock after
// conversion.
auto deleteBatch = [&translationMutex, &batch]() {
const std::lock_guard<std::mutex> lock(translationMutex);
for (auto &[id, translation] : batch) {
auto &[disposable, dense] = translation;
disposable.dispose();
}
};
deleteBatch();
}
};
MLIRContext *ctx = moduleOp.getContext();
Expand Down

0 comments on commit fd7c1ad

Please sign in to comment.