Skip to content

[OpenMP] Add memory allocation using hwloc #132843

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

Merged
merged 3 commits into from
Apr 2, 2025

Conversation

nawrinsu
Copy link
Contributor

This patch adds support for memory allocation using hwloc. To enable memory allocation using hwloc, env KMP_TOPOLOGY_METHOD=hwloc needs to be used. If hwloc is not supported/available, allocation will fallback to default path.

This patch adds support for memory allocation using hwloc. To enable
memory allocation using hwloc, env KMP_TOPOLOGY_METHOD=hwloc needs to
be used. If hwloc is not supported/available, allocation will fallback
to default path.
@nawrinsu nawrinsu requested a review from jpeyton52 March 24, 2025 23:36
@llvmbot llvmbot added the openmp:libomp OpenMP host runtime label Mar 24, 2025
Copy link
Contributor

@jpeyton52 jpeyton52 left a comment

Choose a reason for hiding this comment

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

Sorry about this, it appears that the memory attributes were added in HWLOC 2.3, but there was some mishap with the hwloc_location enum (there is a reference to HWLOC_LOCATION_TYPE_CPUSET in the __kmp_hwloc_alloc_membind() function. To get it working with all the 2.x versions of HWLOC, I had to add this little bit right under the #includes at the top of the file:

+#if KMP_USE_HWLOC
+#if HWLOC_API_VERSION > 0x00020300
+#define KMP_HWLOC_LOCATION_TYPE_CPUSET HWLOC_LOCATION_TYPE_CPUSET
+#elif HWLOC_API_VERSION == 0x00020300
+#define KMP_HWLOC_LOCATION_TYPE_CPUSET hwloc_location::HWLOC_LOCATION_TYPE_CPUSET
+#else
+enum hwloc_memattr_id_e {
+  HWLOC_MEMATTR_ID_BANDWIDTH,
+  HWLOC_MEMATTR_ID_CAPACITY
+};
+#endif
+#endif

Then we can change the HWLOC_API_VERSION to 0x00020400 to 0x00020300

Copy link
Contributor

@jpeyton52 jpeyton52 left a comment

Choose a reason for hiding this comment

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

LGTM

@nawrinsu nawrinsu merged commit 730e8a4 into llvm:main Apr 2, 2025
9 checks passed
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Apr 2, 2025
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Apr 3, 2025
This patch adds support for memory allocation using hwloc. To enable
memory allocation using hwloc, env KMP_TOPOLOGY_METHOD=hwloc needs to be
used. If hwloc is not supported/available, allocation will fallback to
default path.
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.

3 participants