Skip to content
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

Option to set the number of threads for parallel compilation #3048

Merged
merged 15 commits into from
Jan 30, 2025

Conversation

imaihal
Copy link
Collaborator

@imaihal imaihal commented Jan 21, 2025

All available CPUs are used in parallel compilation in current main branch.
This PR creates an option to set the number of threads for parallel compilation. By using -j <#threads> when compiling, thread pool with <#threads> threads are created, and used for parallel compilation in parallelFor() API.
The default value is 0 and all the available CPUs are used as same with current main. When setting -j 1, use single thread without setting thread pool.

src/onnx-mlir.cpp Outdated Show resolved Hide resolved
src/Compiler/CompilerOptions.cpp Outdated Show resolved Hide resolved
src/onnx-mlir.cpp Outdated Show resolved Hide resolved
src/onnx-mlir.cpp Outdated Show resolved Hide resolved
@@ -92,6 +92,7 @@ OptReport optReport; // onnx-mlir only
bool useOldBufferization; // onnx-mlir only
bool enableTiming; // onnx-mlir only
bool enableBoundCheck; // onnx-mlir only
int compilationNumThreads; // onnx-mlir only
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we apply this option to onnx-mlir-opt as well so that we can check performance by calling onnx-mlir-opt --constprop-onnx -j8 for a single operation? It's ok if it needs another PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@tungld I was thinking along the same lines, also for example to test that we get the same result for a test that uses parallelism.

@imaihal I would then add a test that tries the operation that you parallelized and try it with -j 4 for example. You may have to copy a large constant to do that... can lift it from a model.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@tungld @AlexandreEichenberger Thanks for the comments.

I applied this option to onnx-mlir-opt, but parallelization of constprop is not included in this PR (It is included in PR #3042). So I want to add the tests in PR #3042.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Absolutely, this PR set the options, and it will be tested once there is a new opt that can use parallelism.

Copy link
Collaborator

@tungld tungld Jan 28, 2025

Choose a reason for hiding this comment

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

@imaihal I didn't see any change to onnx-mlir-opt.cpp (e.g. MLIRContext in onnx-mlir-opt.cpp). I am curious on how this option is effective inonnx-mlir-opt command line?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@tungld New thread pool is created in MlirOptMain.cpp of MLIR. This is due to handle-split-input-file option (https://github.com/llvm/llvm-project/blob/main/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp#L609-L613). So, it seems to be difficult to set our own threadpool in onnx-mlir-opt.cpp.

In lit tests, how about using--mlir-disable-threading for single thread and using mlir default(use all cpus) for multi-thread? Or, using pass local option might be possible to specify our own thread pool.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@tungld Sorry, it is possible just by modifying onnx-mlir-opt.cpp. I updated.

@imaihal imaihal requested review from chentong319 and tungld January 27, 2025 07:35
@AlexandreEichenberger
Copy link
Collaborator

@imaihal Is your PR ready for review again, meaning do you feel you acted on all the questions/requests?

@imaihal
Copy link
Collaborator Author

imaihal commented Jan 28, 2025

@AlexandreEichenberger Yes. Could you review this again?

Copy link
Collaborator

@AlexandreEichenberger AlexandreEichenberger left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @imaihal for incorporating the feedback from Tong and I.

@imaihal imaihal merged commit 6d2b1d4 into main Jan 30, 2025
10 checks passed
@jenkins-droid
Copy link
Collaborator

Jenkins Linux amd64 Build #16186 [push] Option to set the number... started at 22:02

@jenkins-droid
Copy link
Collaborator

Jenkins Linux ppc64le Build #15215 [push] Option to set the number... started at 23:21

@jenkins-droid
Copy link
Collaborator

Jenkins Linux s390x Build #16188 [push] Option to set the number... started at 23:02

@jenkins-droid
Copy link
Collaborator

Jenkins Linux amd64 Build #16186 [push] Option to set the number... passed after 1 hr 25 min

@jenkins-droid
Copy link
Collaborator

Jenkins Linux s390x Build #16188 [push] Option to set the number... passed after 1 hr 28 min

@jenkins-droid
Copy link
Collaborator

Jenkins Linux ppc64le Build #15215 [push] Option to set the number... passed after 2 hr 26 min

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.

5 participants