HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_MEMBINDING(3)

๐Ÿ’… hwlocality_configuration โ€” Topology Detection Configuration and Query

okay bestie, welcome to hwlocality_configuration(3) from the Library Functions Manual โ€” this is the page where hwloc lets you tune how it sniffs out your hardware before it actually commits. main character energy for your topology, fr fr ๐ŸŽ€


โœจ NAME โœจ

hwlocality_configuration โ€” Topology Detection Configuration and Query ๐ŸŒธ


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

๐Ÿงฑ Data Structures

bestie, these are the little structs you'll be poking at โ€” lowkey the whole vibe check of your machine lives in here:

  • struct hwloc_topology_discovery_support
  • struct hwloc_topology_cpubind_support
  • struct hwloc_topology_membind_support
  • struct hwloc_topology_misc_support
  • struct hwloc_topology_support

๐Ÿท๏ธ Enumerations

okay so there are two enums and honestly? iconic. first up, the flags โ€” note the exact bit values, do not come for them:

enum hwloc_topology_flags_e {
    HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED,
    HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM,
    HWLOC_TOPOLOGY_FLAG_THISSYSTEM_ALLOWED_RESOURCES,
    HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT = (1UL<<3),
    HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_CPUBINDING = (1UL<<4),
    HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_MEMBINDING = (1UL<<5),
    HWLOC_TOPOLOGY_FLAG_DONT_CHANGE_BINDING = (1UL<<6),
    HWLOC_TOPOLOGY_FLAG_NO_DISTANCES = (1UL<<7),
    HWLOC_TOPOLOGY_FLAG_NO_MEMATTRS = (1UL<<8),
    HWLOC_TOPOLOGY_FLAG_NO_CPUKINDS = (1UL<<9)
};

and then the type filters โ€” these ones decide which object types get to stay in the group chat ๐Ÿซถ:

enum hwloc_type_filter_e {
    HWLOC_TYPE_FILTER_KEEP_ALL,
    HWLOC_TYPE_FILTER_KEEP_NONE,
    HWLOC_TYPE_FILTER_KEEP_STRUCTURE,
    HWLOC_TYPE_FILTER_KEEP_IMPORTANT
};

๐Ÿ› ๏ธ Functions

the whole cast, no skips, no cuts โ€” every single one:

int hwloc_topology_set_flags (hwloc_topology_t topology, unsigned long flags)
unsigned long hwloc_topology_get_flags (hwloc_topology_t topology)
int hwloc_topology_is_thissystem (hwloc_topology_t restrict topology)
const struct hwloc_topology_support * hwloc_topology_get_support
    (hwloc_topology_t restrict topology)
int hwloc_topology_set_type_filter (hwloc_topology_t topology,
    hwloc_obj_type_t type, enum hwloc_type_filter_e filter)
int hwloc_topology_get_type_filter (hwloc_topology_t topology,
    hwloc_obj_type_t type, enum hwloc_type_filter_e *filter)
int hwloc_topology_set_all_types_filter (hwloc_topology_t topology, enum
    hwloc_type_filter_e filter)
int hwloc_topology_set_cache_types_filter (hwloc_topology_t topology,
    enum hwloc_type_filter_e filter)
int hwloc_topology_set_icache_types_filter (hwloc_topology_t topology,
    enum hwloc_type_filter_e filter)
int hwloc_topology_set_io_types_filter (hwloc_topology_t topology, enum
    hwloc_type_filter_e filter)
void hwloc_topology_set_userdata (hwloc_topology_t topology, const void
    *userdata)
void * hwloc_topology_get_userdata (hwloc_topology_t topology)

๐ŸŒˆ Detailed Description ๐ŸŒˆ

okay so here's the tea โ˜• โ€” there are several functions you can optionally call between hwloc_topology_init() and hwloc_topology_load(), and what they do is configure how the detection itself should go down. like, you get to be the director of the whole operation before the cameras roll ๐ŸŽฌ

things you can do in that little window:

  • ignore some object types (bye bestie ๐Ÿ‘‹)
  • define a synthetic topology (yes, you can just invent one, no cap)
  • etc.
๐Ÿงš quick vibe check: this is all optional setup stuff, and it only makes sense between hwloc_topology_init() and hwloc_topology_load() โ€” that's your window, don't miss it ๐Ÿ’–

๐Ÿ’… ENUMERATION TYPE DOCUMENTATION ๐Ÿ’…

๐ŸŒˆ enum hwloc_topology_flags_e

Okay so these are the flags you slap onto a topology context before you load it, bestie. Like, they go into hwloc_topology_set_flags(), and hwloc_topology_get_flags() can hand them right back to you. ๐ŸŽ€


๐Ÿซถ HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED

Detect the whole entire system, ignore reservations, and include disallowed objects. Basically gather all the online resources, even if the admin disabled some of them โ€” for instance, ignore Linux Cgroup/Cpusets and gather every processor and memory node. That said, offline PUs and NUMA nodes are still ignored. No cap. ๐Ÿ’€

When this flag is not set, PUs and NUMA nodes that are disallowed are not added to the topology at all. Parent objects (package, core, cache, etc.) only get added if some of their children are allowed. All existing PUs and NUMA nodes in the topology are allowed. In that case hwloc_topology_get_allowed_cpuset() and hwloc_topology_get_allowed_nodeset() are equal to the root object cpuset and nodeset. โœจ

When this flag is set, the actual sets of allowed PUs and NUMA nodes are given by hwloc_topology_get_allowed_cpuset() and hwloc_topology_get_allowed_nodeset(). They may be smaller than the root object cpuset and nodeset, iykyk. ๐Ÿฆ‹

If your current topology gets exported to XML and reimported later, this flag should be set again in the reimported topology so that disallowed resources are reimported as well. Don't forget, bestie. ๐Ÿ˜ญ

๐Ÿงš HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM

Assume that the selected backend provides the topology for the system on which we are running. This forces hwloc_topology_is_thissystem() to return 1, i.e. it makes hwloc assume that the selected backend provides the topology for the system on which we're running โ€” even if it's not the OS-specific backend but the XML backend for instance. What that means: the binding functions actually call the OS-specific system calls and really do binding, while the XML backend would otherwise just hand you empty hooks returning success. ๐Ÿ™ˆ

Setting the environment variable HWLOC_THISSYSTEM may also result in the same behavior. ๐Ÿ‘‘

This one's iconic for efficiency reasons: detect the topology once, save it to an XML file, quickly reload it later through the XML backend โ€” but still have binding functions actually do bind. Main character energy fr fr. โญ


๐Ÿ“ HWLOC_TOPOLOGY_FLAG_THISSYSTEM_ALLOWED_RESOURCES

Get the set of allowed resources from the local operating system even if the topology was loaded from XML or a synthetic description. If the topology was loaded from XML or from a synthetic string, restrict it by applying the current process restrictions such as Linux Cgroup/Cpuset. ๐Ÿ’–

This is useful when the topology is not loaded directly from the local machine (e.g. for performance reason) and it comes with all resources, while the running process is restricted to only parts of the machine. Lowkey perfect for that. ๐ŸŒธ

This flag is ignored unless HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM is also set, since the loaded topology must match the underlying machine where restrictions will be gathered from. Periodt. ๐Ÿ’…

Setting the environment variable HWLOC_THISSYSTEM_ALLOWED_RESOURCES would result in the same behavior. โœจ


๐ŸŽ€ HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT

Import all support bits from the imported topology. When importing an XML topology from a remote machine, binding is disabled by default (see HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM). This disabling is also marked by putting zeroes in the corresponding supported feature bits reported by hwloc_topology_get_support(). ๐Ÿ’€

The flag HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT actually imports binding support bits from the remote machine. It also sets the flag imported_support in the struct hwloc_topology_misc_support array. If the imported XML did not contain any support information (exporter hwloc is too old), this flag is not set. ๐Ÿ˜ญ

Note that non-binding support bits, e.g. the ability to discover NUMA nodes, are always imported. ๐Ÿฆ‹

Note that these supported features are only relevant for the hwloc installation that actually exported the XML topology (it may vary with the operating system, or with how hwloc was compiled). ๐Ÿงš

Note that setting this flag however does not enable binding for the locally imported hwloc topology โ€” it only reports what the remote hwloc and machine support. Read that twice, bestie. ๐Ÿซถ

๐Ÿ”ฅ HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_CPUBINDING

Do not consider resources outside of the process CPU binding. If the binding of the process is limited to a subset of cores, ignore the other cores during discovery. ๐Ÿ’…

The resulting topology is identical to what a call to hwloc_topology_restrict() would generate, but this flag also prevents hwloc from ever touching other resources during the discovery. ๐Ÿ‘‘

This flag especially tells the x86 backend to never temporarily rebind a thread on any excluded core. That's useful on Windows because such temporary rebinding can change the process binding. Another use-case is to avoid cores that would not be able to perform the hwloc discovery anytime soon because they're busy executing some high-priority real-time tasks. ๐Ÿ˜ฎโ€๐Ÿ’จ

If process CPU binding is not supported, the thread CPU binding is considered instead if supported, or the flag is ignored. ๐ŸŒˆ

This flag requires HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM as well, since binding support is required. ๐Ÿ’–

๐Ÿ’œ HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_MEMBINDING

Do not consider resources outside of the process memory binding. If the binding of the process is limited to a subset of NUMA nodes, ignore the other NUMA nodes during discovery. ๐Ÿ“

The resulting topology is identical to what a call to hwloc_topology_restrict() would generate, but this flag also prevents hwloc from ever touching other resources during the discovery. โญ

This flag is meant to be used together with HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_CPUBINDING when both cores and NUMA nodes should be ignored outside of the process binding. ๐Ÿซถ

If process memory binding is not supported, the thread memory binding is considered instead if supported, or the flag is ignored. ๐ŸŒธ

This flag requires HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM as well, since binding support is required. ๐Ÿ˜ญ

๐Ÿฆ‹ HWLOC_TOPOLOGY_FLAG_DONT_CHANGE_BINDING

Do not ever modify the process or thread binding during discovery. This flag disables all hwloc discovery steps that require a change of the process or thread binding. This currently only affects the x86 backend, which gets entirely disabled. ๐Ÿ’€

This is useful when hwloc_topology_load() is called while the application also creates additional threads or modifies the binding. ๐Ÿ™ˆ

This flag is also a strict way to make sure the process binding will not change due to thread binding changes on Windows (see HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_CPUBINDING). ๐Ÿ‘‘


๐ŸŒˆ HWLOC_TOPOLOGY_FLAG_NO_DISTANCES

Ignore distances. Ignore distance information from the operating systems (and from XML) and hence do not use distances for grouping. Simple as that, bestie. โœจ


๐Ÿ’œ HWLOC_TOPOLOGY_FLAG_NO_MEMATTRS

Ignore memory attributes and tiers. Ignore memory attributes from the operating systems (and from XML). Hence also do not try to build memory tiers. ๐ŸŽ€


๐Ÿซถ HWLOC_TOPOLOGY_FLAG_NO_CPUKINDS

Ignore CPU Kinds. Ignore CPU kind information from the operating systems (and from XML). That's the whole vibe. ๐Ÿ’…


๐ŸŒธ enum hwloc_type_filter_e

Type filtering flags, bestie โ€” this is how you tell hwloc which object types to keep around. By default, most objects are kept (HWLOC_TYPE_FILTER_KEEP_ALL). Instruction caches, memory-side caches, I/O and Misc objects are ignored by default (HWLOC_TYPE_FILTER_KEEP_NONE). Group levels are ignored unless they bring structure (HWLOC_TYPE_FILTER_KEEP_STRUCTURE). ๐Ÿฆ‹

Note that group objects are also ignored individually (without the entire level) when they do not bring structure. ๐Ÿ˜Œ


๐Ÿ‘‘ HWLOC_TYPE_FILTER_KEEP_ALL

Keep all objects of this type. Cannot be set for HWLOC_OBJ_GROUP โ€” groups are designed only to add more structure to the topology, so like, that's a no. ๐Ÿšซ


๐ŸŒˆ HWLOC_TYPE_FILTER_KEEP_NONE

Ignore all objects of this type. The bottom-level type HWLOC_OBJ_PU, the HWLOC_OBJ_NUMANODE type, and the top-level type HWLOC_OBJ_MACHINE may not be ignored. Those three are literally the main characters, sorry. ๐Ÿ’€


๐Ÿ’– HWLOC_TYPE_FILTER_KEEP_STRUCTURE

Only ignore objects if their entire level does not bring any structure. Keep the entire level of objects if at least one of these objects adds structure to the topology. An object brings structure when it has multiple children and it is not the only child of its parent. ๐ŸŽ€

If all objects in the level are the only child of their parent, or if all of them have a single child, the entire level may be removed. A common example is caches that are private to each core. ๐Ÿ“

This filter cannot be used for I/O and Misc objects since the topology structure does not matter there. ๐Ÿ™ˆ

๐Ÿ”ฅ HWLOC_TYPE_FILTER_KEEP_IMPORTANT

Only keep likely-important objects of the given type. It is only useful for I/O object types. For HWLOC_OBJ_PCI_DEVICE and HWLOC_OBJ_OS_DEVICE, it means that only objects of major/common kinds are kept (storage, network, OpenFabrics, CUDA, OpenCL, RSMI, NVML, and displays). Also, only OS devices directly attached on PCI (e.g. no USB) are reported. For HWLOC_OBJ_BRIDGE, it means that bridges are kept only if they have children. ๐Ÿซถ

This flag is equivalent to HWLOC_TYPE_FILTER_KEEP_ALL for Normal, Memory and Misc types since they are likely important. Slay. โญ

โœจ FUNCTION DOCUMENTATION โœจ

okay bestie, this is the part where we meet every single function in this crew ๐Ÿ’– no skipping, no skimming, we're doing all of them. Let's go ๐Ÿซถ


๐ŸŽ€ hwloc_topology_get_flags

unsigned long hwloc_topology_get_flags (hwloc_topology_t topology)

Grabs the OR'ed flags of a topology โ€” literally the OR'ed set of hwloc_topology_flags_e that this topology is carrying around.

Lowkey important: if hwloc_topology_set_flags() was never called earlier, no flags are set at all (0 is what you get back). So a zero isn't a bug, it's just a fresh little topology with nothing switched on ๐Ÿฆ‹

Returns: the flags that were previously set with hwloc_topology_set_flags().

๐Ÿ’ก Note: this function may also be called after hwloc_topology_load(). You're not locked out post-load, bestie.

๐ŸŒธ hwloc_topology_get_support

const struct hwloc_topology_support * hwloc_topology_get_support
    (hwloc_topology_t restrict topology)

Retrieves the topology support ๐Ÿ’œ Each flag is basically a vibe check on one feature: if it's 0, that feature is not supported. If it's 1, the feature is supported โ€” but heads up, the corresponding call may still fail in some corner cases ๐Ÿ˜ญ so 1 is not a pinky promise, it's a strong maybe.

These features are also listed by hwloc-info --support โœจ

The reported features are what the current topology supports on the current machine. And if the topology was exported to XML from another machine and later imported here, support still describes what is supported for this imported topology after import. In that case, binding is reported as unsupported by default (see HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM).

But wait ๐Ÿ‘€ the topology flag HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT may be used to report all supported features of the original remote machine instead โ€” binding included. If they were successfully imported, imported_support will be set in the struct hwloc_topology_misc_support array.

Returns: a pointer to a support structure.

๐Ÿ’œ Note, and read this twice, bestie: - The function cannot return NULL. Ever. - The returned pointer should not be freed โ€” it belongs to the hwloc library, it is not yours to yeet. - This function may be called before or after hwloc_topology_load(), but the support structure only contains valid information after.

๐Ÿฆ‹ hwloc_topology_get_type_filter

int hwloc_topology_get_type_filter (hwloc_topology_t topology,
    hwloc_obj_type_t type, enum hwloc_type_filter_e * filter)

Gets the current filtering for the given object type.

Returns: 0 on success, -1 on error.


๐Ÿ’ซ hwloc_topology_get_userdata

void * hwloc_topology_get_userdata (hwloc_topology_t topology)

Retrieves the topology-specific userdata pointer โ€” aka that application-given private data pointer you previously set with hwloc_topology_set_userdata() ๐ŸŽ€

Returns: a pointer to the private-data if anyโ€ฆ or NULL if no private-data was previously set ๐Ÿ™ˆ


๐Ÿ‘‘ hwloc_topology_is_thissystem

int hwloc_topology_is_thissystem (hwloc_topology_t restrict topology)

The big question: does this topology context come from this system? ๐ŸŒˆ

Returns:

  • 1 if this topology context was built using the system running this program.
  • 0 instead โ€” for instance if you're using another file-system root, an XML topology file, or a synthetic topology.
โญ Note: this function may also be called after hwloc_topology_load().

๐Ÿงน hwloc_topology_set_all_types_filter

int hwloc_topology_set_all_types_filter (hwloc_topology_t topology, enum
    hwloc_type_filter_e filter)

Sets the filtering for all object types in one big swoop. If some types don't support this filtering, they are silently ignored โ€” no drama, no error, they just quietly opt out ๐Ÿ’€

Returns: 0 on success, -1 on error.


๐Ÿ“ hwloc_topology_set_cache_types_filter

int hwloc_topology_set_cache_types_filter (hwloc_topology_t topology, enum
    hwloc_type_filter_e filter)

Sets the filtering for all CPU cache object types. Memory-side caches are not involved, since they are not CPU caches. Periodt.

Returns: 0 on success, -1 on error.


๐Ÿ”ฅ hwloc_topology_set_flags

int hwloc_topology_set_flags (hwloc_topology_t topology, unsigned long
    flags)

Sets an OR'ed set of hwloc_topology_flags_e onto a topology that was not yet loaded โ€” this is a pre-load move, bestie, timing matters ๐Ÿ’…

If this function is called multiple times, the last invocation will erase and replace the set of flags that was previously set. No stacking, no accumulating, last one wins, no cap.

By default, no flags are set (0) ๐Ÿฆ‹

The flags set in a topology may be retrieved with hwloc_topology_get_flags().

Returns:

  • 0 on success.
  • -1 on error, for instance if flags are invalid.

โญ hwloc_topology_set_icache_types_filter

int hwloc_topology_set_icache_types_filter (hwloc_topology_t topology, enum
    hwloc_type_filter_e filter)

Sets the filtering for all CPU instruction cache object types. Memory-side caches are not involved since they are not CPU caches โ€” same energy as the cache one, just instruction-flavoured ๐ŸŽ€

Returns: 0 on success, -1 on error.


๐Ÿ’œ hwloc_topology_set_io_types_filter

int hwloc_topology_set_io_types_filter (hwloc_topology_t topology, enum
    hwloc_type_filter_e filter)

Sets the filtering for all I/O object types.

Returns: 0 on success, -1 on error.


๐ŸŒˆ hwloc_topology_set_type_filter

int hwloc_topology_set_type_filter (hwloc_topology_t topology,
    hwloc_obj_type_t type, enum hwloc_type_filter_e filter)

Sets the filtering for the given object type.

Returns: 0 on success, -1 on error.


๐Ÿงš hwloc_topology_set_userdata

void hwloc_topology_set_userdata (hwloc_topology_t topology, const void *
    userdata)

Sets the topology-specific userdata pointer ๐Ÿ’– Each topology may store one application-given private data pointer. It is initialized to NULL, and hwloc will never modify it. Never ever. It's yours.

Use it as you wish, after hwloc_topology_init() and until hwloc_topolog_destroy() ๐ŸŒธ (and yes, that's exactly how it's spelled up there โ€” don't come for me, I'm just the messenger ๐Ÿ’€)

๐ŸŽ€ Heads up bestie: this pointer is not exported to XML.

๐ŸŒŸ AUTHOR ๐ŸŒŸ

Generated automatically by Doxygen for Hardware Locality (hwloc) from the source code. Iconic behaviour, honestly. No notes.


and that's the whole page, bestie ๐Ÿซถ this was Hardware Locality (hwloc), Version 2.15.0, page hwlocality_configuration(3) โ€” go forth and configure your topology with main character energy โœจ๐Ÿ’…

๐Ÿ“ฆ where this page comes from