Skip to content

Conversation

pearzt
Copy link
Contributor

@pearzt pearzt commented Sep 12, 2025

Fix #156679

There is a mismatch between the preprocessor guards around the include of hwloc.h and those protecting its usages, leading to build failures on Darwin: spack/spack-packages#1212

The suggested change introduces KMP_INCLUDES_HWLOCKMP_HWLOC_ENABLED that reflects whether hwloc is actually used. I realize that having both KMP_USE_HWLOC and KMP_HWLOC_ENABLED could be confusing, so I'm open to alternative naming suggestions.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the openmp:libomp OpenMP host runtime label Sep 12, 2025
@pearzt pearzt marked this pull request as draft September 12, 2025 19:15
@pearzt pearzt marked this pull request as ready for review September 18, 2025 08:02
@jplehr jplehr requested a review from jprotze September 18, 2025 08:02
@pearzt pearzt changed the title [Draft][OpenMP] Fix preprocessor mismatches between include and usages of hwloc [OpenMP] Fix preprocessor mismatches between include and usages of hwloc Sep 18, 2025
@jplehr jplehr requested a review from mjklemm September 18, 2025 08:02
@pearzt
Copy link
Contributor Author

pearzt commented Sep 18, 2025

The proposed changes are an attempt to fix the build issues on Darwin, but are currently untested since I don't work on a Mac. If someone could check whether this fixes the issue or ping people who can, that would be great:)

@jprotze
Copy link
Collaborator

jprotze commented Sep 18, 2025

I don't think it is necessary to replace all #if KMP_USE_HWLOC by the new macro, but I don't see how it would be harmful. All uses of __kmp_hwloc_topology should be sufficient to fix the compilation issue. For testing the changes on a non-darwin platform, it should be sufficient to just modify the #define KMP_AFFINITY_SUPPORTED 1 in kmp_os.h to set the value to 0.

How about KMP_INCLUDES_HWLOC as name for the new define?

@pearzt pearzt force-pushed the fix/hwloc-preproc-mismatch branch from f001c80 to a61b86e Compare September 18, 2025 18:06
@pearzt
Copy link
Contributor Author

pearzt commented Sep 18, 2025

@jprotze True, it's not strictly necessary, but the motivation was to help preventing similar issues in the future, since it is easy to overlook that hwloc.h is not necessarily included when KMP_USE_HWLOC is enabled.

I have tested it with #define KMP_AFFINITY_SUPPORTED 1 and the fix works for me, but it would still be nice to have confirmation on the platform where the build issue occurs.

Thanks for suggesting KMP_INCLUDES_HWLOC as a better name - PR is updated.

Copy link
Contributor

@mjklemm mjklemm left a comment

Choose a reason for hiding this comment

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

I think KMP_INCLUDES_HWLOC does not correctly describe what it actually means. KMP_USE_HWLOC is to enable hwloc support in general, bearing in mind that additional conditions may disable it again. I think KMP_HWLOC_ENABLED might be a better choice, because it then describes that a) hwloc.h has been included, and b) that the hwloc-based affinity code is also enabled.

KMP_HWLOC_ENABLED expresses whether hwloc is included *and*
hwloc-based affinity is enabled.
@pearzt
Copy link
Contributor Author

pearzt commented Oct 6, 2025

@mjklemm I've now changed it back to use KMP_HWLOC_ENABLED. As long as nobody else has a better naming suggestion or other objections, I think this is ready to move forward, right?

@pearzt pearzt requested a review from mjklemm October 6, 2025 10:06
Copy link
Contributor

@mjklemm mjklemm 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 for making the changes!

@jplehr jplehr merged commit cd24d10 into llvm:main Oct 15, 2025
9 checks passed
Copy link

@pearzt Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@pearzt
Copy link
Contributor Author

pearzt commented Oct 16, 2025

/cherry-pick cd24d10

@llvmbot
Copy link
Member

llvmbot commented Oct 16, 2025

/pull-request #163768

@llvmbot llvmbot moved this from Needs Triage to Done in LLVM Release Status Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

openmp:libomp OpenMP host runtime

Projects

Development

Successfully merging this pull request may close these issues.

[OpenMP] [runtime] Broken MacOS build in 21.1.0+ if hwloc is turned on

5 participants