Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
Signed-off-by: Haruki Imai <[email protected]>
  • Loading branch information
imaihal committed Oct 23, 2024
1 parent fd7c1ad commit 896e7e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/Dialect/ONNX/ElementsAttr/DisposablePool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,13 @@ void DisposablePool::scrub(ModuleOp moduleOp, OpAttrDictionary opsAttrs) {

// 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
10 changes: 9 additions & 1 deletion src/Dialect/ONNX/Transforms/ScrubDisposablePass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include "src/Dialect/ONNX/ONNXDialect.hpp"
#include "src/Dialect/ONNX/ONNXOps.hpp"

#include <sys/time.h>
// #include <time.h>

using namespace mlir;

namespace onnx_mlir {
Expand All @@ -30,13 +33,18 @@ struct ScrubDisposablePass
StringRef getArgument() const override { return "scrub-disposable"; }

void runOnOperation() final {
struct timeval start_t, end_t;
gettimeofday(&start_t, NULL);
ModuleOp moduleOp = getOperation();
DisposablePool *pool = getDisposablePool();
pool->scrub(
moduleOp, {{ONNXConstantOp::getOperationName(), "value"},
{ONNXConstantOfShapeOp::getOperationName(), "value"}});
if (closeAfter)
pool->close();
gettimeofday(&end_t, NULL);
double totalTime = (((end_t.tv_sec * 1000000.) + end_t.tv_usec) - ((start_t.tv_sec * 1000000) + start_t.tv_usec)) / 1000;
llvm::dbgs() << "ScrubDisposablePass " << totalTime << " msec\n";
}

DisposablePool *getDisposablePool() {
Expand All @@ -57,4 +65,4 @@ std::unique_ptr<mlir::Pass> createScrubDisposablePass(bool closeAfter) {
return std::make_unique<ScrubDisposablePass>(closeAfter);
}

} // namespace onnx_mlir
} // namespace onnx_mlir

0 comments on commit 896e7e0

Please sign in to comment.