---
name: "hwlocality_levels"
section: "3"
platform: "linux"
package: "hwloc"
version: "2.15.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/hwlocality_levels"
---

# hwlocality\_levels(3)

Object levels, depths and types

## NAME

hwlocality\_levels - Object levels, depths and types

## SYNOPSIS

### Enumerations

enum **hwloc\_get\_type\_depth\_e** { **HWLOC\_TYPE\_DEPTH\_UNKNOWN**, **HWLOC\_TYPE\_DEPTH\_MULTIPLE**, **HWLOC\_TYPE\_DEPTH\_NUMANODE**, **HWLOC\_TYPE\_DEPTH\_BRIDGE**, **HWLOC\_TYPE\_DEPTH\_PCI\_DEVICE**, **HWLOC\_TYPE\_DEPTH\_OS\_DEVICE**, **HWLOC\_TYPE\_DEPTH\_MISC**, **HWLOC\_TYPE\_DEPTH\_MEMCACHE** }\

### Functions

int **hwloc\_topology\_get\_depth** (**hwloc\_topology\_t** restrict topology)\
 int **hwloc\_get\_type\_depth** (**hwloc\_topology\_t** topology, **hwloc\_obj\_type\_t** type)\
 int **hwloc\_get\_memory\_parents\_depth** (**hwloc\_topology\_t** topology)\
 int **hwloc\_get\_type\_or\_below\_depth** (**hwloc\_topology\_t** topology, **hwloc\_obj\_type\_t** type)\
 int **hwloc\_get\_type\_or\_above\_depth** (**hwloc\_topology\_t** topology, **hwloc\_obj\_type\_t** type)\
 **hwloc\_obj\_type\_t** **hwloc\_get\_depth\_type** (**hwloc\_topology\_t** topology, int depth)\
 unsigned **hwloc\_get\_nbobjs\_by\_depth** (**hwloc\_topology\_t** topology, int depth)\
 int **hwloc\_get\_nbobjs\_by\_type** (**hwloc\_topology\_t** topology, **hwloc\_obj\_type\_t** type)\
 **hwloc\_obj\_t** **hwloc\_get\_root\_obj** (**hwloc\_topology\_t** topology)\
 **hwloc\_obj\_t** **hwloc\_get\_obj\_by\_depth** (**hwloc\_topology\_t** topology, int depth, unsigned idx)\
 **hwloc\_obj\_t** **hwloc\_get\_obj\_by\_type** (**hwloc\_topology\_t** topology, **hwloc\_obj\_type\_t** type, unsigned idx)\
 **hwloc\_obj\_t** **hwloc\_get\_next\_obj\_by\_depth** (**hwloc\_topology\_t** topology, int depth, **hwloc\_obj\_t** prev)\
 **hwloc\_obj\_t** **hwloc\_get\_next\_obj\_by\_type** (**hwloc\_topology\_t** topology, **hwloc\_obj\_type\_t** type, **hwloc\_obj\_t** prev)\

## Detailed Description

Be sure to see the figure in **Terms and Definitions** that shows a complete topology tree, including depths, child/sibling/cousin relationships, and an example of an asymmetric topology where one package has fewer caches than its peers.

## Enumeration Type Documentation

### enum hwloc\_get\_type\_depth\_e

**Enumerator**

- ***HWLOC\_TYPE\_DEPTH\_UNKNOWN***

  No object of given type exists in the topology.

- ***HWLOC\_TYPE\_DEPTH\_MULTIPLE***

  Objects of given type exist at different depth in the topology (only for Groups).

- ***HWLOC\_TYPE\_DEPTH\_NUMANODE***

  Virtual depth for NUMA nodes.

- ***HWLOC\_TYPE\_DEPTH\_BRIDGE***

  Virtual depth for bridge object level.

- ***HWLOC\_TYPE\_DEPTH\_PCI\_DEVICE***

  Virtual depth for PCI device object level.

- ***HWLOC\_TYPE\_DEPTH\_OS\_DEVICE***

  Virtual depth for software device object level.

- ***HWLOC\_TYPE\_DEPTH\_MISC***

  Virtual depth for Misc object.

- ***HWLOC\_TYPE\_DEPTH\_MEMCACHE***

  Virtual depth for MemCache object.

## Function Documentation

### hwloc\_obj\_type\_t hwloc\_get\_depth\_type (hwloc\_topology\_t topology, int depth)

Returns the type of objects at depth depth. depth should between 0 and **hwloc\_topology\_get\_depth()**-1, or a virtual depth such as **HWLOC\_TYPE\_DEPTH\_NUMANODE**.

**Returns**

The type of objects at depth depth.

(**hwloc\_obj\_type\_t**)-1 if depth depth does not exist.

### int hwloc\_get\_memory\_parents\_depth (hwloc\_topology\_t topology)

Return the depth of parents where memory objects are attached. Memory objects have virtual negative depths because they are not part of the main CPU-side hierarchy of objects. This depth should not be compared with other level depths.

If all Memory objects are attached to Normal parents at the same depth, this parent depth may be compared to other as usual, for instance for knowing whether NUMA nodes is attached above or below Packages.

**Returns**

The depth of Normal parents of all memory children if all these parents have the same depth. For instance the depth of the Package level if all NUMA nodes are attached to Package objects.

**HWLOC\_TYPE\_DEPTH\_MULTIPLE** if Normal parents of all memory children do not have the same depth. For instance if some NUMA nodes are attached to Packages while others are attached to Groups.

### unsigned hwloc\_get\_nbobjs\_by\_depth (hwloc\_topology\_t topology, int depth)

Returns the width of level at depth depth.

**Returns**

The number of objects at topology depth depth.

0 if there are no objects at depth depth.

### int hwloc\_get\_nbobjs\_by\_type (hwloc\_topology\_t topology, hwloc\_obj\_type\_t type) \[inline\]

Returns the width of level type type.

**Returns**

The number of objects of type type.

\-1 if there are multiple levels with objects of that type, e.g. **HWLOC\_OBJ\_GROUP**.

0 if there are no objects at depth depth.

### hwloc\_obj\_t hwloc\_get\_next\_obj\_by\_depth (hwloc\_topology\_t topology, int depth, hwloc\_obj\_t prev) \[inline\]

Returns the next object at depth depth.

**Returns**

The first object at depth depth if prev is NULL.

The object after prev at depth depth if prev is not NULL.

NULL if there is no such object.

### hwloc\_obj\_t hwloc\_get\_next\_obj\_by\_type (hwloc\_topology\_t topology, hwloc\_obj\_type\_t type, hwloc\_obj\_t prev) \[inline\]

Returns the next object of type type.

**Returns**

The first object of type type if prev is NULL.

The object after prev of type type if prev is not NULL.

NULL if there is no such object.

NULL if there are multiple levels with objects of that type (e.g. **HWLOC\_OBJ\_GROUP**), the caller may fallback to **hwloc\_get\_obj\_by\_depth()**.

### hwloc\_obj\_t hwloc\_get\_obj\_by\_depth (hwloc\_topology\_t topology, int depth, unsigned idx)

Returns the topology object at logical index idx from depth depth.

**Returns**

The object if it exists.

NULL if there is no object with this index and depth.

### hwloc\_obj\_t hwloc\_get\_obj\_by\_type (hwloc\_topology\_t topology, hwloc\_obj\_type\_t type, unsigned idx) \[inline\]

Returns the topology object at logical index idx with type type.

**Returns**

The object if it exists.

NULL if there is no object with this index and type.

NULL if there are multiple levels with objects of that type (e.g. **HWLOC\_OBJ\_GROUP**), the caller may fallback to **hwloc\_get\_obj\_by\_depth()**.

### hwloc\_obj\_t hwloc\_get\_root\_obj (hwloc\_topology\_t topology) \[inline\]

Returns the top-object of the topology-tree. Its type is **HWLOC\_OBJ\_MACHINE**.

This function cannot return NULL.

### int hwloc\_get\_type\_depth (hwloc\_topology\_t topology, hwloc\_obj\_type\_t type)

Returns the depth of objects of type type.

**Returns**

The depth of objects of type type.

A negative virtual depth if a NUMA node, I/O or Misc object type is given. These objects are stored in special levels that are not CPU-related. This virtual depth may be passed to other hwloc functions such as **hwloc\_get\_obj\_by\_depth()** but it should not be considered as an actual depth by the application. In particular, it should not be compared with any other object depth or with the entire topology depth.

**HWLOC\_TYPE\_DEPTH\_UNKNOWN** if no object of this type is present on the underlying architecture, or if the OS doesn't provide this kind of information.

**HWLOC\_TYPE\_DEPTH\_MULTIPLE** if type **HWLOC\_OBJ\_GROUP** is given and multiple levels of Groups exist.

**Note**

If the type is absent but a similar type is acceptable, see also **hwloc\_get\_type\_or\_below\_depth()** and **hwloc\_get\_type\_or\_above\_depth()**.

**See also**

**hwloc\_get\_memory\_parents\_depth()** for managing the depth of memory objects.

**hwloc\_type\_sscanf\_as\_depth()** for returning the depth of objects whose type is given as a string.

### int hwloc\_get\_type\_or\_above\_depth (hwloc\_topology\_t topology, hwloc\_obj\_type\_t type) \[inline\]

Returns the depth of objects of type type or above. If no object of this type is present on the underlying architecture, the function returns the depth of the first "present" object typically containing type.

This function is only meaningful for normal object types. If a memory, I/O or Misc object type is given, the corresponding virtual depth is always returned (see **hwloc\_get\_type\_depth()**).

May return **HWLOC\_TYPE\_DEPTH\_MULTIPLE** for **HWLOC\_OBJ\_GROUP** just like **hwloc\_get\_type\_depth()**.

### int hwloc\_get\_type\_or\_below\_depth (hwloc\_topology\_t topology, hwloc\_obj\_type\_t type) \[inline\]

Returns the depth of objects of type type or below. If no object of this type is present on the underlying architecture, the function returns the depth of the first "present" object typically found inside type.

This function is only meaningful for normal object types. If a memory, I/O or Misc object type is given, the corresponding virtual depth is always returned (see **hwloc\_get\_type\_depth()**).

May return **HWLOC\_TYPE\_DEPTH\_MULTIPLE** for **HWLOC\_OBJ\_GROUP** just like **hwloc\_get\_type\_depth()**.

### int hwloc\_topology\_get\_depth (hwloc\_topology\_t restrict topology)

Get the depth of the hierarchical tree of objects. This is the depth of **HWLOC\_OBJ\_PU** objects plus one.

**Returns**

the depth of the object tree.

**Note**

NUMA nodes, I/O and Misc objects are ignored when computing the depth of the tree (they are placed on special levels).

## Author

Generated automatically by Doxygen for Hardware Locality (hwloc) from the source code.
