Skip to content

Conversation

chentong319
Copy link
Collaborator

@chentong319 chentong319 commented Aug 25, 2025

The purpose of this PR is to get a clearer output of --EmitONNXIR with unused ops removed. This is useful when a model is manually altered.
To me, the existing invocation of CSE pass in conversion from onnx to krnl could be removed. But I did not touch it in this PR.

Signed-off-by: Chen Tong <[email protected]>
Signed-off-by: Chen Tong <[email protected]>
@chentong319 chentong319 requested a review from tungld August 25, 2025 20:15
// with --EmitONNXIR.
// This pass is inserted before the instrumentation pass, which may add
// instrumentation ops with external sideeffect.
pm.addPass(mlir::createCSEPass());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if symbol-dce is more appropriate?: https://mlir.llvm.org/docs/Passes/#-symbol-dce

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the symbolDCE also removes the symbols, though there is no symbol declaration at this stage in onnx-mlir.
I replaced the CSE with symbolDCE and removed the debugging parameter, which is always true now.

Signed-off-by: Chen Tong <[email protected]>
Signed-off-by: Chen Tong <[email protected]>
Signed-off-by: Chen Tong <[email protected]>
Copy link
Collaborator

@tungld tungld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you accidentally removed CSE? CSE is needed to merge parallel same patterns into one.

@@ -168,7 +168,7 @@ void addONNXToZHighPasses(mlir::PassManager &pm) {
pm.addPass(onnx_mlir::zhigh::createZHighConstPropagationPass());

// Remove common sub-expressions.
pm.addPass(mlir::createCSEPass());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it removed by accident?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, my mistake.

if (enableCSE)
// Eliminate common sub-expressions before lowering to Krnl.
// TODO: enable this by default when we make sure it works flawlessly.
pm.addPass(mlir::createCSEPass());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this was removed by accident since enableCSE=true means we call pm.addPass(mlir::createCSEPass());.

@chentong319
Copy link
Collaborator Author

I found that this PR is not really needed. The size of remaining IR is caused by the embedding weights, simplification can not help.

@chentong319 chentong319 closed this Sep 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants