-
Notifications
You must be signed in to change notification settings - Fork 322
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
Release MLIRContext and Module before executing opt command for memory reduction #3000
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Haruki Imai <[email protected]> Co-authored-by: Yasushi Negishi <[email protected]>
// Free memory before using LLVM `opt` command | ||
llvmModule.reset(); | ||
module.release(); | ||
context.~MLIRContext(); |
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.
Do you know what are freed/released with these statements? It looks not too much memory saved and not sure it is worth to make a change.
@@ -598,10 +604,12 @@ static int genJniJar(const mlir::OwningOpRef<ModuleOp> &module, | |||
} | |||
|
|||
// Return 0 on success, error code on failure | |||
static int compileModuleToObject(const mlir::OwningOpRef<ModuleOp> &module, | |||
std::string outputNameWithoutExt, std::string &objectNameWithExt) { | |||
static int compileModuleToObject(mlir::OwningOpRef<ModuleOp> &module, |
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.
Removing const
and freeing the object internally seems difficult to follow, at least by looking at the function name. Same for other signature changes in other functions.
Signed-off-by: Haruki Imai <[email protected]>
@@ -806,7 +819,7 @@ static int emitOutputFiles(std::string outputNameNoExt, | |||
case EmitLib: { | |||
std::string sharedLibNameWithExt; | |||
int rc = compileModuleToSharedLibrary( | |||
module, outputNameNoExt, sharedLibNameWithExt); | |||
module, outputNameNoExt, sharedLibNameWithExt, context); |
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.
@imaihal just be noticed that module
and context
are potentially used later by outputCode
(See Line 813/826). So please make sure outputCode
still works since module
has been released inside compileModuleToSharedLibrary
.
This PR releases MLIRContext and Module before execution opt command. They are not necessary after writing LLVM bitcode. By releasing the module, the peak memory reduced a bit.