Open MPI logo

Portable Hardware Locality (hwloc) Documentation: v2.7.0

  |   Home   |   Support   |   FAQ   |  
helper.h
1 /*
2  * Copyright © 2009 CNRS
3  * Copyright © 2009-2021 Inria. All rights reserved.
4  * Copyright © 2009-2012 Université Bordeaux
5  * Copyright © 2009-2010 Cisco Systems, Inc. All rights reserved.
6  * See COPYING in top-level directory.
7  */
8 
13 #ifndef HWLOC_HELPER_H
14 #define HWLOC_HELPER_H
15 
16 #ifndef HWLOC_H
17 #error Please include the main hwloc.h instead
18 #endif
19 
20 #include <stdlib.h>
21 #include <errno.h>
22 
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 
41 static __hwloc_inline hwloc_obj_t
43 {
44  hwloc_obj_t obj = hwloc_get_root_obj(topology);
45  if (!hwloc_bitmap_intersects(obj->cpuset, set))
46  return NULL;
47  while (!hwloc_bitmap_isincluded(obj->cpuset, set)) {
48  /* while the object intersects without being included, look at its children */
49  hwloc_obj_t child = obj->first_child;
50  while (child) {
51  if (hwloc_bitmap_intersects(child->cpuset, set))
52  break;
53  child = child->next_sibling;
54  }
55  if (!child)
56  /* no child intersects, return their father */
57  return obj;
58  /* found one intersecting child, look at its children */
59  obj = child;
60  }
61  /* obj is included, return it */
62  return obj;
63 }
64 
70  hwloc_obj_t * __hwloc_restrict objs, int max);
71 
84 static __hwloc_inline hwloc_obj_t
86  int depth, hwloc_obj_t prev)
87 {
88  hwloc_obj_t next = hwloc_get_next_obj_by_depth(topology, depth, prev);
89  if (!next)
90  return NULL;
91  while (next && (hwloc_bitmap_iszero(next->cpuset) || !hwloc_bitmap_isincluded(next->cpuset, set)))
92  next = next->next_cousin;
93  return next;
94 }
95 
108 static __hwloc_inline hwloc_obj_t
110  hwloc_obj_type_t type, hwloc_obj_t prev)
111 {
112  int depth = hwloc_get_type_depth(topology, type);
113  if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
114  return NULL;
115  return hwloc_get_next_obj_inside_cpuset_by_depth(topology, set, depth, prev);
116 }
117 
126 static __hwloc_inline hwloc_obj_t
128  int depth, unsigned idx) __hwloc_attribute_pure;
129 static __hwloc_inline hwloc_obj_t
131  int depth, unsigned idx)
132 {
133  hwloc_obj_t obj = hwloc_get_obj_by_depth (topology, depth, 0);
134  unsigned count = 0;
135  if (!obj)
136  return NULL;
137  while (obj) {
138  if (!hwloc_bitmap_iszero(obj->cpuset) && hwloc_bitmap_isincluded(obj->cpuset, set)) {
139  if (count == idx)
140  return obj;
141  count++;
142  }
143  obj = obj->next_cousin;
144  }
145  return NULL;
146 }
147 
160 static __hwloc_inline hwloc_obj_t
162  hwloc_obj_type_t type, unsigned idx) __hwloc_attribute_pure;
163 static __hwloc_inline hwloc_obj_t
165  hwloc_obj_type_t type, unsigned idx)
166 {
167  int depth = hwloc_get_type_depth(topology, type);
168  if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
169  return NULL;
170  return hwloc_get_obj_inside_cpuset_by_depth(topology, set, depth, idx);
171 }
172 
181 static __hwloc_inline unsigned
183  int depth) __hwloc_attribute_pure;
184 static __hwloc_inline unsigned
186  int depth)
187 {
188  hwloc_obj_t obj = hwloc_get_obj_by_depth (topology, depth, 0);
189  unsigned count = 0;
190  if (!obj)
191  return 0;
192  while (obj) {
193  if (!hwloc_bitmap_iszero(obj->cpuset) && hwloc_bitmap_isincluded(obj->cpuset, set))
194  count++;
195  obj = obj->next_cousin;
196  }
197  return count;
198 }
199 
212 static __hwloc_inline int
214  hwloc_obj_type_t type) __hwloc_attribute_pure;
215 static __hwloc_inline int
217  hwloc_obj_type_t type)
218 {
219  int depth = hwloc_get_type_depth(topology, type);
220  if (depth == HWLOC_TYPE_DEPTH_UNKNOWN)
221  return 0;
222  if (depth == HWLOC_TYPE_DEPTH_MULTIPLE)
223  return -1; /* FIXME: agregate nbobjs from different levels? */
224  return (int) hwloc_get_nbobjs_inside_cpuset_by_depth(topology, set, depth);
225 }
226 
240 static __hwloc_inline int
241 hwloc_get_obj_index_inside_cpuset (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t set,
242  hwloc_obj_t obj) __hwloc_attribute_pure;
243 static __hwloc_inline int
245  hwloc_obj_t obj)
246 {
247  int idx = 0;
248  if (!hwloc_bitmap_isincluded(obj->cpuset, set))
249  return -1;
250  /* count how many objects are inside the cpuset on the way from us to the beginning of the level */
251  while ((obj = obj->prev_cousin) != NULL)
252  if (!hwloc_bitmap_iszero(obj->cpuset) && hwloc_bitmap_isincluded(obj->cpuset, set))
253  idx++;
254  return idx;
255 }
256 
271 static __hwloc_inline hwloc_obj_t
272 hwloc_get_child_covering_cpuset (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t set,
273  hwloc_obj_t parent) __hwloc_attribute_pure;
274 static __hwloc_inline hwloc_obj_t
276  hwloc_obj_t parent)
277 {
278  hwloc_obj_t child;
279  if (hwloc_bitmap_iszero(set))
280  return NULL;
281  child = parent->first_child;
282  while (child) {
283  if (child->cpuset && hwloc_bitmap_isincluded(set, child->cpuset))
284  return child;
285  child = child->next_sibling;
286  }
287  return NULL;
288 }
289 
294 static __hwloc_inline hwloc_obj_t
295 hwloc_get_obj_covering_cpuset (hwloc_topology_t topology, hwloc_const_cpuset_t set) __hwloc_attribute_pure;
296 static __hwloc_inline hwloc_obj_t
298 {
299  struct hwloc_obj *current = hwloc_get_root_obj(topology);
300  if (hwloc_bitmap_iszero(set) || !hwloc_bitmap_isincluded(set, current->cpuset))
301  return NULL;
302  while (1) {
303  hwloc_obj_t child = hwloc_get_child_covering_cpuset(topology, set, current);
304  if (!child)
305  return current;
306  current = child;
307  }
308 }
309 
320 static __hwloc_inline hwloc_obj_t
322  int depth, hwloc_obj_t prev)
323 {
324  hwloc_obj_t next = hwloc_get_next_obj_by_depth(topology, depth, prev);
325  if (!next)
326  return NULL;
327  while (next && !hwloc_bitmap_intersects(set, next->cpuset))
328  next = next->next_cousin;
329  return next;
330 }
331 
347 static __hwloc_inline hwloc_obj_t
350 {
351  int depth = hwloc_get_type_depth(topology, type);
353  return NULL;
354  return hwloc_get_next_obj_covering_cpuset_by_depth(topology, set, depth, prev);
355 }
356 
377 static __hwloc_inline hwloc_obj_t
378 hwloc_get_ancestor_obj_by_depth (hwloc_topology_t topology __hwloc_attribute_unused, int depth, hwloc_obj_t obj) __hwloc_attribute_pure;
379 static __hwloc_inline hwloc_obj_t
380 hwloc_get_ancestor_obj_by_depth (hwloc_topology_t topology __hwloc_attribute_unused, int depth, hwloc_obj_t obj)
381 {
382  hwloc_obj_t ancestor = obj;
383  if (obj->depth < depth)
384  return NULL;
385  while (ancestor && ancestor->depth > depth)
386  ancestor = ancestor->parent;
387  return ancestor;
388 }
389 
397 static __hwloc_inline hwloc_obj_t
398 hwloc_get_ancestor_obj_by_type (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_type_t type, hwloc_obj_t obj) __hwloc_attribute_pure;
399 static __hwloc_inline hwloc_obj_t
401 {
402  hwloc_obj_t ancestor = obj->parent;
403  while (ancestor && ancestor->type != type)
404  ancestor = ancestor->parent;
405  return ancestor;
406 }
407 
409 static __hwloc_inline hwloc_obj_t
410 hwloc_get_common_ancestor_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj1, hwloc_obj_t obj2) __hwloc_attribute_pure;
411 static __hwloc_inline hwloc_obj_t
412 hwloc_get_common_ancestor_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj1, hwloc_obj_t obj2)
413 {
414  /* the loop isn't so easy since intermediate ancestors may have
415  * different depth, causing us to alternate between using obj1->parent
416  * and obj2->parent. Also, even if at some point we find ancestors of
417  * of the same depth, their ancestors may have different depth again.
418  */
419  while (obj1 != obj2) {
420  while (obj1->depth > obj2->depth)
421  obj1 = obj1->parent;
422  while (obj2->depth > obj1->depth)
423  obj2 = obj2->parent;
424  if (obj1 != obj2 && obj1->depth == obj2->depth) {
425  obj1 = obj1->parent;
426  obj2 = obj2->parent;
427  }
428  }
429  return obj1;
430 }
431 
437 static __hwloc_inline int
438 hwloc_obj_is_in_subtree (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj, hwloc_obj_t subtree_root) __hwloc_attribute_pure;
439 static __hwloc_inline int
440 hwloc_obj_is_in_subtree (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj, hwloc_obj_t subtree_root)
441 {
442  return obj->cpuset && subtree_root->cpuset && hwloc_bitmap_isincluded(obj->cpuset, subtree_root->cpuset);
443 }
444 
455 static __hwloc_inline hwloc_obj_t
456 hwloc_get_next_child (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t parent, hwloc_obj_t prev)
457 {
458  hwloc_obj_t obj;
459  int state = 0;
460  if (prev) {
461  if (prev->type == HWLOC_OBJ_MISC)
462  state = 3;
463  else if (prev->type == HWLOC_OBJ_BRIDGE || prev->type == HWLOC_OBJ_PCI_DEVICE || prev->type == HWLOC_OBJ_OS_DEVICE)
464  state = 2;
465  else if (prev->type == HWLOC_OBJ_NUMANODE)
466  state = 1;
467  obj = prev->next_sibling;
468  } else {
469  obj = parent->first_child;
470  }
471  if (!obj && state == 0) {
472  obj = parent->memory_first_child;
473  state = 1;
474  }
475  if (!obj && state == 1) {
476  obj = parent->io_first_child;
477  state = 2;
478  }
479  if (!obj && state == 2) {
480  obj = parent->misc_first_child;
481  state = 3;
482  }
483  return obj;
484 }
485 
512 HWLOC_DECLSPEC int
514 
523 HWLOC_DECLSPEC int
525 
534 HWLOC_DECLSPEC int
536 
543 HWLOC_DECLSPEC int
545 
552 HWLOC_DECLSPEC int
554 
561 HWLOC_DECLSPEC int
563 
593 static __hwloc_inline int
595  unsigned cachelevel, hwloc_obj_cache_type_t cachetype)
596 {
597  int depth;
598  int found = HWLOC_TYPE_DEPTH_UNKNOWN;
599  for (depth=0; ; depth++) {
600  hwloc_obj_t obj = hwloc_get_obj_by_depth(topology, depth, 0);
601  if (!obj)
602  break;
603  if (!hwloc_obj_type_is_dcache(obj->type) || obj->attr->cache.depth != cachelevel)
604  /* doesn't match, try next depth */
605  continue;
606  if (cachetype == (hwloc_obj_cache_type_t) -1) {
607  if (found != HWLOC_TYPE_DEPTH_UNKNOWN) {
608  /* second match, return MULTIPLE */
610  }
611  /* first match, mark it as found */
612  found = depth;
613  continue;
614  }
615  if (obj->attr->cache.type == cachetype || obj->attr->cache.type == HWLOC_OBJ_CACHE_UNIFIED)
616  /* exact match (either unified is alone, or we match instruction or data), return immediately */
617  return depth;
618  }
619  /* went to the bottom, return what we found */
620  return found;
621 }
622 
627 static __hwloc_inline hwloc_obj_t
628 hwloc_get_cache_covering_cpuset (hwloc_topology_t topology, hwloc_const_cpuset_t set) __hwloc_attribute_pure;
629 static __hwloc_inline hwloc_obj_t
631 {
632  hwloc_obj_t current = hwloc_get_obj_covering_cpuset(topology, set);
633  while (current) {
634  if (hwloc_obj_type_is_dcache(current->type))
635  return current;
636  current = current->parent;
637  }
638  return NULL;
639 }
640 
645 static __hwloc_inline hwloc_obj_t
646 hwloc_get_shared_cache_covering_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj) __hwloc_attribute_pure;
647 static __hwloc_inline hwloc_obj_t
648 hwloc_get_shared_cache_covering_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj)
649 {
650  hwloc_obj_t current = obj->parent;
651  if (!obj->cpuset)
652  return NULL;
653  while (current) {
654  if (!hwloc_bitmap_isequal(current->cpuset, obj->cpuset)
655  && hwloc_obj_type_is_dcache(current->type))
656  return current;
657  current = current->parent;
658  }
659  return NULL;
660 }
661 
691 HWLOC_DECLSPEC int hwloc_bitmap_singlify_per_core(hwloc_topology_t topology, hwloc_bitmap_t cpuset, unsigned which);
692 
702 static __hwloc_inline hwloc_obj_t
703 hwloc_get_pu_obj_by_os_index(hwloc_topology_t topology, unsigned os_index) __hwloc_attribute_pure;
704 static __hwloc_inline hwloc_obj_t
706 {
707  hwloc_obj_t obj = NULL;
708  while ((obj = hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_PU, obj)) != NULL)
709  if (obj->os_index == os_index)
710  return obj;
711  return NULL;
712 }
713 
723 static __hwloc_inline hwloc_obj_t
724 hwloc_get_numanode_obj_by_os_index(hwloc_topology_t topology, unsigned os_index) __hwloc_attribute_pure;
725 static __hwloc_inline hwloc_obj_t
727 {
728  hwloc_obj_t obj = NULL;
729  while ((obj = hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_NUMANODE, obj)) != NULL)
730  if (obj->os_index == os_index)
731  return obj;
732  return NULL;
733 }
734 
746 /* TODO: rather provide an iterator? Provide a way to know how much should be allocated? By returning the total number of objects instead? */
747 HWLOC_DECLSPEC unsigned hwloc_get_closest_objs (hwloc_topology_t topology, hwloc_obj_t src, hwloc_obj_t * __hwloc_restrict objs, unsigned max);
748 
761 static __hwloc_inline hwloc_obj_t
763  hwloc_obj_type_t type1, unsigned idx1,
764  hwloc_obj_type_t type2, unsigned idx2) __hwloc_attribute_pure;
765 static __hwloc_inline hwloc_obj_t
767  hwloc_obj_type_t type1, unsigned idx1,
768  hwloc_obj_type_t type2, unsigned idx2)
769 {
770  hwloc_obj_t obj;
771  obj = hwloc_get_obj_by_type (topology, type1, idx1);
772  if (!obj)
773  return NULL;
774  return hwloc_get_obj_inside_cpuset_by_type(topology, obj->cpuset, type2, idx2);
775 }
776 
795 static __hwloc_inline hwloc_obj_t
796 hwloc_get_obj_below_array_by_type (hwloc_topology_t topology, int nr, hwloc_obj_type_t *typev, unsigned *idxv) __hwloc_attribute_pure;
797 static __hwloc_inline hwloc_obj_t
798 hwloc_get_obj_below_array_by_type (hwloc_topology_t topology, int nr, hwloc_obj_type_t *typev, unsigned *idxv)
799 {
800  hwloc_obj_t obj = hwloc_get_root_obj(topology);
801  int i;
802  for(i=0; i<nr; i++) {
803  if (!obj)
804  return NULL;
805  obj = hwloc_get_obj_inside_cpuset_by_type(topology, obj->cpuset, typev[i], idxv[i]);
806  }
807  return obj;
808 }
809 
848 HWLOC_DECLSPEC hwloc_obj_t
850  hwloc_obj_type_t type, const char *subtype, const char *nameprefix,
851  unsigned long flags);
852 
867  HWLOC_DISTRIB_FLAG_REVERSE = (1UL<<0)
868 };
869 
893 static __hwloc_inline int
895  hwloc_obj_t *roots, unsigned n_roots,
896  hwloc_cpuset_t *set,
897  unsigned n,
898  int until, unsigned long flags)
899 {
900  unsigned i;
901  unsigned tot_weight;
902  unsigned given, givenweight;
903  hwloc_cpuset_t *cpusetp = set;
904 
905  if (flags & ~HWLOC_DISTRIB_FLAG_REVERSE) {
906  errno = EINVAL;
907  return -1;
908  }
909 
910  tot_weight = 0;
911  for (i = 0; i < n_roots; i++)
912  tot_weight += (unsigned) hwloc_bitmap_weight(roots[i]->cpuset);
913 
914  for (i = 0, given = 0, givenweight = 0; i < n_roots; i++) {
915  unsigned chunk, weight;
916  hwloc_obj_t root = roots[flags & HWLOC_DISTRIB_FLAG_REVERSE ? n_roots-1-i : i];
917  hwloc_cpuset_t cpuset = root->cpuset;
918  while (!hwloc_obj_type_is_normal(root->type))
919  /* If memory/io/misc, walk up to normal parent */
920  root = root->parent;
921  weight = (unsigned) hwloc_bitmap_weight(cpuset);
922  if (!weight)
923  continue;
924  /* Give to root a chunk proportional to its weight.
925  * If previous chunks got rounded-up, we may get a bit less. */
926  chunk = (( (givenweight+weight) * n + tot_weight-1) / tot_weight)
927  - (( givenweight * n + tot_weight-1) / tot_weight);
928  if (!root->arity || chunk <= 1 || root->depth >= until) {
929  /* We can't split any more, put everything there. */
930  if (chunk) {
931  /* Fill cpusets with ours */
932  unsigned j;
933  for (j=0; j < chunk; j++)
934  cpusetp[j] = hwloc_bitmap_dup(cpuset);
935  } else {
936  /* We got no chunk, just merge our cpuset to a previous one
937  * (the first chunk cannot be empty)
938  * so that this root doesn't get ignored.
939  */
940  assert(given);
941  hwloc_bitmap_or(cpusetp[-1], cpusetp[-1], cpuset);
942  }
943  } else {
944  /* Still more to distribute, recurse into children */
945  hwloc_distrib(topology, root->children, root->arity, cpusetp, chunk, until, flags);
946  }
947  cpusetp += chunk;
948  given += chunk;
949  givenweight += weight;
950  }
951 
952  return 0;
953 }
954 
972 HWLOC_DECLSPEC hwloc_const_cpuset_t
973 hwloc_topology_get_complete_cpuset(hwloc_topology_t topology) __hwloc_attribute_pure;
974 
986 HWLOC_DECLSPEC hwloc_const_cpuset_t
987 hwloc_topology_get_topology_cpuset(hwloc_topology_t topology) __hwloc_attribute_pure;
988 
1005 HWLOC_DECLSPEC hwloc_const_cpuset_t
1006 hwloc_topology_get_allowed_cpuset(hwloc_topology_t topology) __hwloc_attribute_pure;
1007 
1017 HWLOC_DECLSPEC hwloc_const_nodeset_t
1019 
1031 HWLOC_DECLSPEC hwloc_const_nodeset_t
1033 
1050 HWLOC_DECLSPEC hwloc_const_nodeset_t
1051 hwloc_topology_get_allowed_nodeset(hwloc_topology_t topology) __hwloc_attribute_pure;
1052 
1073 static __hwloc_inline int
1075 {
1077  hwloc_obj_t obj = NULL;
1078  assert(depth != HWLOC_TYPE_DEPTH_UNKNOWN);
1080  while ((obj = hwloc_get_next_obj_covering_cpuset_by_depth(topology, _cpuset, depth, obj)) != NULL)
1081  if (hwloc_bitmap_set(nodeset, obj->os_index) < 0)
1082  return -1;
1083  return 0;
1084 }
1085 
1097 static __hwloc_inline int
1099 {
1101  hwloc_obj_t obj = NULL;
1102  assert(depth != HWLOC_TYPE_DEPTH_UNKNOWN);
1103  hwloc_bitmap_zero(_cpuset);
1104  while ((obj = hwloc_get_next_obj_by_depth(topology, depth, obj)) != NULL) {
1105  if (hwloc_bitmap_isset(nodeset, obj->os_index))
1106  /* no need to check obj->cpuset because objects in levels always have a cpuset */
1107  if (hwloc_bitmap_or(_cpuset, _cpuset, obj->cpuset) < 0)
1108  return -1;
1109  }
1110  return 0;
1111 }
1112 
1132 static __hwloc_inline hwloc_obj_t
1133 hwloc_get_non_io_ancestor_obj(hwloc_topology_t topology __hwloc_attribute_unused,
1134  hwloc_obj_t ioobj)
1135 {
1136  hwloc_obj_t obj = ioobj;
1137  while (obj && !obj->cpuset) {
1138  obj = obj->parent;
1139  }
1140  return obj;
1141 }
1142 
1147 static __hwloc_inline hwloc_obj_t
1149 {
1150  return hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_PCI_DEVICE, prev);
1151 }
1152 
1156 static __hwloc_inline hwloc_obj_t
1158  unsigned domain, unsigned bus, unsigned dev, unsigned func)
1159 {
1160  hwloc_obj_t obj = NULL;
1161  while ((obj = hwloc_get_next_pcidev(topology, obj)) != NULL) {
1162  if (obj->attr->pcidev.domain == domain
1163  && obj->attr->pcidev.bus == bus
1164  && obj->attr->pcidev.dev == dev
1165  && obj->attr->pcidev.func == func)
1166  return obj;
1167  }
1168  return NULL;
1169 }
1170 
1174 static __hwloc_inline hwloc_obj_t
1176 {
1177  unsigned domain = 0; /* default */
1178  unsigned bus, dev, func;
1179 
1180  if (sscanf(busid, "%x:%x.%x", &bus, &dev, &func) != 3
1181  && sscanf(busid, "%x:%x:%x.%x", &domain, &bus, &dev, &func) != 4) {
1182  errno = EINVAL;
1183  return NULL;
1184  }
1185 
1186  return hwloc_get_pcidev_by_busid(topology, domain, bus, dev, func);
1187 }
1188 
1193 static __hwloc_inline hwloc_obj_t
1195 {
1196  return hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_OS_DEVICE, prev);
1197 }
1198 
1203 static __hwloc_inline hwloc_obj_t
1205 {
1206  return hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_BRIDGE, prev);
1207 }
1208 
1209 /* \brief Checks whether a given bridge covers a given PCI bus.
1210  */
1211 static __hwloc_inline int
1213  unsigned domain, unsigned bus)
1214 {
1215  return bridge->type == HWLOC_OBJ_BRIDGE
1217  && bridge->attr->bridge.downstream.pci.domain == domain
1218  && bridge->attr->bridge.downstream.pci.secondary_bus <= bus
1219  && bridge->attr->bridge.downstream.pci.subordinate_bus >= bus;
1220 }
1221 
1226 #ifdef __cplusplus
1227 } /* extern "C" */
1228 #endif
1229 
1230 
1231 #endif /* HWLOC_HELPER_H */
hwloc_const_bitmap_t hwloc_const_cpuset_t
A non-modifiable hwloc_cpuset_t.
Definition: hwloc.h:142
hwloc_const_bitmap_t hwloc_const_nodeset_t
A non-modifiable hwloc_nodeset_t.
Definition: hwloc.h:160
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:157
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:140
enum hwloc_obj_cache_type_e hwloc_obj_cache_type_t
Cache type.
hwloc_obj_type_t
Type of topology object.
Definition: hwloc.h:176
@ HWLOC_OBJ_BRIDGE_PCI
PCI-side of a bridge.
Definition: hwloc.h:335
@ HWLOC_OBJ_CACHE_UNIFIED
Unified cache.
Definition: hwloc.h:327
@ HWLOC_OBJ_MISC
Miscellaneous objects (filtered out by default). Objects without particular meaning,...
Definition: hwloc.h:290
@ HWLOC_OBJ_OS_DEVICE
Operating system device (filtered out by default).
Definition: hwloc.h:279
@ HWLOC_OBJ_PCI_DEVICE
PCI device (filtered out by default).
Definition: hwloc.h:269
@ HWLOC_OBJ_BRIDGE
Bridge (filtered out by default). Any bridge (or PCI switch) that connects the host or an I/O bus,...
Definition: hwloc.h:257
@ HWLOC_OBJ_NUMANODE
NUMA node. An object that contains memory that is directly and byte-accessible to the host processors...
Definition: hwloc.h:236
@ HWLOC_OBJ_PU
Processing Unit, or (Logical) Processor. An execution unit (may share a core with some other logical ...
Definition: hwloc.h:201
struct hwloc_topology * hwloc_topology_t
Topology context.
Definition: hwloc.h:692
static hwloc_obj_t hwloc_get_root_obj(hwloc_topology_t topology)
Returns the top-object of the topology-tree.
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.
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 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.
int hwloc_get_type_depth(hwloc_topology_t topology, hwloc_obj_type_t type)
Returns the depth of objects of type type.
static hwloc_obj_t hwloc_get_next_obj_by_depth(hwloc_topology_t topology, int depth, hwloc_obj_t prev)
Returns the next object at depth depth.
@ HWLOC_TYPE_DEPTH_UNKNOWN
No object of given type exists in the topology.
Definition: hwloc.h:822
@ HWLOC_TYPE_DEPTH_MULTIPLE
Objects of given type exist at different depth in the topology (only for Groups).
Definition: hwloc.h:823
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:216
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:164
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.
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:244
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:42
static hwloc_obj_t hwloc_get_next_obj_inside_cpuset_by_depth(hwloc_topology_t topology, hwloc_const_cpuset_t set, int depth, hwloc_obj_t prev)
Return the next object at depth depth included in CPU set set.
Definition: helper.h:85
static unsigned hwloc_get_nbobjs_inside_cpuset_by_depth(hwloc_topology_t topology, hwloc_const_cpuset_t set, int depth)
Return the number of objects at depth depth included in CPU set set.
Definition: helper.h:185
static hwloc_obj_t hwloc_get_obj_inside_cpuset_by_depth(hwloc_topology_t topology, hwloc_const_cpuset_t set, int depth, unsigned idx)
Return the (logically) idx -th object at depth depth included in CPU set set.
Definition: helper.h:130
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
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:275
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:297
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:348
static hwloc_obj_t hwloc_get_next_obj_covering_cpuset_by_depth(hwloc_topology_t topology, hwloc_const_cpuset_t set, int depth, hwloc_obj_t prev)
Iterate through same-depth objects covering at least CPU set set.
Definition: helper.h:321
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:456
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:440
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:400
static hwloc_obj_t hwloc_get_ancestor_obj_by_depth(hwloc_topology_t topology, int depth, hwloc_obj_t obj)
Returns the ancestor object of obj at depth depth.
Definition: helper.h:380
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 obj1 and obj2.
Definition: helper.h:412
int hwloc_obj_type_is_memory(hwloc_obj_type_t type)
Check whether an object type is Memory.
int hwloc_obj_type_is_cache(hwloc_obj_type_t type)
Check whether an object type is a CPU Cache (Data, Unified or Instruction).
int hwloc_obj_type_is_dcache(hwloc_obj_type_t type)
Check whether an object type is a CPU Data or Unified Cache.
int hwloc_obj_type_is_normal(hwloc_obj_type_t type)
Check whether an object type is Normal.
int hwloc_obj_type_is_icache(hwloc_obj_type_t type)
Check whether an object type is a CPU Instruction Cache,.
int hwloc_obj_type_is_io(hwloc_obj_type_t type)
Check whether an object type is I/O.
static hwloc_obj_t hwloc_get_shared_cache_covering_obj(hwloc_topology_t topology, hwloc_obj_t obj)
Get the first data (or unified) cache shared between an object and somebody else.
Definition: helper.h:648
static hwloc_obj_t hwloc_get_cache_covering_cpuset(hwloc_topology_t topology, hwloc_const_cpuset_t set)
Get the first data (or unified) cache covering a cpuset set.
Definition: helper.h:630
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 level and type.
Definition: helper.h:594
int hwloc_bitmap_singlify_per_core(hwloc_topology_t topology, hwloc_bitmap_t cpuset, unsigned which)
Remove simultaneous multithreading PUs from a CPU set.
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.
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:705
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:766
hwloc_obj_t hwloc_get_obj_with_same_locality(hwloc_topology_t topology, hwloc_obj_t src, hwloc_obj_type_t type, const char *subtype, const char *nameprefix, unsigned long flags)
Return an object of a different type with same locality.
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_NUMANODE with os_index.
Definition: helper.h:726
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:798
static int hwloc_distrib(hwloc_topology_t topology, hwloc_obj_t *roots, unsigned n_roots, hwloc_cpuset_t *set, unsigned n, int until, unsigned long flags)
Distribute n items over the topology under roots.
Definition: helper.h:894
hwloc_distrib_flags_e
Flags to be given to hwloc_distrib().
Definition: helper.h:863
@ HWLOC_DISTRIB_FLAG_REVERSE
Distrib in reverse order, starting from the last objects.
Definition: helper.h:867
hwloc_const_nodeset_t hwloc_topology_get_allowed_nodeset(hwloc_topology_t topology)
Get allowed node set.
hwloc_const_nodeset_t hwloc_topology_get_topology_nodeset(hwloc_topology_t topology)
Get topology node set.
hwloc_const_cpuset_t hwloc_topology_get_allowed_cpuset(hwloc_topology_t topology)
Get allowed CPU set.
hwloc_const_nodeset_t hwloc_topology_get_complete_nodeset(hwloc_topology_t topology)
Get complete node set.
hwloc_const_cpuset_t hwloc_topology_get_topology_cpuset(hwloc_topology_t topology)
Get topology CPU set.
hwloc_const_cpuset_t hwloc_topology_get_complete_cpuset(hwloc_topology_t topology)
Get complete CPU set.
static int 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.
Definition: helper.h:1074
static int 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.
Definition: helper.h:1098
static int hwloc_bridge_covers_pcibus(hwloc_obj_t bridge, unsigned domain, unsigned bus)
Definition: helper.h:1212
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:1175
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:1148
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:1194
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:1204
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:1157
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:1133
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.
int hwloc_bitmap_set(hwloc_bitmap_t bitmap, unsigned id)
Add index id in bitmap bitmap.
int hwloc_bitmap_isset(hwloc_const_bitmap_t bitmap, unsigned id)
Test whether index id is part of bitmap bitmap.
int 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.
int hwloc_bitmap_isequal(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2)
Test whether bitmap bitmap1 is equal to bitmap bitmap2.
int hwloc_bitmap_iszero(hwloc_const_bitmap_t bitmap)
Test whether bitmap bitmap is empty.
struct hwloc_bitmap_s * hwloc_bitmap_t
Set of bits represented as an opaque pointer to an internal bitmap.
Definition: bitmap.h:68
void hwloc_bitmap_zero(hwloc_bitmap_t bitmap)
Empty the bitmap bitmap.
hwloc_bitmap_t hwloc_bitmap_dup(hwloc_const_bitmap_t bitmap)
Duplicate bitmap bitmap by allocating a new bitmap and copying bitmap contents.
int hwloc_bitmap_intersects(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2)
Test whether bitmaps bitmap1 and bitmap2 intersects.
Structure of a topology object.
Definition: hwloc.h:396
struct hwloc_obj ** children
Normal children, children[0 .. arity -1].
Definition: hwloc.h:456
hwloc_nodeset_t nodeset
NUMA nodes covered by this object or containing this object.
Definition: hwloc.h:540
int depth
Vertical index in the hierarchy.
Definition: hwloc.h:419
struct hwloc_obj * misc_first_child
First Misc child. Misc objects are listed here (misc_arity and misc_first_child) instead of in the no...
Definition: hwloc.h:505
char * subtype
Subtype string to better describe the type field.
Definition: hwloc.h:399
unsigned os_index
OS-provided physical index number. It is not guaranteed unique across the entire machine,...
Definition: hwloc.h:401
hwloc_cpuset_t cpuset
CPUs covered by this object.
Definition: hwloc.h:512
struct hwloc_obj * next_sibling
Next object below the same parent (inside the same list of children).
Definition: hwloc.h:448
struct hwloc_obj * next_cousin
Next object of same type and depth.
Definition: hwloc.h:442
struct hwloc_obj * io_first_child
First I/O child. Bridges, PCI and OS devices are listed here (io_arity and io_first_child) instead of...
Definition: hwloc.h:493
unsigned arity
Number of normal children. Memory, Misc and I/O children are not listed here but rather in their dedi...
Definition: hwloc.h:452
struct hwloc_obj * memory_first_child
First Memory child. NUMA nodes and Memory-side caches are listed here (memory_arity and memory_first_...
Definition: hwloc.h:475
struct hwloc_obj * prev_cousin
Previous object of same type and depth.
Definition: hwloc.h:443
hwloc_obj_type_t type
Type of object.
Definition: hwloc.h:398
union hwloc_obj_attr_u * attr
Object type-specific Attributes, may be NULL if no attribute value was found.
Definition: hwloc.h:415
struct hwloc_obj * parent
Parent, NULL if root (Machine object)
Definition: hwloc.h:446
struct hwloc_obj * first_child
First normal child.
Definition: hwloc.h:457
struct hwloc_obj_attr_u::hwloc_pcidev_attr_s pcidev
struct hwloc_obj_attr_u::hwloc_bridge_attr_s bridge
struct hwloc_obj_attr_u::hwloc_cache_attr_s cache
unsigned depth
Depth of cache (e.g., L1, L2, ...etc.)
Definition: hwloc.h:618
hwloc_obj_cache_type_t type
Cache type.
Definition: hwloc.h:622
unsigned char dev
Definition: hwloc.h:639
unsigned char func
Definition: hwloc.h:639
unsigned short domain
Definition: hwloc.h:635
unsigned char bus
Definition: hwloc.h:639
union hwloc_obj_attr_u::hwloc_bridge_attr_s::@1 downstream
struct hwloc_pcidev_attr_s pci
Definition: hwloc.h:648
hwloc_obj_bridge_type_t downstream_type
Definition: hwloc.h:661