Skip to content

Conversation

pearzt
Copy link

@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
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
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.

#include "kmp_dispatch_hier.h"
#endif
#if KMP_USE_HWLOC
#if KMP_INCLUDES_HWLOC
Copy link
Contributor

@mjklemm mjklemm Sep 26, 2025

Choose a reason for hiding this comment

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

Several of these do not have the comment to indicate which #endif is closing off that compilation guards. It would be great if you could add them.

Copy link
Author

Choose a reason for hiding this comment

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

Done

KMP_HWLOC_ENABLED expresses whether hwloc is included *and*
hwloc-based affinity is enabled.
@pearzt
Copy link
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!

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
None yet
Development

Successfully merging this pull request may close these issues.

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