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

[R-package] Remove non-beneficial parallelization #6209

Merged
merged 5 commits into from
Jan 3, 2024

Conversation

david-cortes
Copy link
Contributor

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 for amd64, but is unlikely to make a difference in most cases since there aren't dedicated SIMD instructions for all these operations.

Copy link
Collaborator

@jameslamb jameslamb left a 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:

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.

@jameslamb
Copy link
Collaborator

jameslamb commented Dec 28, 2023

/gha run r-valgrind

Workflow R valgrind tests has been triggered! 🚀
https://github.com/microsoft/LightGBM/actions/runs/7344164225

Status: success ✔️.

@jameslamb jameslamb self-requested a review December 28, 2023 04:11
Copy link
Collaborator

@jameslamb jameslamb left a 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

@david-cortes
Copy link
Contributor Author

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.

@jameslamb
Copy link
Collaborator

jameslamb commented Dec 30, 2023

/gha run r-valgrind

Workflow R valgrind tests has been triggered! 🚀
https://github.com/microsoft/LightGBM/actions/runs/7361885363

Status: success ✔️.

@jameslamb jameslamb self-requested a review January 3, 2024 04:35
Copy link
Collaborator

@jameslamb jameslamb left a 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.

@jameslamb jameslamb merged commit 78d021c into microsoft:master Jan 3, 2024
42 checks passed
Copy link

github-actions bot commented Jan 9, 2025

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants