-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
BLD Add Meson OpenMP checks #29762
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
BLD Add Meson OpenMP checks #29762
Conversation
@adrinjalali do you want to have a quick look and see whether that seems to go in the right direction to make sure we correctly define OpenMP dependencies. I need to clean up a few things but I think this is pretty much working right now. |
build_tools/meson-openmp-linter.py
Outdated
|
||
|
||
def get_canonical_name_meson(target, build_path): | ||
# TODO taking [0] I don't expect to have 2 filenames here |
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 add an assert to make check this expectation?
# TODO taking [0] I don't expect to have 2 filenames here | |
# TODO taking [0] I don't expect to have 2 filenames here | |
assert len(target["filename"]) == 1 |
@@ -40,6 +40,11 @@ jobs: | |||
- bash: | | |||
./build_tools/linting.sh | |||
displayName: Run linters | |||
- bash: | | |||
pip install ninja meson scipy |
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.
I'm surprised that SciPy is required for this check. Is this required by meson?
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.
Since #28721 we are checking the scipy version in sklearn/meson.build
(the build dependencies versions in general), so you need scipy to run meson setup
.
scikit-learn/sklearn/meson.build
Lines 41 to 45 in 4aeb191
scipy_version = run_command(py, | |
['-c', 'import scipy; print(scipy.__version__)'], check: true).stdout().strip() | |
scipy_min_version = run_command(py, ['_min_dependencies.py', 'scipy'], check: true).stdout().strip() | |
if not scipy_version.version_compare('>=' + scipy_min_version) | |
error('scikit-learn requires scipy>=' + scipy_min_version + ', got ' + scipy_version + ' instead') |
I agree it is a bit surprising but I am not sure this is worth complicating the meson.build
.
} | ||
|
||
foreach ext_name, ext_dict : cluster_extension_metadata | ||
py.extension_module( | ||
ext_name, | ||
[ext_dict.get('sources'), utils_cython_tree], | ||
dependencies: [np_dep, openmp_dep], | ||
dependencies: [np_dep] + ext_dict.get('dependencies', []), |
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.
does this now make things more specific since we have the linter?
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.
The linter will catch if an extension module use OpenMP flags but does not use it, where "using OpenMP" is defined by the following git grep
regexp. I think it makes sense but please double-check:
git grep -lP "cython.*parallel|_openmp_helpers"
https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/cluster/_dbscan_inner.pyx and https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/cluster/_hierarchical_fast.pyx do not use OpenMP AFAICT.
dependencies: [np_dep, openmp_dep], | ||
dependencies: [np_dep], |
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.
curious why you thought these are needed before then. And are they really not needed?
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.
curious why you thought these are needed before then.
This is the most complicated meson.build
we have and I would not be surprised if I cut some corners when I put it together.
And are they really not needed?
I am pretty sure they are not needed since there is nothing related to OpenMP in https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/metrics/_pairwise_distances_reduction/_datasets_pair.pyx.tp.
build_tools/meson-openmp-linter.py
Outdated
from pathlib import Path | ||
|
||
|
||
def uses_openmp(targets): |
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.
a bit of comment as what each function does would make reading the code easier, but not a big deal.
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.
That was part of the clean-up I had in mind indeed 😉
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
…nto meson-openmp-linter
OK I did the clean-up I had in mind, let me know if you think more doc/clarification is needed. |
…nto meson-openmp-linter
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.
Love this! 🥳
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.
No time to review in details nor to test that the script works as expected myself but I spotted a quick typo:
Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
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.
I could get what happens by reading the file so I'm pretty happy with the script.
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com> Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com> Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
This avoids to mess up Meson OpenMP to try to alleviate @adrinjalali's concern and avoid missing OpenMP dependencies as in #29694.
Summary:
git grep
command is used to figure out which Cython files are using OpenMPmeson introspect
produces a json that shows theninja.build
information in particular the compiler flags, so we can figure out which Cython module use OpenMP flags.The script makes sure that 1. and 2. match.
The script also found some cases where
openmp_dep
was added to an extension module dependency inmeson.build
and the Cython file was not using any OpenMP features (based ongit grep
regex) so this PR fixes this.