-
Notifications
You must be signed in to change notification settings - Fork 329
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
Conversation
Signed-off-by: Haruki Imai <[email protected]>
Signed-off-by: Haruki Imai <[email protected]>
Signed-off-by: Haruki Imai <[email protected]>
Signed-off-by: Haruki Imai <[email protected]>
src/Compiler/CompilerOptions.cpp
Outdated
@@ -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 |
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.
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.
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.
@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.
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.
@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.
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.
Absolutely, this PR set the options, and it will be tested once there is a new opt that can use parallelism.
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 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?
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.
@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.
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.
@tungld Sorry, it is possible just by modifying onnx-mlir-opt.cpp. I updated.
Signed-off-by: Haruki Imai <[email protected]>
Signed-off-by: Haruki Imai <[email protected]>
Signed-off-by: Haruki Imai <[email protected]>
Signed-off-by: Haruki Imai <[email protected]>
@imaihal Is your PR ready for review again, meaning do you feel you acted on all the questions/requests? |
@AlexandreEichenberger Yes. Could you review this again? |
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.
LGTM, thanks @imaihal for incorporating the feedback from Tong and I.
Signed-off-by: Haruki Imai <[email protected]>
Signed-off-by: Haruki Imai <[email protected]>
Signed-off-by: Haruki Imai <[email protected]>
Jenkins Linux amd64 Build #16186 [push] Option to set the number... started at 22:02 |
Jenkins Linux ppc64le Build #15215 [push] Option to set the number... started at 23:21 |
Jenkins Linux s390x Build #16188 [push] Option to set the number... started at 23:02 |
Jenkins Linux amd64 Build #16186 [push] Option to set the number... passed after 1 hr 25 min |
Jenkins Linux s390x Build #16188 [push] Option to set the number... passed after 1 hr 28 min |
Jenkins Linux ppc64le Build #15215 [push] Option to set the number... passed after 2 hr 26 min |
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 inparallelFor()
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.