PyHwloc API

This page provides the reference for the high-level interface. Most classes in this interface have a native_handle property that returns a C handle for the underlying type. Users can use it to reach to the low-level interface.

The Top Level Module

The top-level pyhwloc exports some shorthands for creating the Topology.

pyhwloc.from_pid(pid: int, *, load: bool = False) Topology

Create a topology from a specific process ID.

Parameters

pid

Process ID to get topology from

load :

Whether the object should load the topology from the system. Set to False if you want to apply additional filters.

Returns

New Topology instance for the specified process.

pyhwloc.from_synthetic(description: str, *, load: bool = False) Topology

Create a topology from a synthetic description.

Parameters

description

Synthetic topology description (e.g., “node:2 core:2 pu:2”)

load :

Whether the object should load the topology from the system. Set to False if you want to apply additional filters.

Returns

New Topology instance from the synthetic description.

pyhwloc.from_this_system(*, load: bool = False) Topology

Create a topology from this system.

Parameters

load :

Whether the object should load the topology from the system. Set to False if you want to apply additional filters.

Returns

New Topology instance for the specified process.

pyhwloc.from_xml_buffer(xml_buffer: str, *, load: bool = False) Topology

Create a topology from a XML string.

Parameters

xml_buffer

XML string containing topology

load :

Whether the object should load the topology from the system. Set to False if you want to apply additional filters.

Returns

New Topology instance loaded from XML string.

pyhwloc.from_xml_file(xml_path: PathLike | str, *, load: bool = False) Topology

Create a topology from a XML file.

Parameters

xml_path

Path to XML file containing topology

load :

Whether the object should load the topology from the system. Set to False if you want to apply additional filters.

Returns

New Topology instance loaded from XML file.

The Bitmap Interface

class pyhwloc.bitmap.Bitmap

This represents a set of integers (positive or null). A bitmap may be of infinite size (all bits are set after some point). A bitmap may even be full if all bits are set.

allbut(bit: int) None

See hwloc_bitmap_allbut()

andnot(other: Bitmap) Bitmap

See hwloc_bitmap_andnot()

any() bool

True if bitmap has any set bits.

clear_range(begin: int, end: int) None

Clear a range of bits [begin, end).

clr(bit: int) None

See hwloc_bitmap_clr()

fill() None

See hwloc_bitmap_fill()

first() int

See hwloc_bitmap_first()

classmethod from_list_string(list_string: str) Bitmap

Parse a bitmap from list string representation (e.g., ‘0,2,4-6’).

classmethod from_sched_set(index: set[int]) Bitmap

From a Python set of index, typically used by the os.sched_* functions to represent CPU index.

classmethod from_string(string: str) Bitmap

Parse a bitmap from string representation.

classmethod from_taskset_string(string: str) Bitmap

Parse a bitmap from taskset string representation.

classmethod full() Bitmap

Create an infinite bitmap with all bits set.

intersects(other: Bitmap) bool

See hwloc_bitmap_intersects()

is_full() bool

See hwloc_bitmap_isfull()

is_included(other: Bitmap) bool

See hwloc_bitmap_isincluded()

is_zero() bool

See hwloc_bitmap_iszero()

iter_unset() Iterator[int]

Iterate over unset bits in the bitmap.

last() int

See hwloc_bitmap_last()

only(bit: int) None

See hwloc_bitmap_only()

set(bit: int) None

See hwloc_bitmap_set()

set_range(begin: int, end: int) None

Set a range of bits [begin, end).

singlify() None

See hwloc_bitmap_singlify()

to_list_string() str

Convert the bitmap to a list string representation (e.g., ‘0,2,4-6’).

to_sched_set() set[int]

Convert to a Python set of index, typically used by the os.sched_* functions to represent CPU index.

to_string() str

Convert the bitmap to the hwloc bitmap string representation (Hex representation of the integers).

to_taskset_string() str

Convert bitmap to taskset string representation (Concatenated hex strings).

weight() int

See hwloc_bitmap_weight()

zero() None

See hwloc_bitmap_zero()

pyhwloc.bitmap.compare_first(lhs: Bitmap, rhs: Bitmap) int

See hwloc_bitmap_compare_first()

The Topology Interface

class pyhwloc.topology.AllowFlags(*values)

See hwloc_allow_flags_e.

class pyhwloc.topology.CpuBindFlags(*values)

See hwloc_cpubind_flags_t.

class pyhwloc.topology.DistancesKind(*values)

See hwloc_distances_kind_e.

class pyhwloc.topology.ExportSyntheticFlags(*values)

See hwloc_topology_export_synthetic_flags_e.

class pyhwloc.topology.ExportXmlFlags(*values)

See hwloc_topology_export_xml_flags_e.

class pyhwloc.topology.MemBindFlags(*values)

See hwloc_membind_flags_t.

class pyhwloc.topology.MemBindPolicy(*values)

See hwloc_membind_policy_t.

class pyhwloc.topology.RestrictFlags(*values)

See hwloc_restrict_flags_e.

class pyhwloc.topology.Topology

High-level interface for the hwloc topology.

This class provides a context manager interface for working with hardware topology information. It automatically handles topology initialization, loading, and cleanup.

The default Topology constructor initializes a topology object based on the current system. For alternative topology sources, use the class methods:

# Context manager usage (recommended)
with Topology.from_this_system() as topo:  # Current system
    print(f"Topology depth: {topo.depth}")

# Synthetic topology
with Topology.from_synthetic("node:2 core:2 pu:2") as topo:
    print(f"Topology depth: {topo.depth}")

# Load from XML file
with Topology.from_xml_file("/path/to/topology.xml") as topo:
    print(f"Topology depth: {topo.depth}")

# Direct usage,  cleanup is recommended but not required.
try:
    topo = Topology()
    print(f"Topology depth: {topo.depth}")
finally:
    topo.destroy()

# Uses automatic cleanup in the `__del__` method instead. This depends on the gc
# and doesn't propagate exceptions raised inside the destroy method.
topo = Topology()

To use a filter or set a component, users need to call the load() explicitly when not using the context manager:

with Topology.from_this_system().set_all_types_filter(
    TypeFilter.KEEP_IMPORTANT
) as topo:
    # auto load when using a context manager
    pass

topo = Topology.from_this_system().set_all_types_filter(
    TypeFilter.KEEP_IMPORTANT
).load() # Load the topology

Lastly, there’s a short hand for using the current system if you don’t need to apply filter or set component/flags:

with Topology() as topo:
    print(f"Topology depth: {topo.depth}")
allow(cpuset: Bitmap | None, nodeset: Bitmap | None, flags: int | AllowFlags | Sequence[AllowFlags]) None

See hwloc_topology_allow()

property allowed_cpuset: Bitmap

See hwloc_topology_get_allowed_cpuset()

property allowed_nodeset: Bitmap

See hwloc_topology_get_allowed_nodeset()

check() None

See hwloc_topology_check()

property cpuset: Bitmap

See hwloc_topology_get_topology_cpuset()

property depth: int

See hwloc_topology_get_depth()

destroy() None

Explicitly destroy the topology and free resources.

export_synthetic(flags: int | ExportSyntheticFlags | Sequence[ExportSyntheticFlags]) str

See hwloc_topology_export_synthetic()

export_xml_buffer(flags: int | ExportXmlFlags | Sequence[ExportXmlFlags] = 0) str

See hwloc_topology_export_xmlbuffer()

export_xml_file(path: PathLike | str, flags: int | ExportXmlFlags | Sequence[ExportXmlFlags] = 0) None

See hwloc_topology_export_xml()

classmethod from_pid(pid: int, *, load: bool = False) Topology

Create a topology from a specific process ID.

Parameters

pid

Process ID to get topology from

load :

Whether the object should load the topology from the system. Set to False if you want to apply additional filters.

Returns

New Topology instance for the specified process.

classmethod from_synthetic(description: str, *, load: bool = False) Topology

Create a topology from a synthetic description.

Parameters

description

Synthetic topology description (e.g., “node:2 core:2 pu:2”)

load :

Whether the object should load the topology from the system. Set to False if you want to apply additional filters.

Returns

New Topology instance from the synthetic description.

classmethod from_this_system(*, load: bool = False) Topology

Create a topology from this system.

Parameters

load :

Whether the object should load the topology from the system. Set to False if you want to apply additional filters.

Returns

New Topology instance for the specified process.

classmethod from_xml_buffer(xml_buffer: str, *, load: bool = False) Topology

Create a topology from a XML string.

Parameters

xml_buffer

XML string containing topology

load :

Whether the object should load the topology from the system. Set to False if you want to apply additional filters.

Returns

New Topology instance loaded from XML string.

classmethod from_xml_file(xml_path: PathLike | str, *, load: bool = False) Topology

Create a topology from a XML file.

Parameters

xml_path

Path to XML file containing topology

load :

Whether the object should load the topology from the system. Set to False if you want to apply additional filters.

Returns

New Topology instance loaded from XML file.

get_area_membind(mem: memoryview, flags: int | MemBindFlags | Sequence[MemBindFlags] = 0) tuple[Bitmap, MemBindPolicy]

Get memory area binding.

Parameters

mem

Memory area. Use memoryview_from_memory() to construct a memoryview if you have pointers.

flags

Flags for getting memory binding.

Returns

Tuple of (bitmap, policy) for memory area binding

get_cpubind(flags: int | CpuBindFlags | Sequence[CpuBindFlags] = 0) Bitmap

Get current process CPU binding.

Parameters

flags

Flags for getting CPU binding

Returns

Bitmap representing current CPU binding

get_cpukinds() CpuKinds

Get a proxy object for the CPU kinds.

get_depth_type(depth: int) ObjType

Get the object type at specific depth.

Parameters

depth

Depth level in topology tree

Returns

Object type at that depth

get_distances(kind: int | DistancesKind | Sequence[DistancesKind] = 0) list[Distances]

See hwloc_distances_get()

get_flags() int

See hwloc_topology_get_flags()

get_last_cpu_location(flags: int | CpuBindFlags | Sequence[CpuBindFlags] = 0) Bitmap

Get where current process last ran.

Parameters

flags

Flags for getting CPU location

Returns

Bitmap representing the cpuset where the process last ran.

get_memattrs() MemAttrs

Get a proxy object for the memory attributes.

get_membind(flags: int | MemBindFlags | Sequence[MemBindFlags] = 0) tuple[Bitmap, MemBindPolicy]

Get current process memory binding.

Parameters

flags

Flags for getting memory binding

Returns

Tuple of (bitmap, policy) for current memory binding

get_nbobjs_by_depth(depth: int) int

See hwloc_get_nbobjs_by_depth()

get_nbobjs_by_type(obj_type: ObjType) int

See hwloc_get_nbobjs_by_type()

get_numanode_obj_by_os_index(os_index: int) Object | None

See hwloc_get_numanode_obj_by_os_index()

get_obj_by_depth(depth: int, idx: int) Object | None

Get object at specific depth and index.

Parameters

depth

Depth level in topology tree

idx

Index of object at that depth

Returns

Object instance or None if not found

get_obj_by_type(obj_type: ObjType, idx: int) Object | None

See hwloc_get_obj_by_type()

get_proc_cpubind(pid: int, flags: int | CpuBindFlags | Sequence[CpuBindFlags] = 0) Bitmap

Get process CPU binding.

Parameters

pid

Process ID to query

flags

Flags for getting CPU binding

Returns

Bitmap representing process CPU binding

get_proc_last_cpu_location(pid: int, flags: int | CpuBindFlags | Sequence[CpuBindFlags] = 0) Bitmap

Get where specific process last ran.

Parameters

pid

Process ID to query. On Linux, pid can also be a thread ID if the flag is set to THREAD.

flags

Flags for getting CPU location

Returns

Bitmap representing the cpuset where process last ran

get_proc_membind(pid: int, flags: int | MemBindFlags | Sequence[MemBindFlags] = 0) tuple[Bitmap, MemBindPolicy]

Get process memory binding.

Parameters

pid

Process ID to query.

flags

Flags for getting memory binding.

Returns

Tuple of (nodeset, policy) for process memory binding

get_pu_obj_by_os_index(os_index: int) Object | None

See hwloc_get_pu_obj_by_os_index()

get_root_obj() Object

See hwloc_get_root_obj()

get_support() Any

See pyhwloc.hwloc.core.topology_get_support().

Returns

A namedtuple with the same structure as hwloc_topology_support.

get_thread_cpubind(thread_id: int, flags: int | CpuBindFlags | Sequence[CpuBindFlags] = 0) Bitmap

Get thread CPU binding.

Parameters

thread_id

Thread ID to query

flags

Flags for getting CPU binding

Returns

Bitmap representing thread CPU binding

property info: dict[str, str]

See hwloc_topology_get_infos()

property is_loaded: bool

Check if topology is loaded and ready for use.

is_this_system() bool

Check if topology represents the current system.

iter_all_breadth_first() Iterator[Object]

Iterate over all objects in the topology.

Yields

All object instances in breadth first order.

iter_bridges() Iterator[Bridge]

Iterate over all bridges.

Yields

All bridge instances.

iter_cores() Iterator[Object]

Iterate over all cores.

Yields

All core object instances

iter_cpus() Iterator[Object]

Iterate over all processing units (CPUs).

Yields

All PU (processing unit) object instances

iter_numa_nodes() Iterator[NumaNode]

Iterate over all NUMA nodes.

Yields

All NUMA node object instances

iter_objs_by_depth(depth: int) Iterator[Object]

Iterate over all objects at specific depth.

Parameters

depth

Depth level in topology tree

Yields

Object instances at that depth

iter_objs_by_type(obj_type: ObjType) Iterator[Object]

Iterate over all objects of specific type.

Parameters

obj_type

Type of object to iterate

Yields

Object instances of that type

iter_os_devices() Iterator[OsDevice]

Iterate over all OS devices.

Yields

All OS devices instances.

iter_packages() Iterator[Object]

Iterate over all packages (sockets).

Yields

All package object instances

iter_pci_devices() Iterator[PciDevice]

Iterate over all PCI devices.

Yields

All PCI device instances.

load() Topology

Load the topology. No-op if it’s already loaded

n_cores() int

Get the total number of cores.

Returns

Number of core objects in the topology

n_cpus() int

Get the total number of processing units (CPUs).

Returns

Number of PU objects in the topology

n_numa_nodes() int

Get the total number of NUMA nodes.

Returns

Number of NUMA node objects in the topology

n_os_devices() int

Get the total number of OS devices.

Returns

Number of OS device objects in the topology

n_packages() int

Get the total number of packages (sockets).

Returns

Number of package objects in the topology

n_pci_devices() int

Get the total number of PCI devices.

Returns

Number of PCI device objects in the topology

property native_handle: c_void_p

Get the native hwloc topology handle.

refresh() None

See hwloc_topology_refresh()

restrict(cpuset: Bitmap, flags: int | RestrictFlags | Sequence[RestrictFlags]) None

See hwloc_topology_restrict()

set_all_types_filter(type_filter: TypeFilter) Topology

See hwloc_topology_set_all_types_filter()

set_area_membind(mem: memoryview, target: Bitmap | set[int] | Object, policy: MemBindPolicy, flags: int | MemBindFlags | Sequence[MemBindFlags] = 0) None

Bind memory area to NUMA nodes.

Parameters

mem

Memory area. Use memoryview_from_memory() to construct a memoryview if you have pointers.

target

NUMA nodes to bind memory to. This can be an Object, a Bitmap, or a CPU set used by the os.sched_* routines (set [int]).

policy

Memory binding policy to use.

flags

Additional flags for memory binding.

set_cache_types_filter(type_filter: TypeFilter) Topology

See hwloc_topology_set_cache_types_filter()

set_components(name: str, flags: int | TopologyComponentsFlag | Sequence[TopologyComponentsFlag] = TopologyComponentsFlag.BLACKLIST) Topology

See hwloc_topology_set_components()

set_cpubind(target: Bitmap | set[int] | Object, flags: int | CpuBindFlags | Sequence[CpuBindFlags] = 0) None

Bind current process to specified CPUs.

Parameters

target

CPUs to bind the current process to. This can be an Object, a Bitmap, or a CPU set used by the os.sched_* routines (set [int]).

flags

Additional flags for CPU binding

set_flags(flags: int | TopologyFlags | Sequence[TopologyFlags]) Topology

See hwloc_topology_set_flags()

set_icache_types_filter(type_filter: TypeFilter) Topology

See hwloc_topology_set_icache_types_filter()

set_io_types_filter(type_filter: TypeFilter) Topology

See hwloc_topology_set_io_types_filter()

set_membind(target: Bitmap | set[int] | Object, policy: MemBindPolicy, flags: int | MemBindFlags | Sequence[MemBindFlags] = 0) None

Bind the current process memory to specified NUMA nodes. The current process is assumed to be single-threaded.

Parameters

target

NUMA nodes to bind memory to. This can be an Object, a Bitmap, or a CPU set used by the os.sched_* routines (set [int]).

policy

Memory binding policy to use

flags

Additional flags for memory binding.

set_proc_cpubind(pid: int, target: Bitmap | set[int] | Object, flags: int | CpuBindFlags | Sequence[CpuBindFlags] = 0) None

Bind specific process to CPUs.

Parameters

pid

Process ID to bind

target

CPUs to bind the current process to. This can be an Object, a Bitmap, or a CPU set used by the os.sched_* routines (set [int]).

flags

Additional flags for CPU binding

set_proc_membind(pid: int, target: Bitmap | set[int] | Object, policy: MemBindPolicy, flags: int | MemBindFlags | Sequence[MemBindFlags] = 0) None

Bind specific process memory to NUMA nodes.

Parameters

pid

Process ID to bind.

target

NUMA nodes to bind memory to. This can be an Object, a Bitmap, or a CPU set used by the os.sched_* routines (set [int]).

policy

Memory binding policy to use

flags

Additional flags for memory binding

set_thread_cpubind(thread_id: int, target: Bitmap | set[int] | Object, flags: int | CpuBindFlags | Sequence[CpuBindFlags] = 0) None

Bind specific thread to CPUs.

Parameters

thread_id

Thread ID to bind

target

CPUs to bind the current process to. This can be an Object, a Bitmap, or a CPU set used by the os.sched_* routines (set [int]).

flags

Additional flags for CPU binding

class pyhwloc.topology.TypeFilter(*values)

See hwloc_type_filter_e.

The Object Interface

Python interface of the hwloc_obj type.

class pyhwloc.hwobject.ObjType(*values)

See hwloc_obj_type_t.

class pyhwloc.hwobject.ObjOsdevType(*values)

See hwloc_obj_osdev_type_e.

class pyhwloc.hwobject.ObjBridgeType(*values)

See hwloc_obj_bridge_type_e.

class pyhwloc.hwobject.ObjSnprintfFlag(*values)

See hwloc_obj_snprintf_flag_e.

class pyhwloc.hwobject.GetTypeDepth(*values)

See hwloc_get_type_depth_e.

class pyhwloc.hwobject.ObjTypeCmp(*values)

Result from compare_types().

pyhwloc.hwobject.compare_types(type1: ObjType | Object, type2: ObjType | Object) ObjTypeCmp

See the relationship between two object types. If the returned enum is INCLUDE, it implies that type1 objects usually include type2 objects. The reverse is indicated by the INCLUDED_BY.

class pyhwloc.hwobject.Object(hdl: _core.ObjPtr, topology: _TopoRef)

High-level interface for the hwloc object. Only the topology can return objects. User should not use the constructor.

Parameters

hdl :

Raw pointer to hwloc object

add_info(name: str, value: str) None

See hwloc_obj_add_info()

property arity: int

Number of normal children.

property attr: Structure | None

Get attributes of this object. The return type depends on the type of this object as the underlying type is a C union hwloc_obj_attr_u. We have a number of methods for commonly used attributes like the is_normal(), but don’t have a proper wrapper for the entire union yet.

All pyhwloc structs can be properly printed in Python. To get an overview of the object attributes, you can print the result from this method, or use the format_attr().

property children: list[Object]

Normal children. Memory, Misc and I/O children are not listed here.

common_ancestor_obj(other: Object) Object

See hwloc_get_common_ancestor_obj()

property complete_cpuset: Bitmap | None

The complete CPU set of processors of this object.

property complete_nodeset: Bitmap | None

The complete NUMA node set of this object.

property cpuset: Bitmap | None

CPUs covered by this object.

property depth: int

Vertical index in the hierarchy.

property first_child: Object | None

First normal child.

format_attr(sep: str = ', ', flags: int | ObjSnprintfFlag | Sequence[ObjSnprintfFlag] = ObjSnprintfFlag.OLD_VERBOSE) str | None

Print the attributes.

get_ancestor_obj_by_depth(depth: int) Object | None

See hwloc_get_ancestor_obj_by_depth()

get_ancestor_obj_by_type(obj_type: ObjType) Object | None

See hwloc_get_ancestor_obj_by_type()

get_info_by_name(name: str) str | None

See hwloc_obj_get_info_by_name()

property gp_index: int

Global persistent index.

property info: dict[str, str]

Get the object info.

property io_arity: int

Number of I/O children.

property io_first_child: Object | None

First I/O child.

is_bridge() bool

Whether this object is a Bridge.

is_cache() bool

See hwloc_obj_type_is_cache()

is_dcache() bool

See hwloc_obj_type_is_dcache()

is_group() bool

Whether this object is a Group.

is_icache() bool

See hwloc_obj_type_is_icache()

is_in_subtree(subtree_root: Object) bool

See hwloc_obj_is_in_subtree()

is_io() bool

See hwloc_obj_type_is_io()

is_memory() bool

See hwloc_obj_type_is_memory()

is_normal() bool

See hwloc_obj_type_is_normal()

is_numa_node() bool

Whether this object is a NumaNode.

is_os_device() bool

Whether this object is a OsDevice.

is_pci_device() bool

Whether this object is a PciDevice.

iter_children() Iterator[Object]

Iterate over all children of this object.

iter_io_children() Iterator[Object]

Iterate over all I/O children of this object.

iter_memory_children() Iterator[Object]

Iterate over all memory children of this object.

iter_misc_children() Iterator[Object]

Iterate over all misc children of this object.

iter_siblings() Iterator[Object]

Iterate over all siblings of this object (including self).

property last_child: Object | None

Last normal child.

property logical_index: int

Horizontal index in the whole list of similar objects.

property memory_arity: int

Number of Memory children.

property memory_first_child: Object | None

First Memory child.

property misc_arity: int

Number of Misc children.

property misc_first_child: Object | None

First Misc child.

property name: str | None

Object-specific name if any.

property native_handle: _Pointer

Get the raw object pointer.

property next_cousin: Object | None

Next object of same type and depth.

property next_sibling: Object | None

Next object below the same parent.

property nodeset: Bitmap | None

NUMA nodes covered by this object or containing this object.

property os_index: int

OS-provided physical index number.

property parent: Object | None

Parent object, None if root (Machine object).

property prev_cousin: Object | None

Previous object of same type and depth.

property prev_sibling: Object | None

Previous object below the same parent.

property sibling_rank: int

Index in parent’s children array.

property subtype: str | None

Subtype string to better describe the type field.

property symmetric_subtree: bool

Set if the subtree of normal objects below this object is symmetric.

property total_memory: int

Total memory (in bytes) in NUMA nodes below this object.

property type: ObjType

Type of object.

class pyhwloc.hwobject.NumaNode(hdl: _core.ObjPtr, topology: _TopoRef)

NUMA node object.

class PageType(size: 'int', count: 'int')
add_info(name: str, value: str) None

See hwloc_obj_add_info()

property arity: int

Number of normal children.

property attr: NumanodeAttr

Return numa node attributes.

property children: list[Object]

Normal children. Memory, Misc and I/O children are not listed here.

common_ancestor_obj(other: Object) Object

See hwloc_get_common_ancestor_obj()

property complete_cpuset: Bitmap | None

The complete CPU set of processors of this object.

property complete_nodeset: Bitmap | None

The complete NUMA node set of this object.

property cpuset: Bitmap | None

CPUs covered by this object.

property depth: int

Vertical index in the hierarchy.

property first_child: Object | None

First normal child.

format_attr(sep: str = ', ', flags: int | ObjSnprintfFlag | Sequence[ObjSnprintfFlag] = ObjSnprintfFlag.OLD_VERBOSE) str | None

Print the attributes.

get_ancestor_obj_by_depth(depth: int) Object | None

See hwloc_get_ancestor_obj_by_depth()

get_ancestor_obj_by_type(obj_type: ObjType) Object | None

See hwloc_get_ancestor_obj_by_type()

get_info_by_name(name: str) str | None

See hwloc_obj_get_info_by_name()

property gp_index: int

Global persistent index.

property info: dict[str, str]

Get the object info.

property io_arity: int

Number of I/O children.

property io_first_child: Object | None

First I/O child.

is_bridge() bool

Whether this object is a Bridge.

is_cache() bool

See hwloc_obj_type_is_cache()

is_dcache() bool

See hwloc_obj_type_is_dcache()

is_group() bool

Whether this object is a Group.

is_icache() bool

See hwloc_obj_type_is_icache()

is_in_subtree(subtree_root: Object) bool

See hwloc_obj_is_in_subtree()

is_io() bool

See hwloc_obj_type_is_io()

is_memory() bool

See hwloc_obj_type_is_memory()

is_normal() bool

See hwloc_obj_type_is_normal()

is_numa_node() bool

Whether this object is a NumaNode.

is_os_device() bool

Whether this object is a OsDevice.

is_pci_device() bool

Whether this object is a PciDevice.

iter_children() Iterator[Object]

Iterate over all children of this object.

iter_io_children() Iterator[Object]

Iterate over all I/O children of this object.

iter_memory_children() Iterator[Object]

Iterate over all memory children of this object.

iter_misc_children() Iterator[Object]

Iterate over all misc children of this object.

iter_siblings() Iterator[Object]

Iterate over all siblings of this object (including self).

property last_child: Object | None

Last normal child.

property local_memory: int

Local memory (in bytes).

property logical_index: int

Horizontal index in the whole list of similar objects.

property memory_arity: int

Number of Memory children.

property memory_first_child: Object | None

First Memory child.

property misc_arity: int

Number of Misc children.

property misc_first_child: Object | None

First Misc child.

property name: str | None

Object-specific name if any.

property native_handle: _Pointer

Get the raw object pointer.

property next_cousin: Object | None

Next object of same type and depth.

property next_sibling: Object | None

Next object below the same parent.

property nodeset: Bitmap | None

NUMA nodes covered by this object or containing this object.

property os_index: int

OS-provided physical index number.

property page_types: list[PageType]

List of local memory page types.

property parent: Object | None

Parent object, None if root (Machine object).

property prev_cousin: Object | None

Previous object of same type and depth.

property prev_sibling: Object | None

Previous object below the same parent.

property sibling_rank: int

Index in parent’s children array.

property subtype: str | None

Subtype string to better describe the type field.

property symmetric_subtree: bool

Set if the subtree of normal objects below this object is symmetric.

property total_memory: int

Total memory (in bytes) in NUMA nodes below this object.

property type: ObjType

Type of object.

class pyhwloc.hwobject.Cache(hdl: _core.ObjPtr, topology: _TopoRef)

Cache Object.

add_info(name: str, value: str) None

See hwloc_obj_add_info()

property arity: int

Number of normal children.

property associativity: int

Ways of associativity, -1 if fully associative, 0 if unknown.

property attr: CacheAttr

Return cache attributes.

property cache_depth: int

Depth of cache (e.g., L1, L2, …etc.).

property cache_type: int

Cache type.

property children: list[Object]

Normal children. Memory, Misc and I/O children are not listed here.

common_ancestor_obj(other: Object) Object

See hwloc_get_common_ancestor_obj()

property complete_cpuset: Bitmap | None

The complete CPU set of processors of this object.

property complete_nodeset: Bitmap | None

The complete NUMA node set of this object.

property cpuset: Bitmap | None

CPUs covered by this object.

property depth: int

Vertical index in the hierarchy.

property first_child: Object | None

First normal child.

format_attr(sep: str = ', ', flags: int | ObjSnprintfFlag | Sequence[ObjSnprintfFlag] = ObjSnprintfFlag.OLD_VERBOSE) str | None

Print the attributes.

get_ancestor_obj_by_depth(depth: int) Object | None

See hwloc_get_ancestor_obj_by_depth()

get_ancestor_obj_by_type(obj_type: ObjType) Object | None

See hwloc_get_ancestor_obj_by_type()

get_info_by_name(name: str) str | None

See hwloc_obj_get_info_by_name()

property gp_index: int

Global persistent index.

property info: dict[str, str]

Get the object info.

property io_arity: int

Number of I/O children.

property io_first_child: Object | None

First I/O child.

is_bridge() bool

Whether this object is a Bridge.

is_cache() bool

See hwloc_obj_type_is_cache()

is_dcache() bool

See hwloc_obj_type_is_dcache()

is_group() bool

Whether this object is a Group.

is_icache() bool

See hwloc_obj_type_is_icache()

is_in_subtree(subtree_root: Object) bool

See hwloc_obj_is_in_subtree()

is_io() bool

See hwloc_obj_type_is_io()

is_memory() bool

See hwloc_obj_type_is_memory()

is_normal() bool

See hwloc_obj_type_is_normal()

is_numa_node() bool

Whether this object is a NumaNode.

is_os_device() bool

Whether this object is a OsDevice.

is_pci_device() bool

Whether this object is a PciDevice.

iter_children() Iterator[Object]

Iterate over all children of this object.

iter_io_children() Iterator[Object]

Iterate over all I/O children of this object.

iter_memory_children() Iterator[Object]

Iterate over all memory children of this object.

iter_misc_children() Iterator[Object]

Iterate over all misc children of this object.

iter_siblings() Iterator[Object]

Iterate over all siblings of this object (including self).

property last_child: Object | None

Last normal child.

property linesize: int

Cache-line size in bytes. 0 if unknown.

property logical_index: int

Horizontal index in the whole list of similar objects.

property memory_arity: int

Number of Memory children.

property memory_first_child: Object | None

First Memory child.

property misc_arity: int

Number of Misc children.

property misc_first_child: Object | None

First Misc child.

property name: str | None

Object-specific name if any.

property native_handle: _Pointer

Get the raw object pointer.

property next_cousin: Object | None

Next object of same type and depth.

property next_sibling: Object | None

Next object below the same parent.

property nodeset: Bitmap | None

NUMA nodes covered by this object or containing this object.

property os_index: int

OS-provided physical index number.

property parent: Object | None

Parent object, None if root (Machine object).

property prev_cousin: Object | None

Previous object of same type and depth.

property prev_sibling: Object | None

Previous object below the same parent.

property sibling_rank: int

Index in parent’s children array.

property size: int

Size of cache in bytes.

property subtype: str | None

Subtype string to better describe the type field.

property symmetric_subtree: bool

Set if the subtree of normal objects below this object is symmetric.

property total_memory: int

Total memory (in bytes) in NUMA nodes below this object.

property type: ObjType

Type of object.

class pyhwloc.hwobject.Group(hdl: _core.ObjPtr, topology: _TopoRef)

Object with type == GROUP.

add_info(name: str, value: str) None

See hwloc_obj_add_info()

property arity: int

Number of normal children.

property attr: GroupAttr

Return group attributes.

property children: list[Object]

Normal children. Memory, Misc and I/O children are not listed here.

common_ancestor_obj(other: Object) Object

See hwloc_get_common_ancestor_obj()

property complete_cpuset: Bitmap | None

The complete CPU set of processors of this object.

property complete_nodeset: Bitmap | None

The complete NUMA node set of this object.

property cpuset: Bitmap | None

CPUs covered by this object.

property depth: int

Vertical index in the hierarchy.

property first_child: Object | None

First normal child.

format_attr(sep: str = ', ', flags: int | ObjSnprintfFlag | Sequence[ObjSnprintfFlag] = ObjSnprintfFlag.OLD_VERBOSE) str | None

Print the attributes.

get_ancestor_obj_by_depth(depth: int) Object | None

See hwloc_get_ancestor_obj_by_depth()

get_ancestor_obj_by_type(obj_type: ObjType) Object | None

See hwloc_get_ancestor_obj_by_type()

get_info_by_name(name: str) str | None

See hwloc_obj_get_info_by_name()

property gp_index: int

Global persistent index.

property group_depth: int

Depth of group object.

property info: dict[str, str]

Get the object info.

property io_arity: int

Number of I/O children.

property io_first_child: Object | None

First I/O child.

is_bridge() bool

Whether this object is a Bridge.

is_cache() bool

See hwloc_obj_type_is_cache()

is_dcache() bool

See hwloc_obj_type_is_dcache()

is_group() bool

Whether this object is a Group.

is_icache() bool

See hwloc_obj_type_is_icache()

is_in_subtree(subtree_root: Object) bool

See hwloc_obj_is_in_subtree()

is_io() bool

See hwloc_obj_type_is_io()

is_memory() bool

See hwloc_obj_type_is_memory()

is_normal() bool

See hwloc_obj_type_is_normal()

is_numa_node() bool

Whether this object is a NumaNode.

is_os_device() bool

Whether this object is a OsDevice.

is_pci_device() bool

Whether this object is a PciDevice.

iter_children() Iterator[Object]

Iterate over all children of this object.

iter_io_children() Iterator[Object]

Iterate over all I/O children of this object.

iter_memory_children() Iterator[Object]

Iterate over all memory children of this object.

iter_misc_children() Iterator[Object]

Iterate over all misc children of this object.

iter_siblings() Iterator[Object]

Iterate over all siblings of this object (including self).

property last_child: Object | None

Last normal child.

property logical_index: int

Horizontal index in the whole list of similar objects.

property memory_arity: int

Number of Memory children.

property memory_first_child: Object | None

First Memory child.

property misc_arity: int

Number of Misc children.

property misc_first_child: Object | None

First Misc child.

property name: str | None

Object-specific name if any.

property native_handle: _Pointer

Get the raw object pointer.

property next_cousin: Object | None

Next object of same type and depth.

property next_sibling: Object | None

Next object below the same parent.

property nodeset: Bitmap | None

NUMA nodes covered by this object or containing this object.

property os_index: int

OS-provided physical index number.

property parent: Object | None

Parent object, None if root (Machine object).

property prev_cousin: Object | None

Previous object of same type and depth.

property prev_sibling: Object | None

Previous object below the same parent.

property sibling_rank: int

Index in parent’s children array.

property subtype: str | None

Subtype string to better describe the type field.

property symmetric_subtree: bool

Set if the subtree of normal objects below this object is symmetric.

property total_memory: int

Total memory (in bytes) in NUMA nodes below this object.

property type: ObjType

Type of object.

class pyhwloc.hwobject.PciDevice(hdl: _core.ObjPtr, topology: _TopoRef)

Object with type == PCI_DEVICE.

add_info(name: str, value: str) None

See hwloc_obj_add_info()

property arity: int

Number of normal children.

property attr: PcidevAttr

Return PCI device attributes.

property base_class: int

The base class number

property children: list[Object]

Normal children. Memory, Misc and I/O children are not listed here.

common_ancestor_obj(other: Object) Object

See hwloc_get_common_ancestor_obj()

property complete_cpuset: Bitmap | None

The complete CPU set of processors of this object.

property complete_nodeset: Bitmap | None

The complete NUMA node set of this object.

property cpuset: Bitmap | None

CPUs covered by this object.

property depth: int

Vertical index in the hierarchy.

property device_id: int

Device ID (yyyy in [xxxx:yyyy]).

property first_child: Object | None

First normal child.

format_attr(sep: str = ', ', flags: int | ObjSnprintfFlag | Sequence[ObjSnprintfFlag] = ObjSnprintfFlag.OLD_VERBOSE) str | None

Print the attributes.

property func: int

Function number (t in the PCI BDF notation xxxx:yy:zz.t).

get_ancestor_obj_by_depth(depth: int) Object | None

See hwloc_get_ancestor_obj_by_depth()

get_ancestor_obj_by_type(obj_type: ObjType) Object | None

See hwloc_get_ancestor_obj_by_type()

get_info_by_name(name: str) str | None

See hwloc_obj_get_info_by_name()

property gp_index: int

Global persistent index.

property info: dict[str, str]

Get the object info.

property io_arity: int

Number of I/O children.

property io_first_child: Object | None

First I/O child.

is_bridge() bool

Whether this object is a Bridge.

is_cache() bool

See hwloc_obj_type_is_cache()

is_dcache() bool

See hwloc_obj_type_is_dcache()

is_group() bool

Whether this object is a Group.

is_icache() bool

See hwloc_obj_type_is_icache()

is_in_subtree(subtree_root: Object) bool

See hwloc_obj_is_in_subtree()

is_io() bool

See hwloc_obj_type_is_io()

is_memory() bool

See hwloc_obj_type_is_memory()

is_normal() bool

See hwloc_obj_type_is_normal()

is_numa_node() bool

Whether this object is a NumaNode.

is_os_device() bool

Whether this object is a OsDevice.

is_pci_device() bool

Whether this object is a PciDevice.

iter_children() Iterator[Object]

Iterate over all children of this object.

iter_io_children() Iterator[Object]

Iterate over all I/O children of this object.

iter_memory_children() Iterator[Object]

Iterate over all memory children of this object.

iter_misc_children() Iterator[Object]

Iterate over all misc children of this object.

iter_siblings() Iterator[Object]

Iterate over all siblings of this object (including self).

property last_child: Object | None

Last normal child.

property linkspeed: float

Link speed in GB/s.

property logical_index: int

Horizontal index in the whole list of similar objects.

property memory_arity: int

Number of Memory children.

property memory_first_child: Object | None

First Memory child.

property misc_arity: int

Number of Misc children.

property misc_first_child: Object | None

First Misc child.

property name: str | None

Object-specific name if any.

property native_handle: _Pointer

Get the raw object pointer.

property next_cousin: Object | None

Next object of same type and depth.

property next_sibling: Object | None

Next object below the same parent.

property nodeset: Bitmap | None

NUMA nodes covered by this object or containing this object.

property os_index: int

OS-provided physical index number.

property parent: Object | None

Parent object, None if root (Machine object).

property pci_id: PciId

Domain, bus, dev.

property prev_cousin: Object | None

Previous object of same type and depth.

property prev_sibling: Object | None

Previous object below the same parent.

property prog_if: int

Register-level programming interface number (3rd byte of the class).

property revision: int

Revision number.

property sibling_rank: int

Index in parent’s children array.

property subclass: int

The sub-class number

property subdevice_id: int

Sub-Device ID.

property subtype: str | None

Subtype string to better describe the type field.

property subvendor_id: int

Sub-Vendor ID.

property symmetric_subtree: bool

Set if the subtree of normal objects below this object is symmetric.

property total_memory: int

Total memory (in bytes) in NUMA nodes below this object.

property type: ObjType

Type of object.

property vendor_id: int

Vendor ID (xxxx in [xxxx:yyyy]).

class pyhwloc.hwobject.Bridge(hdl: _core.ObjPtr, topology: _TopoRef)

Object with type == BRIDGE.

add_info(name: str, value: str) None

See hwloc_obj_add_info()

property arity: int

Number of normal children.

property attr: BridgeAttr

Return bridge attributes.

property children: list[Object]

Normal children. Memory, Misc and I/O children are not listed here.

common_ancestor_obj(other: Object) Object

See hwloc_get_common_ancestor_obj()

property complete_cpuset: Bitmap | None

The complete CPU set of processors of this object.

property complete_nodeset: Bitmap | None

The complete NUMA node set of this object.

property cpuset: Bitmap | None

CPUs covered by this object.

property depth: int

Vertical index in the hierarchy.

property downstream_pci: BridgeDownstreamPci

PCI attribute of the downstream part as a PCI device.

downstream_type() ObjBridgeType

Downstream Bridge type

property first_child: Object | None

First normal child.

format_attr(sep: str = ', ', flags: int | ObjSnprintfFlag | Sequence[ObjSnprintfFlag] = ObjSnprintfFlag.OLD_VERBOSE) str | None

Print the attributes.

get_ancestor_obj_by_depth(depth: int) Object | None

See hwloc_get_ancestor_obj_by_depth()

get_ancestor_obj_by_type(obj_type: ObjType) Object | None

See hwloc_get_ancestor_obj_by_type()

get_info_by_name(name: str) str | None

See hwloc_obj_get_info_by_name()

property gp_index: int

Global persistent index.

property info: dict[str, str]

Get the object info.

property io_arity: int

Number of I/O children.

property io_first_child: Object | None

First I/O child.

is_bridge() bool

Whether this object is a Bridge.

is_cache() bool

See hwloc_obj_type_is_cache()

is_dcache() bool

See hwloc_obj_type_is_dcache()

is_group() bool

Whether this object is a Group.

is_icache() bool

See hwloc_obj_type_is_icache()

is_in_subtree(subtree_root: Object) bool

See hwloc_obj_is_in_subtree()

is_io() bool

See hwloc_obj_type_is_io()

is_memory() bool

See hwloc_obj_type_is_memory()

is_normal() bool

See hwloc_obj_type_is_normal()

is_numa_node() bool

Whether this object is a NumaNode.

is_os_device() bool

Whether this object is a OsDevice.

is_pci_device() bool

Whether this object is a PciDevice.

iter_children() Iterator[Object]

Iterate over all children of this object.

iter_io_children() Iterator[Object]

Iterate over all I/O children of this object.

iter_memory_children() Iterator[Object]

Iterate over all memory children of this object.

iter_misc_children() Iterator[Object]

Iterate over all misc children of this object.

iter_siblings() Iterator[Object]

Iterate over all siblings of this object (including self).

property last_child: Object | None

Last normal child.

property logical_index: int

Horizontal index in the whole list of similar objects.

property memory_arity: int

Number of Memory children.

property memory_first_child: Object | None

First Memory child.

property misc_arity: int

Number of Misc children.

property misc_first_child: Object | None

First Misc child.

property name: str | None

Object-specific name if any.

property native_handle: _Pointer

Get the raw object pointer.

property next_cousin: Object | None

Next object of same type and depth.

property next_sibling: Object | None

Next object below the same parent.

property nodeset: Bitmap | None

NUMA nodes covered by this object or containing this object.

property os_index: int

OS-provided physical index number.

property parent: Object | None

Parent object, None if root (Machine object).

property prev_cousin: Object | None

Previous object of same type and depth.

property prev_sibling: Object | None

Previous object below the same parent.

property sibling_rank: int

Index in parent’s children array.

property subtype: str | None

Subtype string to better describe the type field.

property symmetric_subtree: bool

Set if the subtree of normal objects below this object is symmetric.

property total_memory: int

Total memory (in bytes) in NUMA nodes below this object.

property type: ObjType

Type of object.

property upstream_pci: PciDevAttr

PCI attribute of the upstream part as a PCI device.

property upstream_type: ObjBridgeType

Upstream Bridge type.

class pyhwloc.hwobject.OsDevice(hdl: _core.ObjPtr, topology: _TopoRef)

Object with type == OS_DEVICE.

add_info(name: str, value: str) None

See hwloc_obj_add_info()

property arity: int

Number of normal children.

property attr: OsdevAttr

Return OS device attributes.

property children: list[Object]

Normal children. Memory, Misc and I/O children are not listed here.

common_ancestor_obj(other: Object) Object

See hwloc_get_common_ancestor_obj()

property complete_cpuset: Bitmap | None

The complete CPU set of processors of this object.

property complete_nodeset: Bitmap | None

The complete NUMA node set of this object.

property cpuset: Bitmap | None

CPUs covered by this object.

property depth: int

Vertical index in the hierarchy.

property first_child: Object | None

First normal child.

format_attr(sep: str = ', ', flags: int | ObjSnprintfFlag | Sequence[ObjSnprintfFlag] = ObjSnprintfFlag.OLD_VERBOSE) str | None

Print the attributes.

get_ancestor_obj_by_depth(depth: int) Object | None

See hwloc_get_ancestor_obj_by_depth()

get_ancestor_obj_by_type(obj_type: ObjType) Object | None

See hwloc_get_ancestor_obj_by_type()

get_info_by_name(name: str) str | None

See hwloc_obj_get_info_by_name()

property gp_index: int

Global persistent index.

property info: dict[str, str]

Get the object info.

property io_arity: int

Number of I/O children.

property io_first_child: Object | None

First I/O child.

is_bridge() bool

Whether this object is a Bridge.

is_cache() bool

See hwloc_obj_type_is_cache()

is_coproc() bool

Types include the ObjOsdevType.COPROC.

is_dcache() bool

See hwloc_obj_type_is_dcache()

is_gpu() bool

Types include the ObjOsdevType.GPU.

is_group() bool

Whether this object is a Group.

is_icache() bool

See hwloc_obj_type_is_icache()

is_in_subtree(subtree_root: Object) bool

See hwloc_obj_is_in_subtree()

is_io() bool

See hwloc_obj_type_is_io()

is_memory() bool

See hwloc_obj_type_is_memory()

is_normal() bool

See hwloc_obj_type_is_normal()

is_numa_node() bool

Whether this object is a NumaNode.

is_os_device() bool

Whether this object is a OsDevice.

is_osdev_type(typ: int) bool

Check type of the OS device.

is_pci_device() bool

Whether this object is a PciDevice.

is_storage() bool

Types include the ObjOsdevType.STORAGE.

iter_children() Iterator[Object]

Iterate over all children of this object.

iter_io_children() Iterator[Object]

Iterate over all I/O children of this object.

iter_memory_children() Iterator[Object]

Iterate over all memory children of this object.

iter_misc_children() Iterator[Object]

Iterate over all misc children of this object.

iter_siblings() Iterator[Object]

Iterate over all siblings of this object (including self).

property last_child: Object | None

Last normal child.

property logical_index: int

Horizontal index in the whole list of similar objects.

property memory_arity: int

Number of Memory children.

property memory_first_child: Object | None

First Memory child.

property misc_arity: int

Number of Misc children.

property misc_first_child: Object | None

First Misc child.

property name: str | None

Object-specific name if any.

property native_handle: _Pointer

Get the raw object pointer.

property next_cousin: Object | None

Next object of same type and depth.

property next_sibling: Object | None

Next object below the same parent.

property nodeset: Bitmap | None

NUMA nodes covered by this object or containing this object.

property os_index: int

OS-provided physical index number.

property parent: Object | None

Parent object, None if root (Machine object).

property prev_cousin: Object | None

Previous object of same type and depth.

property prev_sibling: Object | None

Previous object below the same parent.

property sibling_rank: int

Index in parent’s children array.

property subtype: str | None

Subtype string to better describe the type field.

property symmetric_subtree: bool

Set if the subtree of normal objects below this object is symmetric.

property total_memory: int

Total memory (in bytes) in NUMA nodes below this object.

property type: ObjType

Type of object.

Distance Matrix

This module provides wrappers around hwloc distance matrices.

See Topology Attributes: Distances, Memory Attributes and CPU Kinds for an introduction to the basic concepts.

class pyhwloc.distances.Distances(hdl: _core.DistancesPtr, topo: _TopoRef)

High-level interface for hwloc distance matrix. Users can index the Distances class like a matrix:

from pyhwloc import from_this_system

with from_this_system() as topo:
    dist = topo.get_disances()
    d = dist[0, 1]
__getitem__(key: tuple[int | Object, int | Object]) float

Get distance value by matrix coordinates or objects.

Parameters

key

Matrix coordinates (i, j), or an object pair.

Returns

Distance value

find_object_index(obj: Object) int

See hwloc_distances_obj_index()

get_distance(obj1: Object, obj2: Object) tuple[float, float]

See hwloc_distances_obj_pair_values()

property name: str | None

See hwloc_distances_get_name()

property nbobjs: int

Number of objects in this distance matrix.

property objects: list[Object]

List of objects in this distance matrix.

property shape: tuple[int, int]

Shape of the distance matrix (nbobjs, nbobjs).

CPU Kinds

CPU Kinds is a structure inside the topology. The Python interface implements it as an independent class.

class pyhwloc.cpukinds.CpuKinds(topology: _TopoRef)

Represents the CPU kinds in hwloc. Use the get_cpukinds() to obtain an instance of this class.

get_info(kind_index: int) tuple[Bitmap, int, dict[str, str]]

See hwloc_cpukinds_get_info()

get_kind_by_cpuset(cpuset: Bitmap) int

See hwloc_cpukinds_get_by_cpuset()

n_kinds() int

See hwloc_cpukinds_get_nr()

register(cpuset: Bitmap, forced_efficiency: int, infos: dict[str, str] = {}) None

See hwloc_cpukinds_register()

Memory Attributes

This module provides high-level interfaces for hwloc memory attributes.

class pyhwloc.memattrs.LocalNumaNodeFlag(*values)

See hwloc_local_numanode_flag_e.

class pyhwloc.memattrs.MemAttr(attr_id: _core.hwloc_memattr_id_t, topo: _TopoRef)

High-level interface for a single memory attribute.

Memory attributes describe characteristics like bandwidth, latency, or capacity of memory nodes. This class provides methods to query values and find optimal targets or initiators for memory operations.

property flags: int

See hwloc_memattr_get_flags()

get_best_initiator(target_node: Object) tuple[Object | Bitmap, int]

See hwloc_memattr_get_best_initiator()

get_best_target(initiator: Object | Bitmap | set[int] | None = None) tuple[Object, int]

See hwloc_memattr_get_best_target()

get_initiators(target_node: Object) list[tuple[Object | Bitmap, int]]

See hwloc_memattr_get_initiators()

get_targets(initiator: Object | Bitmap | set[int] | None = None) list[tuple[Object, int]]

See hwloc_memattr_get_targets()

get_value(target_node: Object, initiator: Object | Bitmap | set[int] | None = None) int

See hwloc_memattr_get_value()

property higher_first: bool

The best nodes for this memory attribute are those with the higher values. For instance Bandwidth.

property lower_first: bool

The best nodes for this memory attribute are those with the lower values. For instance Latency.

property name: str

See hwloc_memattr_get_name()

property native_handle: c_uint

The memory attribute ID.

property needs_initiator: bool

The value returned for this memory attribute depends on the given initiator. For instance Bandwidth and Latency, but not Capacity.

set_value(target_node: Object, value: int, initiator: Object | Bitmap | set[int] | None = None) None

See hwloc_memattr_set_value()

class pyhwloc.memattrs.MemAttrFlag(*values)

See hwloc_memattr_flag_e.

class pyhwloc.memattrs.MemAttrId(*values)

See hwloc_memattr_id_e.

class pyhwloc.memattrs.MemAttrs(topo: _TopoRef)

Accessor for memory attributes.

get(identifier: str | int | MemAttrId) MemAttr

Get a memory attribute by name or ID.

get_local_numa_nodes(initiator: Object | Bitmap | set[int], flags: int | LocalNumaNodeFlag | Sequence[LocalNumaNodeFlag] = 0) list[Object]

See hwloc_get_local_numanode_objs()

register(name: str, flags: int | MemAttrFlag | Sequence[MemAttrFlag] = 0) MemAttr

See hwloc_memattr_register()

Interoperability with the CUDA Runtime API

class pyhwloc.cuda_runtime.Device

Class to represent a CUDA runtime device. This class can be created using the get_device().

from pyhwloc.topology import Topology, TypeFilter
from pyhwloc.cuda_runtime import get_device

with Topology.from_this_system().set_io_types_filter(
    TypeFilter.KEEP_ALL
) as topo:
    ordinal = 0  # The first CUDA runtime device.
    dev = get_device(topo, ordinal)
    print(dev.get_affinity())  # CPU affinity
    print(dev.pci_id)  # PCI information
    # Get the hwloc object
    osdev = dev.get_osdev()
classmethod from_idx(topo: _TopoRef, idx: int) Device

Create Device from CUDA ordinal.

get_affinity() Bitmap

See hwloc_cudart_get_device_cpuset()

get_osdev() OsDevice | None

See hwloc_cudart_get_device_osdev_by_index()

get_pcidev() PciDevice | None

See hwloc_cudart_get_device_pcidev()

property index: int

Device ordinal.

property pci_id: PciId

See hwloc_cudart_get_device_pci_ids()

pyhwloc.cuda_runtime.get_device(topology: Topology, device: int) Device

Get the CUDA device from its ordinal.

Parameters

topology :

Hwloc topology, loaded with OS devices.

device :

Device ordinal.

Interoperability with the NVIDIA Management Library (NVML)

class pyhwloc.nvml.Device

Class to represent an NVML device. This class can be created using the get_device().

from pyhwloc.topology import Topology, TypeFilter
from pyhwloc.nvml import get_device
import pynvml

with Topology.from_this_system().set_io_types_filter(
    TypeFilter.KEEP_ALL
) as topo:
    # Initialize NVML
    pynvml.nvmlInit()
    try:
        # Get the first NVML device
        nvml_hdl = pynvml.nvmlDeviceGetHandleByIndex(0)
        dev = get_device(topo, nvml_hdl)
        print(dev.get_affinity())  # CPU affinity
        # Get the hwloc object
        osdev = dev.get_osdev()
    finally:
        pynvml.nvmlShutdown()
classmethod from_idx(topo: _TopoRef, idx: int) Device

Create Device from NVML device ordinal.

classmethod from_native_handle(topo: _TopoRef, hdl: ctypes._Pointer) Device

Create Device from NVML handle and index.

Parameters

topo :

Weak reference to the topology

hdl :

NVML device handle from pynvml

get_affinity() Bitmap

See hwloc_nvml_get_device_cpuset()

get_osdev() OsDevice | None

See hwloc_nvml_get_device_osdev()

property index: int

Device ordinal.

property native_handle: _Pointer

Obtain the NVML’s native device handle.

pyhwloc.nvml.get_cpu_affinity(device: int | str) Bitmap

Get optimal affinity using nvml directly. This should produce the same result as pyhwloc.nvml.Device.get_affinity().

Parameters

device :

Either the UUID of the device or a CUDA runtime ordinal.

pyhwloc.nvml.get_device(topology: Topology, device: int | _Pointer) Device

Get the NVML device from its handle or ordinal.

Parameters

topology :

Hwloc topology, loaded with OS devices.

device :

Either the device ordinal or the nvmlDevice

Interoperability with the CUDA Driver API

class pyhwloc.cuda_driver.Device

Class to represent a CUDA driver device. This class can be created using the get_device().

from pyhwloc.topology import Topology, TypeFilter
from pyhwloc.cuda_driver import get_device
import cuda.bindings.driver as cuda

with Topology.from_this_system().set_io_types_filter(
    TypeFilter.KEEP_ALL
) as topo:
    # Get the first CUDA device
    status, cu_device = cuda.cuDeviceGet(0)
    dev = get_device(topo, cu_device)
    print(dev.get_affinity())  # CPU affinity
    print(dev.pci_id)  # PCI information
    # Get the hwloc objects
    pcidev = dev.get_pcidev()
    osdev = dev.get_osdev()
classmethod from_idx(topo: _TopoRef, idx: int) Device

Create Device from the CUDA driver ordinal.

classmethod from_native_handle(topo: _TopoRef, device: CUdevice) Device

Create Device from CUDA driver device.

Parameters

topo :

Weak reference to the topology

device :

CUdevice handle from CUDA driver API

get_affinity() Bitmap

See hwloc_cuda_get_device_cpuset()

get_osdev() OsDevice | None

See hwloc_cuda_get_device_osdev()

get_pcidev() PciDevice | None

See hwloc_cuda_get_device_pcidev()

property pci_id: PciId

See hwloc_cuda_get_device_pci_ids()

pyhwloc.cuda_driver.get_device(topology: Topology, device: int | CUdevice) Device

Get the CUDA driver device from its CUdevice handle or ordinal.

Parameters

topology :

Hardware topology, loaded with OS devices

device :

CUdevice handle from CUDA driver API or device ordinal.

Utilities

class pyhwloc.utils.PciId(domain: 'int', bus: 'int', dev: 'int')
pyhwloc.utils.memoryview_from_memory(ptr: c_void_p, size: int, read_only: bool) memoryview

Create a Python memoryview from a ctypes pointer.

Parameters

ptr :

A ctypes Pointer.

size :

Size in bytes.

read_only :

Do we need write access to the memory view?

Returns

A Python memoryview object.