-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compute memory usage per location #538
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Part of the Concrete Compiler Project, under the BSD3 License with Zama | ||
// Exceptions. See | ||
// https://github.com/zama-ai/concrete-compiler-internal/blob/main/LICENSE.txt | ||
// for license information. | ||
|
||
#ifndef CONCRETELANG_DIALECT_CONCRETE_MEMORY_USAGE_H | ||
#define CONCRETELANG_DIALECT_CONCRETE_MEMORY_USAGE_H | ||
|
||
#include <mlir/IR/BuiltinOps.h> | ||
#include <mlir/IR/Operation.h> | ||
#include <mlir/Pass/Pass.h> | ||
|
||
#include <concretelang/Support/CompilationFeedback.h> | ||
|
||
namespace mlir { | ||
namespace concretelang { | ||
namespace Concrete { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This enter/exit pass could be factorized There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or even more the nested loop logic too |
||
|
||
struct MemoryUsagePass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following the common pass pattern, this should be hidden in cpp and expose uniquely a |
||
: public PassWrapper<MemoryUsagePass, OperationPass<ModuleOp>> { | ||
|
||
CompilationFeedback &feedback; | ||
|
||
MemoryUsagePass(CompilationFeedback &feedback) : feedback{feedback} {}; | ||
|
||
void runOnOperation() override { | ||
WalkResult walk = | ||
getOperation()->walk([&](Operation *op, const WalkStage &stage) { | ||
if (stage.isBeforeAllRegions()) { | ||
std::optional<StringError> error = this->enter(op); | ||
if (error.has_value()) { | ||
op->emitError() << error->mesg; | ||
return WalkResult::interrupt(); | ||
} | ||
} | ||
|
||
if (stage.isAfterAllRegions()) { | ||
std::optional<StringError> error = this->exit(op); | ||
if (error.has_value()) { | ||
op->emitError() << error->mesg; | ||
return WalkResult::interrupt(); | ||
} | ||
} | ||
|
||
return WalkResult::advance(); | ||
}); | ||
|
||
if (walk.wasInterrupted()) { | ||
signalPassFailure(); | ||
} | ||
} | ||
|
||
std::optional<StringError> enter(Operation *op); | ||
|
||
std::optional<StringError> exit(Operation *op); | ||
|
||
std::map<std::string, std::vector<mlir::Value>> visitedValuesPerLoc; | ||
|
||
size_t iterations = 1; | ||
}; | ||
|
||
} // namespace Concrete | ||
} // namespace concretelang | ||
} // namespace mlir | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
add_mlir_library( | ||
ConcreteDialectAnalysis | ||
MemoryUsage.cpp | ||
ADDITIONAL_HEADER_DIRS | ||
${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/Concrete | ||
DEPENDS | ||
ConcreteDialect | ||
mlir-headers | ||
LINK_LIBS | ||
PUBLIC | ||
MLIRIR | ||
ConcreteDialect) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So here and same reflexion for statistics, why not follow the common pass pattern?