-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[R-package] Remove non-beneficial parallelization #6209
Conversation
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.
Thanks for this!
I hadn't seen #pragma omp simd
before, but based on my read of these:
- https://www.ibm.com/docs/en/xl-c-and-cpp-linux/16.1.0?topic=pdop-pragma-omp-simd
- https://www.openmp.org/spec-html/5.0/openmpsu42.html
I agree that it's more appropriate than multi-threading for these particular loops. Assuming CI doesn't uncover any portability issues, I support this.
/gha run r-valgrind Workflow R valgrind tests has been triggered! 🚀 Status: success ✔️. |
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.
In the MSVC jobs, I see the following compilation errors:
C:\Users\runneradmin\RtmpuUk2KH\Rbuild1ed04e141067\lightgbm\src\src\lightgbm_R.cpp(230,9): error C7660: 'simd': requires '-openmp:experimental' command line option(s) [C:\Users\runneradmin\RtmpuUk2KH\Rbuild1ed04e141067\lightgbm\src\build\lightgbm_capi_objs.vcxproj]
I see that with both Visual Studio 2019 (build link)) and Visual Studio 2022 (build link).
I found some details on this at https://learn.microsoft.com/en-us/cpp/build/reference/openmp-enable-openmp-2-0-support?view=msvc-170.
Could you please just guard these so they'll be ignored when compiling with MSVC?
Similar to what XGBoost does: https://github.com/dmlc/xgboost/blob/a197899161fa70e681101de4232745fdfe737804/R-package/src/xgboost_R.cc#L403-L405
#ifndef _MSC_VER
#pragma omp simd
#endif
979ed8a
to
7fcbd9c
Compare
Added. But on second thought, these aren't going to do anything in most cases, so I've replaced the loops altogether and switched vectors to unique pointers where possible. |
/gha run r-valgrind Workflow R valgrind tests has been triggered! 🚀 Status: success ✔️. |
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.
Looks great to me. I'm confident in this based on the passing tests...these code paths are all well-covered.
Thanks very much.
This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this. |
The R wrapper makes usage of OMP parallel clauses for operations like converting from one data type to another.
In a regular amd64 platform, these clauses would not make the operations faster, since these operations (assuming #6208 gets merged beforehand) are so fast that speed of execution is given by how fast it can read data from RAM, and having multiple threads reading from RAM (as far as desktop amd64 is concerned) does not make those reads any faster.
This PR switches the clause from parallel to
simd
which would be more appropriate foramd64
, but is unlikely to make a difference in most cases since there aren't dedicated SIMD instructions for all these operations.