-
Notifications
You must be signed in to change notification settings - Fork 28
System info utils #743
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
System info utils #743
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c24cde4
system info rework
madsbk 62cd813
Apply suggestions from code review
madsbk f80a323
Merge branch 'main' of github.com:rapidsai/rapidsmpf into system_info
madsbk 8ae647e
docs
madsbk 32a3686
Update python/rapidsmpf/rapidsmpf/utils/system_info.pyx
madsbk 0b9d087
Merge branch 'main' into system_info
madsbk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
| #include <vector> | ||
|
|
||
| namespace rapidsmpf { | ||
|
|
||
| /** | ||
| * @brief Get the total amount of system memory. | ||
| * | ||
| * @return Total host memory in bytes. | ||
| * | ||
| * @note On WSL and in containerized environments, the returned value | ||
| * reflects the memory visible to the Linux kernel instance, which may | ||
| * differ from the physical memory of the host. | ||
| * | ||
| * @note Terminates the process if `sysconf(_SC_PAGE_SIZE)` or | ||
| * `sysconf(_SC_PHYS_PAGES)` fails. | ||
| */ | ||
| std::uint64_t get_total_host_memory() noexcept; | ||
|
|
||
| /** | ||
| * @brief Get the NUMA node ID associated with the calling CPU thread. | ||
| * | ||
| * A NUMA (Non-Uniform Memory Access) node represents a group of CPU cores and | ||
| * memory that have faster access to each other than to memory attached to | ||
| * other nodes. On NUMA systems, binding allocations and threads to the same | ||
| * NUMA node can significantly reduce memory access latency and improve | ||
| * bandwidth. | ||
| * | ||
| * This function returns the NUMA node on which the calling thread is currently | ||
| * executing, as determined by the operating system's CPU and memory topology. | ||
| * The value can change if the thread migrates between CPUs. | ||
| * | ||
| * If NUMA support is not available on the system or cannot be queried, the | ||
| * function returns 0, which corresponds to the single implicit NUMA node on | ||
| * non-NUMA systems. | ||
| * | ||
| * @return The NUMA node ID of the calling thread, or 0 if NUMA is unavailable. | ||
| */ | ||
| int get_current_numa_node() noexcept; | ||
|
|
||
| /** | ||
| * @brief Get current NUMA node(s) for memory binding. | ||
| * | ||
| * Queries the NUMA node associated with the CPU on which the calling thread is | ||
| * currently executing. This is a best-effort approach and may not be accurate | ||
| * in all cases. | ||
| * | ||
| * Since processes are typically scheduled on CPUs that are local to their | ||
| * memory, using the CPU's NUMA node (via `numa_node_of_cpu`) provides a | ||
| * reasonable approximation that works well in practice for topology-aware | ||
| * binding scenarios. This intentionally avoids querying the process memory | ||
| * binding policy programmatically. | ||
| * | ||
| * If NUMA support is not available or the NUMA node cannot be determined, the | ||
| * function returns a vector containing a single element, `0`, which corresponds | ||
| * to the single implicit NUMA node on non-NUMA systems. | ||
| * | ||
| * @return Vector of NUMA node IDs associated with the calling thread. | ||
| */ | ||
| std::vector<int> get_current_numa_nodes() noexcept; | ||
|
|
||
| /** | ||
| * @brief Get the total amount of host memory for a NUMA node. | ||
| * | ||
| * @param numa_id | ||
| * NUMA node for which to query the total host memory. Defaults to the | ||
| * current NUMA node as returned by `get_current_numa_node()`. | ||
| * | ||
| * @note If NUMA support is not available or the node size cannot be | ||
| * determined, this function falls back to returning the total host memory. | ||
| * | ||
| * @return Total host memory of the NUMA node in bytes. | ||
| */ | ||
| std::uint64_t get_numa_node_host_memory(int numa_id = get_current_numa_node()) noexcept; | ||
|
|
||
|
|
||
| } // namespace rapidsmpf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
|
|
||
| #include <exception> | ||
| #include <iostream> | ||
|
|
||
| #include <sched.h> | ||
| #include <unistd.h> | ||
|
|
||
| #include <rapidsmpf/system_info.hpp> | ||
|
|
||
|
|
||
| #if RAPIDSMPF_HAVE_NUMA | ||
| #include <numa.h> | ||
| #endif | ||
|
|
||
| namespace rapidsmpf { | ||
|
|
||
| std::uint64_t get_total_host_memory() noexcept { | ||
| static const uint64_t ret = [] { | ||
| auto const page_size = ::sysconf(_SC_PAGE_SIZE); | ||
| auto const phys_pages = ::sysconf(_SC_PHYS_PAGES); | ||
|
|
||
| if (page_size == -1 || phys_pages == -1) { | ||
| std::cerr << "get_total_host_memory() - fatal error: " | ||
| << "sysconf(_SC_PAGE_SIZE/_SC_PHYS_PAGES) failed" << std::endl; | ||
| std::terminate(); | ||
| } | ||
| return static_cast<std::uint64_t>(page_size) | ||
| * static_cast<std::uint64_t>(phys_pages); | ||
| }(); | ||
| return ret; | ||
| } | ||
|
|
||
| int get_current_numa_node() noexcept { | ||
| #if RAPIDSMPF_HAVE_NUMA | ||
| static const int ret = [] { | ||
| if (numa_available() == -1) { | ||
| return 0; | ||
| } | ||
| return numa_node_of_cpu(sched_getcpu()); | ||
| }(); | ||
| return ret; | ||
| #else | ||
| return 0; | ||
| #endif | ||
| } | ||
|
|
||
| std::vector<int> get_current_numa_nodes() noexcept { | ||
| std::vector<int> ret; | ||
| #if RAPIDSMPF_HAVE_NUMA | ||
| int const cpu = ::sched_getcpu(); | ||
| if (numa_available() != -1 && cpu >= 0) { | ||
| int numa_node = numa_node_of_cpu(cpu); | ||
| if (numa_node >= 0) { | ||
| ret.push_back(numa_node); | ||
| } | ||
| } | ||
| #endif | ||
| if (ret.empty()) { | ||
| return {0}; | ||
| } | ||
| return ret; | ||
| } | ||
|
|
||
| std::uint64_t get_numa_node_host_memory([[maybe_unused]] int numa_id) noexcept { | ||
| long long ret = -1; | ||
|
|
||
| #if RAPIDSMPF_HAVE_NUMA | ||
| if (numa_available() == -1) { | ||
| return get_total_host_memory(); | ||
| } | ||
| long long ignored = 0; | ||
| ret = numa_node_size64(numa_id, &ignored); | ||
| #endif | ||
|
|
||
| if (ret == -1) { | ||
| return get_total_host_memory(); | ||
| } | ||
| return static_cast<std::uint64_t>(ret); | ||
| } | ||
|
|
||
| } // namespace rapidsmpf | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.