13 #ifndef HWLOC_HELPER_H
14 #define HWLOC_HELPER_H
17 #error Please include the main hwloc.h instead
92 if (!next || !next->
cpuset)
125 unsigned depth,
unsigned idx) __hwloc_attribute_pure;
128 unsigned depth,
unsigned idx)
172 static __hwloc_inline
unsigned
174 unsigned depth) __hwloc_attribute_pure;
175 static __hwloc_inline
unsigned
200 static __hwloc_inline
int
203 static __hwloc_inline
int
223 static __hwloc_inline
int
226 static __hwloc_inline
int
311 if (!next || !next->
cpuset)
363 if (obj->
depth < depth)
365 while (ancestor && ancestor->
depth > depth)
366 ancestor = ancestor->
parent;
377 while (ancestor && ancestor->
type != type)
378 ancestor = ancestor->
parent;
393 while (obj1 != obj2) {
398 if (obj1 != obj2 && obj1->
depth == obj2->
depth) {
410 static __hwloc_inline
int
412 static __hwloc_inline
int
427 if (prev->
parent != parent)
459 static __hwloc_inline
int
465 for (depth=0; ; depth++) {
505 current = current->
parent;
522 while (current && current->
cpuset) {
526 current = current->
parent;
653 for(i=0; i<nr; i++) {
701 static __hwloc_inline
int
706 unsigned until,
unsigned long flags)
710 unsigned given, givenweight;
719 for (i = 0; i < n_roots; i++)
723 for (i = 0, given = 0, givenweight = 0; i < n_roots; i++) {
724 unsigned chunk, weight;
734 chunk = (( (givenweight+weight) * n + tot_weight-1) / tot_weight)
735 - (( givenweight * n + tot_weight-1) / tot_weight);
736 if (!root->
arity || chunk <= 1 || root->
depth >= until) {
741 for (j=0; j < chunk; j++)
757 givenweight += weight;
921 static __hwloc_inline
void
949 static __hwloc_inline
void
970 static __hwloc_inline
void
1001 static __hwloc_inline
void
1100 while (obj && obj->
cpuset) {
1125 static __hwloc_inline
int
1128 float *
latency,
float *reverse_latency)
1132 unsigned first_logical ;
1141 if (distances && distances->
latency) {
1142 const float * latency_matrix = distances->
latency;
1146 *latency = latency_matrix[l1*nbobjs+l2];
1147 *reverse_latency = latency_matrix[l2*nbobjs+l1];
1174 while (obj && !obj->
cpuset) {
1195 unsigned domain,
unsigned bus,
unsigned dev,
unsigned func)
1214 unsigned domain = 0;
1215 unsigned bus, dev, func;
1217 if (sscanf(busid,
"%x:%x.%x", &bus, &dev, &func) != 3
1218 && sscanf(busid,
"%x:%x:%x.%x", &domain, &bus, &dev, &func) != 4) {
1248 static __hwloc_inline
int
1250 unsigned domain,
unsigned bus)
1266 unsigned domain,
unsigned bus)
static void hwloc_cpuset_to_nodeset(hwloc_topology_t topology, hwloc_const_cpuset_t _cpuset, hwloc_nodeset_t nodeset)
Convert a CPU set into a NUMA node set and handle non-NUMA cases.
Definition: helper.h:922
struct hwloc_obj * parent
Parent, NULL if root (system object)
Definition: hwloc.h:370
hwloc_bitmap_t hwloc_bitmap_dup(hwloc_const_bitmap_t bitmap)
Duplicate bitmap bitmap by allocating a new bitmap and copying bitmap contents.
hwloc_obj_type_t
Type of topology object.
Definition: hwloc.h:160
static hwloc_obj_t hwloc_get_numanode_obj_by_os_index(hwloc_topology_t topology, unsigned os_index)
Returns the object of type HWLOC_OBJ_NODE with os_index.
Definition: helper.h:577
hwloc_bitmap_t hwloc_nodeset_t
A node set is a bitmap whose bits are set according to NUMA memory node physical OS indexes...
Definition: hwloc.h:141
unsigned arity
Number of children.
Definition: hwloc.h:376
static hwloc_obj_t hwloc_get_next_obj_covering_cpuset_by_type(hwloc_topology_t topology, hwloc_const_cpuset_t set, hwloc_obj_type_t type, hwloc_obj_t prev)
Iterate through same-type objects covering at least CPU set set.
Definition: helper.h:334
struct hwloc_distances_s ** distances
Distances between all objects at same depth below this object.
Definition: hwloc.h:475
static hwloc_obj_t hwloc_get_obj_by_type(hwloc_topology_t topology, hwloc_obj_type_t type, unsigned idx)
Returns the topology object at logical index idx with type type.
static int hwloc_obj_is_in_subtree(hwloc_topology_t topology, hwloc_obj_t obj, hwloc_obj_t subtree_root)
Returns true if obj is inside the subtree beginning with ancestor object subtree_root.
Definition: helper.h:413
static hwloc_const_nodeset_t hwloc_topology_get_allowed_nodeset(hwloc_topology_t topology)
Get allowed node set.
Definition: helper.h:886
unsigned depth
Vertical index in the hierarchy. If the topology is symmetric, this is equal to the parent depth plus...
Definition: hwloc.h:354
hwloc_obj_cache_type_t type
Cache type.
Definition: hwloc.h:501
static hwloc_obj_t hwloc_get_common_ancestor_obj(hwloc_topology_t topology, hwloc_obj_t obj1, hwloc_obj_t obj2)
Returns the common parent object to objects lvl1 and lvl2.
Definition: helper.h:386
unsigned depth
Depth of cache (e.g., L1, L2, ...etc.)
Definition: hwloc.h:497
int hwloc_bitmap_weight(hwloc_const_bitmap_t bitmap)
Compute the "weight" of bitmap bitmap (i.e., number of indexes that are in the bitmap).
int hwloc_bitmap_isincluded(hwloc_const_bitmap_t sub_bitmap, hwloc_const_bitmap_t super_bitmap)
Test whether bitmap sub_bitmap is part of bitmap super_bitmap.
hwloc_obj_bridge_type_t downstream_type
Definition: hwloc.h:528
static hwloc_obj_t hwloc_get_ancestor_obj_by_type(hwloc_topology_t topology, hwloc_obj_type_t type, hwloc_obj_t obj)
Returns the ancestor object of obj with type type.
Definition: helper.h:374
static hwloc_const_cpuset_t hwloc_topology_get_topology_cpuset(hwloc_topology_t topology)
Get topology CPU set.
Definition: helper.h:800
static hwloc_obj_t hwloc_get_cache_covering_cpuset(hwloc_topology_t topology, hwloc_const_cpuset_t set)
Get the first cache covering a cpuset set.
Definition: helper.h:499
struct hwloc_obj_attr_u::hwloc_pcidev_attr_s pcidev
unsigned char bus
Definition: hwloc.h:510
static hwloc_obj_t hwloc_get_first_largest_obj_inside_cpuset(hwloc_topology_t topology, hwloc_const_cpuset_t set)
Get the first largest object included in the given cpuset set.
Definition: helper.h:45
unsigned relative_depth
Relative depth of the considered objects below the object containing this distance information...
Definition: hwloc.h:551
static int hwloc_bridge_covers_pcibus(hwloc_obj_t bridge, unsigned domain, unsigned bus)
Definition: helper.h:1249
struct hwloc_obj_attr_u::hwloc_bridge_attr_s bridge
PCI-side of a bridge.
Definition: hwloc.h:262
static int hwloc_get_latency(hwloc_topology_t topology, hwloc_obj_t obj1, hwloc_obj_t obj2, float *latency, float *reverse_latency)
Get the latency in both directions between two objects.
Definition: helper.h:1126
static hwloc_obj_t hwloc_get_next_bridge(hwloc_topology_t topology, hwloc_obj_t prev)
Get the next bridge in the system.
Definition: helper.h:1241
hwloc_nodeset_t allowed_nodeset
The set of allowed NUMA memory nodes.
Definition: hwloc.h:462
void hwloc_bitmap_fill(hwloc_bitmap_t bitmap)
Fill bitmap bitmap with all possible indexes (even if those objects don't exist or are otherwise unav...
static hwloc_const_cpuset_t hwloc_topology_get_complete_cpuset(hwloc_topology_t topology)
Get complete CPU set.
Definition: helper.h:782
unsigned char func
Definition: hwloc.h:510
unsigned nbobjs
Number of objects considered in the matrix. It is the number of descendant objects at relative_depth ...
Definition: hwloc.h:553
static hwloc_obj_t hwloc_get_next_obj_by_type(hwloc_topology_t topology, hwloc_obj_type_t type, hwloc_obj_t prev)
Returns the next object of type type.
static int hwloc_get_nbobjs_inside_cpuset_by_type(hwloc_topology_t topology, hwloc_const_cpuset_t set, hwloc_obj_type_t type)
Return the number of objects of type type included in CPU set set.
Definition: helper.h:204
static hwloc_obj_t hwloc_get_ancestor_obj_by_depth(hwloc_topology_t topology, unsigned depth, hwloc_obj_t obj)
Returns the ancestor object of obj at depth depth.
Definition: helper.h:360
static hwloc_obj_t hwloc_get_next_child(hwloc_topology_t topology, hwloc_obj_t parent, hwloc_obj_t prev)
Return the next child.
Definition: helper.h:423
void hwloc_bitmap_set(hwloc_bitmap_t bitmap, unsigned id)
Add index id in bitmap bitmap.
static hwloc_obj_t hwloc_get_root_obj(hwloc_topology_t topology)
Returns the top-object of the topology-tree.
static hwloc_obj_t hwloc_get_next_osdev(hwloc_topology_t topology, hwloc_obj_t prev)
Get the next OS device in the system.
Definition: helper.h:1231
Distrib in reverse order, starting from the last objects.
Definition: helper.h:675
void hwloc_bitmap_or(hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2)
Or bitmaps bitmap1 and bitmap2 and store the result in bitmap res.
union hwloc_obj_attr_u * attr
Object type-specific Attributes, may be NULL if no attribute value was found.
Definition: hwloc.h:350
struct hwloc_obj * first_child
First child.
Definition: hwloc.h:378
static hwloc_obj_t hwloc_get_next_obj_covering_cpuset_by_depth(hwloc_topology_t topology, hwloc_const_cpuset_t set, unsigned depth, hwloc_obj_t prev)
Iterate through same-depth objects covering at least CPU set set.
Definition: helper.h:307
hwloc_cpuset_t cpuset
CPUs covered by this object.
Definition: hwloc.h:388
static hwloc_obj_t hwloc_get_obj_below_by_type(hwloc_topology_t topology, hwloc_obj_type_t type1, unsigned idx1, hwloc_obj_type_t type2, unsigned idx2)
Find an object below another object, both specified by types and indexes.
Definition: helper.h:617
hwloc_obj_bridge_type_t upstream_type
Definition: hwloc.h:521
unsigned char dev
Definition: hwloc.h:510
static const struct hwloc_distances_s * hwloc_get_whole_distance_matrix_by_type(hwloc_topology_t topology, hwloc_obj_type_t type)
Get the distances between all objects of a given type.
Definition: helper.h:1074
NUMA node. A set of processors around memory which the processors can directly access.
Definition: hwloc.h:180
float * latency
Matrix of latencies between objects, stored as a one-dimension array. May be NULL if the distances co...
Definition: hwloc.h:558
unsigned short domain
Definition: hwloc.h:509
static hwloc_obj_t hwloc_get_shared_cache_covering_obj(hwloc_topology_t topology, hwloc_obj_t obj)
Get the first cache shared between an object and somebody else.
Definition: helper.h:517
PCI device. These objects have neither CPU sets nor node sets. They are not added to the topology unl...
Definition: hwloc.h:228
int hwloc_bitmap_iszero(hwloc_const_bitmap_t bitmap)
Test whether bitmap bitmap is empty.
static hwloc_obj_t hwloc_get_next_obj_inside_cpuset_by_type(hwloc_topology_t topology, hwloc_const_cpuset_t set, hwloc_obj_type_t type, hwloc_obj_t prev)
Return the next object of type type included in CPU set set.
Definition: helper.h:109
Processing Unit, or (Logical) Processor. An execution unit (may share a core with some other logical ...
Definition: hwloc.h:195
hwloc_cpuset_t allowed_cpuset
The CPU set of allowed logical processors.
Definition: hwloc.h:420
static hwloc_const_nodeset_t hwloc_topology_get_complete_nodeset(hwloc_topology_t topology)
Get complete node set.
Definition: helper.h:851
union hwloc_obj_attr_u::hwloc_bridge_attr_s::@1 downstream
static hwloc_obj_t hwloc_get_obj_below_array_by_type(hwloc_topology_t topology, int nr, hwloc_obj_type_t *typev, unsigned *idxv)
Find an object below a chain of objects specified by types and indexes.
Definition: helper.h:649
int hwloc_get_type_depth(hwloc_topology_t topology, hwloc_obj_type_t type)
Returns the depth of objects of type type.
Distances between objects.
Definition: hwloc.h:550
static hwloc_const_cpuset_t hwloc_topology_get_allowed_cpuset(hwloc_topology_t topology)
Get allowed CPU set.
Definition: helper.h:834
static hwloc_obj_t hwloc_get_hostbridge_by_pcibus(hwloc_topology_t topology, unsigned domain, unsigned bus)
Find the hostbridge that covers the given PCI bus.
Definition: helper.h:1265
Objects of given type exist at different depth in the topology.
Definition: hwloc.h:1118
static int hwloc_get_obj_index_inside_cpuset(hwloc_topology_t topology, hwloc_const_cpuset_t set, hwloc_obj_t obj)
Return the logical index among the objects included in CPU set set.
Definition: helper.h:227
static hwloc_obj_t hwloc_get_next_obj_inside_cpuset_by_depth(hwloc_topology_t topology, hwloc_const_cpuset_t set, unsigned depth, hwloc_obj_t prev)
Return the next object at depth depth included in CPU set set.
Definition: helper.h:88
static unsigned hwloc_get_nbobjs_inside_cpuset_by_depth(hwloc_topology_t topology, hwloc_const_cpuset_t set, unsigned depth)
Return the number of objects at depth depth included in CPU set set.
Definition: helper.h:176
Unified cache.
Definition: hwloc.h:253
unsigned logical_index
Horizontal index in the whole list of similar objects, hence guaranteed unique across the entire mach...
Definition: hwloc.h:359
static hwloc_obj_t hwloc_get_next_obj_by_depth(hwloc_topology_t topology, unsigned depth, hwloc_obj_t prev)
Returns the next object at depth depth.
static int hwloc_get_cache_type_depth(hwloc_topology_t topology, unsigned cachelevel, hwloc_obj_cache_type_t cachetype)
Find the depth of cache objects matching cache depth and type.
Definition: helper.h:460
int hwloc_get_largest_objs_inside_cpuset(hwloc_topology_t topology, hwloc_const_cpuset_t set, hwloc_obj_t *restrict objs, int max)
Get the set of largest objects covering exactly a given cpuset set.
enum hwloc_obj_cache_type_e hwloc_obj_cache_type_t
Cache type.
static hwloc_obj_t hwloc_get_obj_inside_cpuset_by_type(hwloc_topology_t topology, hwloc_const_cpuset_t set, hwloc_obj_type_t type, unsigned idx)
Return the idx -th object of type type included in CPU set set.
Definition: helper.h:158
hwloc_nodeset_t nodeset
NUMA nodes covered by this object or containing this object.
Definition: hwloc.h:431
hwloc_distrib_flags_e
Flags to be given to hwloc_distrib().
Definition: helper.h:671
Operating system device. These objects have neither CPU sets nor node sets. They are not added to the...
Definition: hwloc.h:233
struct hwloc_obj ** children
Children, children[0 .. arity -1].
Definition: hwloc.h:377
Bridge. Any bridge that connects the host or an I/O bus, to another I/O bus. Bridge objects have neit...
Definition: hwloc.h:221
static void hwloc_cpuset_from_nodeset_strict(struct hwloc_topology *topology, hwloc_cpuset_t _cpuset, hwloc_const_nodeset_t nodeset)
Convert a NUMA node set into a CPU set without handling non-NUMA cases.
Definition: helper.h:1002
static hwloc_obj_t hwloc_get_pcidev_by_busidstring(hwloc_topology_t topology, const char *busid)
Find the PCI device object matching the PCI bus id given as a string xxxx:yy:zz.t or yy:zz...
Definition: helper.h:1212
static const struct hwloc_distances_s * hwloc_get_whole_distance_matrix_by_depth(hwloc_topology_t topology, unsigned depth)
Get the distances between all objects at the given depth.
Definition: helper.h:1044
Host-side of a bridge, only possible upstream.
Definition: hwloc.h:261
struct hwloc_obj * next_sibling
Next object below the same parent.
Definition: hwloc.h:372
hwloc_const_bitmap_t hwloc_const_cpuset_t
A non-modifiable hwloc_cpuset_t.
Definition: hwloc.h:124
int hwloc_bitmap_isequal(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2)
Test whether bitmap bitmap1 is equal to bitmap bitmap2.
struct hwloc_obj * next_cousin
Next object of same type and depth.
Definition: hwloc.h:366
static hwloc_obj_t hwloc_get_pcidev_by_busid(hwloc_topology_t topology, unsigned domain, unsigned bus, unsigned dev, unsigned func)
Find the PCI device object matching the PCI bus id given domain, bus device and function PCI bus id...
Definition: helper.h:1194
static hwloc_const_nodeset_t hwloc_topology_get_topology_nodeset(hwloc_topology_t topology)
Get topology node set.
Definition: helper.h:869
hwloc_cpuset_t complete_cpuset
The complete CPU set of logical processors of this object,.
Definition: hwloc.h:401
hwloc_const_bitmap_t hwloc_const_nodeset_t
A non-modifiable hwloc_nodeset_t.
Definition: hwloc.h:144
struct hwloc_obj_attr_u::hwloc_cache_attr_s cache
static const struct hwloc_distances_s * hwloc_get_distance_matrix_covering_obj_by_depth(hwloc_topology_t topology, hwloc_obj_t obj, unsigned depth, unsigned *firstp)
Get distances for the given depth and covering some objects.
Definition: helper.h:1096
static void hwloc_cpuset_from_nodeset(hwloc_topology_t topology, hwloc_cpuset_t _cpuset, hwloc_const_nodeset_t nodeset)
Convert a NUMA node set into a CPU set and handle non-NUMA cases.
Definition: helper.h:971
static void hwloc_cpuset_to_nodeset_strict(struct hwloc_topology *topology, hwloc_const_cpuset_t _cpuset, hwloc_nodeset_t nodeset)
Convert a CPU set into a NUMA node set without handling non-NUMA cases.
Definition: helper.h:950
hwloc_cpuset_t online_cpuset
The CPU set of online logical processors.
Definition: hwloc.h:412
static hwloc_obj_t hwloc_get_non_io_ancestor_obj(hwloc_topology_t topology, hwloc_obj_t ioobj)
Get the first non-I/O ancestor object.
Definition: helper.h:1170
static int hwloc_distrib(hwloc_topology_t topology, hwloc_obj_t *roots, unsigned n_roots, hwloc_cpuset_t *set, unsigned n, unsigned until, unsigned long flags)
Distribute n items over the topology under roots.
Definition: helper.h:702
static hwloc_obj_t hwloc_get_pu_obj_by_os_index(hwloc_topology_t topology, unsigned os_index)
Returns the object of type HWLOC_OBJ_PU with os_index.
Definition: helper.h:556
struct hwloc_pcidev_attr_s pci
Definition: hwloc.h:519
int hwloc_bitmap_isset(hwloc_const_bitmap_t bitmap, unsigned id)
Test whether index id is part of bitmap bitmap.
unsigned distances_count
Definition: hwloc.h:476
No object of given type exists in the topology.
Definition: hwloc.h:1117
unsigned hwloc_get_closest_objs(hwloc_topology_t topology, hwloc_obj_t src, hwloc_obj_t *restrict objs, unsigned max)
Do a depth-first traversal of the topology to find and sort.
Cache. Can be L1i, L1d, L2, L3, ...
Definition: hwloc.h:188
unsigned os_index
OS-provided physical index number. It is not guaranteed unique across the entire machine, except for PUs and NUMA nodes.
Definition: hwloc.h:342
hwloc_bitmap_t hwloc_cpuset_t
A CPU set is a bitmap whose bits are set according to CPU physical OS indexes.
Definition: hwloc.h:122
static hwloc_obj_t hwloc_get_child_covering_cpuset(hwloc_topology_t topology, hwloc_const_cpuset_t set, hwloc_obj_t parent)
Get the child covering at least CPU set set.
Definition: helper.h:258
static hwloc_obj_t hwloc_get_next_pcidev(hwloc_topology_t topology, hwloc_obj_t prev)
Get the next PCI device in the system.
Definition: helper.h:1185
struct hwloc_obj * prev_cousin
Previous object of same type and depth.
Definition: hwloc.h:367
static hwloc_const_cpuset_t hwloc_topology_get_online_cpuset(hwloc_topology_t topology)
Get online CPU set.
Definition: helper.h:817
hwloc_nodeset_t complete_nodeset
The complete NUMA node set of this object,.
Definition: hwloc.h:448
struct hwloc_topology * hwloc_topology_t
Topology context.
Definition: hwloc.h:596
hwloc_obj_t hwloc_get_obj_by_depth(hwloc_topology_t topology, unsigned depth, unsigned idx)
Returns the topology object at logical index idx from depth depth.
static hwloc_obj_t hwloc_get_obj_inside_cpuset_by_depth(hwloc_topology_t topology, hwloc_const_cpuset_t set, unsigned depth, unsigned idx)
Return the (logically) idx -th object at depth depth included in CPU set set.
Definition: helper.h:127
int hwloc_bitmap_intersects(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2)
Test whether bitmaps bitmap1 and bitmap2 intersects.
hwloc_obj_type_t type
Type of object.
Definition: hwloc.h:341
void hwloc_bitmap_zero(hwloc_bitmap_t bitmap)
Empty the bitmap bitmap.
static hwloc_obj_t hwloc_get_obj_covering_cpuset(hwloc_topology_t topology, hwloc_const_cpuset_t set)
Get the lowest object covering at least CPU set set.
Definition: helper.h:283
Structure of a topology object.
Definition: hwloc.h:339