Update hwloc to v1.11.12
[charm.git] / contrib / hwloc / include / hwloc.h
blobf96d6ef126fca42278da405d4686f6979b1cb78c
1 /*
2 * Copyright © 2009 CNRS
3 * Copyright © 2009-2018 Inria. All rights reserved.
4 * Copyright © 2009-2012 Université Bordeaux
5 * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
6 * See COPYING in top-level directory.
7 */
9 /*=====================================================================
10 * PLEASE GO READ THE DOCUMENTATION!
11 * ------------------------------------------------
12 * $tarball_directory/doc/doxygen-doc/
13 * or
14 * http://www.open-mpi.org/projects/hwloc/doc/
15 *=====================================================================
17 * FAIR WARNING: Do NOT expect to be able to figure out all the
18 * subtleties of hwloc by simply reading function prototypes and
19 * constant descrptions here in this file.
21 * Hwloc has wonderful documentation in both PDF and HTML formats for
22 * your reading pleasure. The formal documentation explains a LOT of
23 * hwloc-specific concepts, provides definitions, and discusses the
24 * "big picture" for many of the things that you'll find here in this
25 * header file.
27 * The PDF/HTML documentation was generated via Doxygen; much of what
28 * you'll see in there is also here in this file. BUT THERE IS A LOT
29 * THAT IS IN THE PDF/HTML THAT IS ***NOT*** IN hwloc.h!
31 * There are entire paragraph-length descriptions, discussions, and
32 * pretty prictures to explain subtle corner cases, provide concrete
33 * examples, etc.
35 * Please, go read the documentation. :-)
37 * Moreover there are several examples of hwloc use under doc/examples
38 * in the source tree.
40 *=====================================================================*/
42 /** \file
43 * \brief The hwloc API.
45 * See hwloc/bitmap.h for bitmap specific macros.
46 * See hwloc/helper.h for high-level topology traversal helpers.
47 * See hwloc/inlines.h for the actual inline code of some functions below.
50 #ifndef HWLOC_H
51 #define HWLOC_H
53 #include <hwloc/autogen/config.h>
54 #include <sys/types.h>
55 #include <stdio.h>
56 #include <string.h>
57 #include <limits.h>
60 * Symbol transforms
62 #include <hwloc/rename.h>
65 * Bitmap definitions
68 #include <hwloc/bitmap.h>
71 #ifdef __cplusplus
72 extern "C" {
73 #endif
76 /** \defgroup hwlocality_api_version API version
77 * @{
80 /** \brief Indicate at build time which hwloc API version is being used.
82 * This number is updated to (X>>16)+(Y>>8)+Z when a new release X.Y.Z
83 * actually modifies the API.
85 * Users may check for available features at build time using this number
86 * (see \ref faq_upgrade).
88 #define HWLOC_API_VERSION 0x00010b06
90 /** \brief Indicate at runtime which hwloc API version was used at build time.
92 * Should be ::HWLOC_API_VERSION if running on the same version.
94 HWLOC_DECLSPEC unsigned hwloc_get_api_version(void);
96 /** \brief Current component and plugin ABI version (see hwloc/plugins.h) */
97 #define HWLOC_COMPONENT_ABI 4
99 /** @} */
103 /** \defgroup hwlocality_object_sets Object Sets (hwloc_cpuset_t and hwloc_nodeset_t)
105 * Hwloc uses bitmaps to represent two distinct kinds of object sets:
106 * CPU sets (::hwloc_cpuset_t) and NUMA node sets (::hwloc_nodeset_t).
107 * These types are both typedefs to a common back end type
108 * (::hwloc_bitmap_t), and therefore all the hwloc bitmap functions
109 * are applicable to both ::hwloc_cpuset_t and ::hwloc_nodeset_t (see
110 * \ref hwlocality_bitmap).
112 * The rationale for having two different types is that even though
113 * the actions one wants to perform on these types are the same (e.g.,
114 * enable and disable individual items in the set/mask), they're used
115 * in very different contexts: one for specifying which processors to
116 * use and one for specifying which NUMA nodes to use. Hence, the
117 * name difference is really just to reflect the intent of where the
118 * type is used.
120 * @{
123 /** \brief A CPU set is a bitmap whose bits are set according to CPU
124 * physical OS indexes.
126 * It may be consulted and modified with the bitmap API as any
127 * ::hwloc_bitmap_t (see hwloc/bitmap.h).
129 * Each bit may be converted into a PU object using
130 * hwloc_get_pu_obj_by_os_index().
132 typedef hwloc_bitmap_t hwloc_cpuset_t;
133 /** \brief A non-modifiable ::hwloc_cpuset_t. */
134 typedef hwloc_const_bitmap_t hwloc_const_cpuset_t;
136 /** \brief A node set is a bitmap whose bits are set according to NUMA
137 * memory node physical OS indexes.
139 * It may be consulted and modified with the bitmap API as any
140 * ::hwloc_bitmap_t (see hwloc/bitmap.h).
141 * Each bit may be converted into a NUMA node object using
142 * hwloc_get_numanode_obj_by_os_index().
144 * When binding memory on a system without any NUMA node
145 * (when the whole memory is considered as a single memory bank),
146 * the nodeset may be either empty (no memory selected)
147 * or full (whole system memory selected).
149 * See also \ref hwlocality_helper_nodeset_convert.
151 typedef hwloc_bitmap_t hwloc_nodeset_t;
152 /** \brief A non-modifiable ::hwloc_nodeset_t.
154 typedef hwloc_const_bitmap_t hwloc_const_nodeset_t;
156 /** @} */
160 /** \defgroup hwlocality_object_types Object Types
161 * @{
164 /** \brief Type of topology object.
166 * \note Do not rely on the ordering or completeness of the values as new ones
167 * may be defined in the future! If you need to compare types, use
168 * hwloc_compare_types() instead.
170 typedef enum {
171 /* ***************************************************************
172 WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
174 If new enum values are added here, you MUST also go update the
175 obj_type_order[] and obj_order_type[] arrays in src/topology.c.
177 WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
178 *************************************************************** */
180 HWLOC_OBJ_SYSTEM, /**< \brief Whole system (may be a cluster of machines).
181 * The whole system that is accessible to hwloc.
182 * That may comprise several machines in SSI systems
183 * like Kerrighed.
185 HWLOC_OBJ_MACHINE, /**< \brief Machine.
186 * The typical root object type.
187 * A set of processors and memory with cache
188 * coherency.
190 HWLOC_OBJ_NUMANODE, /**< \brief NUMA node.
191 * An object that contains memory that is directly
192 * and byte-accessible to the host processors.
193 * It is usually close to some cores (the corresponding objects
194 * are descendants of the NUMA node object in the hwloc tree).
196 * There is always at one such object in the topology
197 * even if the machine is not NUMA.
199 HWLOC_OBJ_PACKAGE, /**< \brief Physical package.
200 * The physical package that usually gets inserted
201 * into a socket on the motherboard.
202 * A processor package usually contains multiple cores.
204 HWLOC_OBJ_CACHE, /**< \brief Cache.
205 * Can be L1i, L1d, L2, L3, ...
207 HWLOC_OBJ_CORE, /**< \brief Core.
208 * A computation unit (may be shared by several
209 * logical processors).
211 HWLOC_OBJ_PU, /**< \brief Processing Unit, or (Logical) Processor.
212 * An execution unit (may share a core with some
213 * other logical processors, e.g. in the case of
214 * an SMT core).
216 * Objects of this kind are always reported and can
217 * thus be used as fallback when others are not.
220 HWLOC_OBJ_GROUP, /**< \brief Group objects.
221 * Objects which do not fit in the above but are
222 * detected by hwloc and are useful to take into
223 * account for affinity. For instance, some operating systems
224 * expose their arbitrary processors aggregation this
225 * way. And hwloc may insert such objects to group
226 * NUMA nodes according to their distances.
227 * See also \ref faq_groups.
229 * These objects are ignored when they do not bring
230 * any structure.
233 HWLOC_OBJ_MISC, /**< \brief Miscellaneous objects.
234 * Objects without particular meaning, that can e.g. be
235 * added by the application for its own use, or by hwloc
236 * for miscellaneous objects such as MemoryModule (DIMMs).
239 HWLOC_OBJ_BRIDGE, /**< \brief Bridge.
240 * Any bridge that connects the host or an I/O bus,
241 * to another I/O bus.
242 * Bridge objects have neither CPU sets nor node sets.
243 * They are not added to the topology unless I/O discovery
244 * is enabled with hwloc_topology_set_flags().
246 HWLOC_OBJ_PCI_DEVICE, /**< \brief PCI device.
247 * These objects have neither CPU sets nor node sets.
248 * They are not added to the topology unless I/O discovery
249 * is enabled with hwloc_topology_set_flags().
251 HWLOC_OBJ_OS_DEVICE, /**< \brief Operating system device.
252 * These objects have neither CPU sets nor node sets.
253 * They are not added to the topology unless I/O discovery
254 * is enabled with hwloc_topology_set_flags().
257 HWLOC_OBJ_TYPE_MAX /**< \private Sentinel value */
259 /* ***************************************************************
260 WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
262 If new enum values are added here, you MUST also go update the
263 obj_type_order[] and obj_order_type[] arrays in src/topology.c.
265 WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
266 *************************************************************** */
267 } hwloc_obj_type_t;
269 /** \brief Cache type. */
270 typedef enum hwloc_obj_cache_type_e {
271 HWLOC_OBJ_CACHE_UNIFIED, /**< \brief Unified cache. */
272 HWLOC_OBJ_CACHE_DATA, /**< \brief Data cache. */
273 HWLOC_OBJ_CACHE_INSTRUCTION /**< \brief Instruction cache.
274 * Only used when the ::HWLOC_TOPOLOGY_FLAG_ICACHES topology flag is set. */
275 } hwloc_obj_cache_type_t;
277 /** \brief Type of one side (upstream or downstream) of an I/O bridge. */
278 typedef enum hwloc_obj_bridge_type_e {
279 HWLOC_OBJ_BRIDGE_HOST, /**< \brief Host-side of a bridge, only possible upstream. */
280 HWLOC_OBJ_BRIDGE_PCI /**< \brief PCI-side of a bridge. */
281 } hwloc_obj_bridge_type_t;
283 /** \brief Type of a OS device. */
284 typedef enum hwloc_obj_osdev_type_e {
285 HWLOC_OBJ_OSDEV_BLOCK, /**< \brief Operating system block device.
286 * For instance "sda" on Linux. */
287 HWLOC_OBJ_OSDEV_GPU, /**< \brief Operating system GPU device.
288 * For instance ":0.0" for a GL display,
289 * "card0" for a Linux DRM device. */
290 HWLOC_OBJ_OSDEV_NETWORK, /**< \brief Operating system network device.
291 * For instance the "eth0" interface on Linux. */
292 HWLOC_OBJ_OSDEV_OPENFABRICS, /**< \brief Operating system openfabrics device.
293 * For instance the "mlx4_0" InfiniBand HCA,
294 * or "hfi1_0" Omni-Path interface on Linux. */
295 HWLOC_OBJ_OSDEV_DMA, /**< \brief Operating system dma engine device.
296 * For instance the "dma0chan0" DMA channel on Linux. */
297 HWLOC_OBJ_OSDEV_COPROC /**< \brief Operating system co-processor device.
298 * For instance "mic0" for a Xeon Phi (MIC) on Linux,
299 * "opencl0d0" for a OpenCL device,
300 * "cuda0" for a CUDA device. */
301 } hwloc_obj_osdev_type_t;
303 /** \brief Compare the depth of two object types
305 * Types shouldn't be compared as they are, since newer ones may be added in
306 * the future. This function returns less than, equal to, or greater than zero
307 * respectively if \p type1 objects usually include \p type2 objects, are the
308 * same as \p type2 objects, or are included in \p type2 objects. If the types
309 * can not be compared (because neither is usually contained in the other),
310 * ::HWLOC_TYPE_UNORDERED is returned. Object types containing CPUs can always
311 * be compared (usually, a system contains machines which contain nodes which
312 * contain packages which contain caches, which contain cores, which contain
313 * processors).
315 * \note ::HWLOC_OBJ_PU will always be the deepest.
316 * \note This does not mean that the actual topology will respect that order:
317 * e.g. as of today cores may also contain caches, and packages may also contain
318 * nodes. This is thus just to be seen as a fallback comparison method.
320 HWLOC_DECLSPEC int hwloc_compare_types (hwloc_obj_type_t type1, hwloc_obj_type_t type2) __hwloc_attribute_const;
322 enum hwloc_compare_types_e {
323 HWLOC_TYPE_UNORDERED = INT_MAX /**< \brief Value returned by hwloc_compare_types() when types can not be compared. \hideinitializer */
326 /** @} */
330 /** \defgroup hwlocality_objects Object Structure and Attributes
331 * @{
334 union hwloc_obj_attr_u;
336 /** \brief Object memory */
337 struct hwloc_obj_memory_s {
338 hwloc_uint64_t total_memory; /**< \brief Total memory (in bytes) in this object and its children */
339 hwloc_uint64_t local_memory; /**< \brief Local memory (in bytes) */
341 /** \brief Size of array \p page_types */
342 unsigned page_types_len;
343 /** \brief Array of local memory page types, \c NULL if no local memory and \p page_types is 0.
345 * The array is sorted by increasing \p size fields.
346 * It contains \p page_types_len slots.
348 struct hwloc_obj_memory_page_type_s {
349 hwloc_uint64_t size; /**< \brief Size of pages */
350 hwloc_uint64_t count; /**< \brief Number of pages of this size */
351 } * page_types;
354 /** \brief Structure of a topology object
356 * Applications must not modify any field except hwloc_obj.userdata.
358 struct hwloc_obj {
359 /* physical information */
360 hwloc_obj_type_t type; /**< \brief Type of object */
362 unsigned os_index; /**< \brief OS-provided physical index number.
363 * It is not guaranteed unique across the entire machine,
364 * except for PUs and NUMA nodes.
366 char *name; /**< \brief Object-specific name if any.
367 * Mostly used for identifying OS devices and Misc objects where
368 * a name string is more useful than numerical indexes.
371 struct hwloc_obj_memory_s memory; /**< \brief Memory attributes */
373 union hwloc_obj_attr_u *attr; /**< \brief Object type-specific Attributes,
374 * may be \c NULL if no attribute value was found */
376 /* global position */
377 unsigned depth; /**< \brief Vertical index in the hierarchy.
379 * For normal objects, this is the depth of the horizontal level
380 * that contains this object and its cousins of the same type.
381 * If the topology is symmetric, this is equal to the parent depth
382 * plus one, and also equal to the number of parent/child links
383 * from the root object to here.
385 * For special objects (I/O and Misc) that are not
386 * in the main tree, this is a special negative value that
387 * corresponds to their dedicated level,
388 * see hwloc_get_type_depth() and ::hwloc_get_type_depth_e.
389 * Those special values can be passed to hwloc functions such
390 * hwloc_get_nbobjs_by_depth() as usual.
392 unsigned logical_index; /**< \brief Horizontal index in the whole list of similar objects,
393 * hence guaranteed unique across the entire machine.
394 * Could be a "cousin_rank" since it's the rank within the "cousin" list below
396 signed os_level; /**< \brief OS-provided physical level, -1 if unknown or meaningless */
398 /* cousins are all objects of the same type (and depth) across the entire topology */
399 struct hwloc_obj *next_cousin; /**< \brief Next object of same type and depth */
400 struct hwloc_obj *prev_cousin; /**< \brief Previous object of same type and depth */
402 /* children of the same parent are siblings, even if they may have different type and depth */
403 struct hwloc_obj *parent; /**< \brief Parent, \c NULL if root (system object) */
404 unsigned sibling_rank; /**< \brief Index in parent's \c children[] array */
405 struct hwloc_obj *next_sibling; /**< \brief Next object below the same parent */
406 struct hwloc_obj *prev_sibling; /**< \brief Previous object below the same parent */
408 /* children array below this object */
409 unsigned arity; /**< \brief Number of children */
410 struct hwloc_obj **children; /**< \brief Children, \c children[0 .. arity -1] */
411 struct hwloc_obj *first_child; /**< \brief First child */
412 struct hwloc_obj *last_child; /**< \brief Last child */
414 /* misc */
415 void *userdata; /**< \brief Application-given private data pointer,
416 * initialized to \c NULL, use it as you wish.
417 * See hwloc_topology_set_userdata_export_callback()
418 * if you wish to export this field to XML. */
420 /* cpusets and nodesets */
421 hwloc_cpuset_t cpuset; /**< \brief CPUs covered by this object
423 * This is the set of CPUs for which there are PU objects in the topology
424 * under this object, i.e. which are known to be physically contained in this
425 * object and known how (the children path between this object and the PU
426 * objects).
428 * If the ::HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM configuration flag is set, some of
429 * these CPUs may be offline, or not allowed for binding, see online_cpuset
430 * and allowed_cpuset.
432 * \note Its value must not be changed, hwloc_bitmap_dup() must be used instead.
434 hwloc_cpuset_t complete_cpuset; /**< \brief The complete CPU set of logical processors of this object,
436 * This includes not only the same as the cpuset field, but also some CPUs for
437 * which topology information is unknown or incomplete, and the CPUs that are
438 * ignored when the ::HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM flag is not set.
439 * Thus no corresponding PU object may be found in the topology, because the
440 * precise position is undefined. It is however known that it would be somewhere
441 * under this object.
443 * \note Its value must not be changed, hwloc_bitmap_dup() must be used instead.
445 hwloc_cpuset_t online_cpuset; /**< \brief The CPU set of online logical processors
447 * This includes the CPUs contained in this object that are online, i.e. draw
448 * power and can execute threads. It may however not be allowed to bind to
449 * them due to administration rules, see allowed_cpuset.
451 * \note Its value must not be changed, hwloc_bitmap_dup() must be used instead.
453 hwloc_cpuset_t allowed_cpuset; /**< \brief The CPU set of allowed logical processors
455 * This includes the CPUs contained in this object which are allowed for
456 * binding, i.e. passing them to the hwloc binding functions should not return
457 * permission errors. This is usually restricted by administration rules.
458 * Some of them may however be offline so binding to them may still not be
459 * possible, see online_cpuset.
461 * \note Its value must not be changed, hwloc_bitmap_dup() must be used instead.
464 hwloc_nodeset_t nodeset; /**< \brief NUMA nodes covered by this object or containing this object
466 * This is the set of NUMA nodes for which there are NUMA node objects in the
467 * topology under or above this object, i.e. which are known to be physically
468 * contained in this object or containing it and known how (the children path
469 * between this object and the NUMA node objects).
471 * In the end, these nodes are those that are close to the current object.
473 * If the ::HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM configuration flag is set, some of
474 * these nodes may not be allowed for allocation, see allowed_nodeset.
476 * If there are no NUMA nodes in the machine, all the memory is close to this
477 * object, so \p nodeset is full.
479 * \note Its value must not be changed, hwloc_bitmap_dup() must be used instead.
481 hwloc_nodeset_t complete_nodeset; /**< \brief The complete NUMA node set of this object,
483 * This includes not only the same as the nodeset field, but also some NUMA
484 * nodes for which topology information is unknown or incomplete, and the nodes
485 * that are ignored when the ::HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM flag is not set.
486 * Thus no corresponding NUMA node object may be found in the topology, because the
487 * precise position is undefined. It is however known that it would be
488 * somewhere under this object.
490 * If there are no NUMA nodes in the machine, all the memory is close to this
491 * object, so \p complete_nodeset is full.
493 * \note Its value must not be changed, hwloc_bitmap_dup() must be used instead.
495 hwloc_nodeset_t allowed_nodeset; /**< \brief The set of allowed NUMA memory nodes
497 * This includes the NUMA memory nodes contained in this object which are
498 * allowed for memory allocation, i.e. passing them to NUMA node-directed
499 * memory allocation should not return permission errors. This is usually
500 * restricted by administration rules.
502 * If there are no NUMA nodes in the machine, all the memory is close to this
503 * object, so \p allowed_nodeset is full.
505 * \note Its value must not be changed, hwloc_bitmap_dup() must be used instead.
508 struct hwloc_distances_s **distances; /**< \brief Distances between all objects at same depth below this object */
509 unsigned distances_count;
511 struct hwloc_obj_info_s *infos; /**< \brief Array of stringified info type=name. */
512 unsigned infos_count; /**< \brief Size of infos array. */
514 int symmetric_subtree; /**< \brief Set if the subtree of objects below this object is symmetric,
515 * which means all children and their children have identical subtrees.
516 * If set in the topology root object, lstopo may export the topology
517 * as a synthetic string.
521 * \brief Convenience typedef; a pointer to a struct hwloc_obj.
523 typedef struct hwloc_obj * hwloc_obj_t;
525 /** \brief Object type-specific Attributes */
526 union hwloc_obj_attr_u {
527 /** \brief Cache-specific Object Attributes */
528 struct hwloc_cache_attr_s {
529 hwloc_uint64_t size; /**< \brief Size of cache in bytes */
530 unsigned depth; /**< \brief Depth of cache (e.g., L1, L2, ...etc.) */
531 unsigned linesize; /**< \brief Cache-line size in bytes. 0 if unknown */
532 int associativity; /**< \brief Ways of associativity,
533 * -1 if fully associative, 0 if unknown */
534 hwloc_obj_cache_type_t type; /**< \brief Cache type */
535 } cache;
536 /** \brief Group-specific Object Attributes */
537 struct hwloc_group_attr_s {
538 unsigned depth; /**< \brief Depth of group object */
539 } group;
540 /** \brief PCI Device specific Object Attributes */
541 struct hwloc_pcidev_attr_s {
542 unsigned short domain;
543 unsigned char bus, dev, func;
544 unsigned short class_id;
545 unsigned short vendor_id, device_id, subvendor_id, subdevice_id;
546 unsigned char revision;
547 float linkspeed; /* in GB/s */
548 } pcidev;
549 /** \brief Bridge specific Object Attribues */
550 struct hwloc_bridge_attr_s {
551 union {
552 struct hwloc_pcidev_attr_s pci;
553 } upstream;
554 hwloc_obj_bridge_type_t upstream_type;
555 union {
556 struct {
557 unsigned short domain;
558 unsigned char secondary_bus, subordinate_bus;
559 } pci;
560 } downstream;
561 hwloc_obj_bridge_type_t downstream_type;
562 unsigned depth;
563 } bridge;
564 /** \brief OS Device specific Object Attributes */
565 struct hwloc_osdev_attr_s {
566 hwloc_obj_osdev_type_t type;
567 } osdev;
570 /** \brief Distances between objects
572 * One object may contain a distance structure describing distances
573 * between all its descendants at a given relative depth. If the
574 * containing object is the root object of the topology, then the
575 * distances are available for all objects in the machine.
577 * If the \p latency pointer is not \c NULL, the pointed array contains
578 * memory latencies (non-zero values), see below.
580 * In the future, some other types of distances may be considered.
581 * In these cases, \p latency may be \c NULL.
583 struct hwloc_distances_s {
584 unsigned relative_depth; /**< \brief Relative depth of the considered objects
585 * below the object containing this distance information. */
586 unsigned nbobjs; /**< \brief Number of objects considered in the matrix.
587 * It is the number of descendant objects at \p relative_depth
588 * below the containing object.
589 * It corresponds to the result of hwloc_get_nbobjs_inside_cpuset_by_depth(). */
591 float *latency; /**< \brief Matrix of latencies between objects, stored as a one-dimension array.
592 * May be \c NULL if the distances considered here are not latencies.
594 * Unless defined by the user, this currently contains latencies
595 * between NUMA nodes (as reported in the System Locality Distance Information Table
596 * (SLIT) in the ACPI specification), which may or may not be accurate.
597 * It corresponds to the latency for accessing the memory of one node
598 * from a core in another node.
600 * Values are normalized to get 1.0 as the minimal value in the matrix.
601 * Latency from i-th to j-th object is stored in slot i*nbobjs+j.
603 float latency_max; /**< \brief The maximal value in the latency matrix. */
604 float latency_base; /**< \brief The multiplier that should be applied to latency matrix
605 * to retrieve the original OS-provided latencies.
606 * Usually 10 on Linux since ACPI SLIT uses 10 for local latency.
610 /** \brief Object info
612 * \sa hwlocality_info_attr
614 struct hwloc_obj_info_s {
615 char *name; /**< \brief Info name */
616 char *value; /**< \brief Info value */
619 /** @} */
623 /** \defgroup hwlocality_creation Topology Creation and Destruction
624 * @{
627 struct hwloc_topology;
628 /** \brief Topology context
630 * To be initialized with hwloc_topology_init() and built with hwloc_topology_load().
632 typedef struct hwloc_topology * hwloc_topology_t;
634 /** \brief Allocate a topology context.
636 * \param[out] topologyp is assigned a pointer to the new allocated context.
638 * \return 0 on success, -1 on error.
640 HWLOC_DECLSPEC int hwloc_topology_init (hwloc_topology_t *topologyp);
642 /** \brief Build the actual topology
644 * Build the actual topology once initialized with hwloc_topology_init() and
645 * tuned with \ref hwlocality_configuration routines.
646 * No other routine may be called earlier using this topology context.
648 * \param topology is the topology to be loaded with objects.
650 * \return 0 on success, -1 on error.
652 * \note On failure, the topology is reinitialized. It should be either
653 * destroyed with hwloc_topology_destroy() or configured and loaded again.
655 * \note This function may be called only once per topology.
657 * \note The binding of the current thread or process may temporarily change
658 * during this call but it will be restored before it returns.
660 * \sa hwlocality_configuration
662 HWLOC_DECLSPEC int hwloc_topology_load(hwloc_topology_t topology);
664 /** \brief Terminate and free a topology context
666 * \param topology is the topology to be freed
668 HWLOC_DECLSPEC void hwloc_topology_destroy (hwloc_topology_t topology);
670 /** \brief Duplicate a topology.
672 * The entire topology structure as well as its objects
673 * are duplicated into a new one.
675 * This is useful for keeping a backup while modifying a topology.
677 * \note Object userdata is not duplicated since hwloc does not know what it point to.
678 * The objects of both old and new topologies will point to the same userdata.
680 HWLOC_DECLSPEC int hwloc_topology_dup(hwloc_topology_t *newtopology, hwloc_topology_t oldtopology);
682 /** \brief Run internal checks on a topology structure
684 * The program aborts if an inconsistency is detected in the given topology.
686 * \param topology is the topology to be checked
688 * \note This routine is only useful to developers.
690 * \note The input topology should have been previously loaded with
691 * hwloc_topology_load().
693 HWLOC_DECLSPEC void hwloc_topology_check(hwloc_topology_t topology);
695 /** @} */
699 /** \defgroup hwlocality_configuration Topology Detection Configuration and Query
701 * Several functions can optionally be called between hwloc_topology_init() and
702 * hwloc_topology_load() to configure how the detection should be performed,
703 * e.g. to ignore some objects types, define a synthetic topology, etc.
705 * If none of them is called, the default is to detect all the objects of the
706 * machine that the caller is allowed to access.
708 * This default behavior may also be modified through environment variables
709 * if the application did not modify it already.
710 * Setting HWLOC_XMLFILE in the environment enforces the discovery from a XML
711 * file as if hwloc_topology_set_xml() had been called.
712 * HWLOC_FSROOT switches to reading the topology from the specified Linux
713 * filesystem root as if hwloc_topology_set_fsroot() had been called.
714 * Finally, HWLOC_THISSYSTEM enforces the return value of
715 * hwloc_topology_is_thissystem().
717 * @{
720 /** \brief Ignore an object type.
722 * Ignore all objects from the given type.
723 * The bottom-level type ::HWLOC_OBJ_PU may not be ignored.
724 * The top-level object of the hierarchy will never be ignored, even if this function
725 * succeeds.
726 * Group objects are always ignored if they do not bring any structure
727 * since they are designed to add structure to the topology.
728 * I/O objects may not be ignored, topology flags should be used to configure
729 * their discovery instead.
731 HWLOC_DECLSPEC int hwloc_topology_ignore_type(hwloc_topology_t topology, hwloc_obj_type_t type);
733 /** \brief Ignore an object type if it does not bring any structure.
735 * Ignore all objects from the given type as long as they do not bring any structure:
736 * Each ignored object should have a single children or be the only child of its parent.
737 * The bottom-level type ::HWLOC_OBJ_PU may not be ignored.
738 * I/O objects may not be ignored, topology flags should be used to configure
739 * their discovery instead.
741 HWLOC_DECLSPEC int hwloc_topology_ignore_type_keep_structure(hwloc_topology_t topology, hwloc_obj_type_t type);
743 /** \brief Ignore all objects that do not bring any structure.
745 * Ignore all objects that do not bring any structure:
746 * This is equivalent to calling hwloc_topology_ignore_type_keep_structure()
747 * for all object types.
749 HWLOC_DECLSPEC int hwloc_topology_ignore_all_keep_structure(hwloc_topology_t topology);
751 /** \brief Flags to be set onto a topology context before load.
753 * Flags should be given to hwloc_topology_set_flags().
754 * They may also be returned by hwloc_topology_get_flags().
756 enum hwloc_topology_flags_e {
757 /** \brief Detect the whole system, ignore reservations and offline settings.
759 * Gather all resources, even if some were disabled by the administrator.
760 * For instance, ignore Linux Cgroup/Cpusets and gather all processors and memory nodes,
761 * and ignore the fact that some resources may be offline.
763 * When this flag is not set, PUs that are disallowed are not added to the topology.
764 * Parent objects (package, core, cache, etc.) are added only if some of their children are allowed.
765 * NUMA nodes are always added but their available memory is set to 0 when disallowed.
767 * If the current topology is exported to XML and reimported later, this flag
768 * should be set again in the reimported topology so that disallowed resources
769 * are reimported as well.
770 * \hideinitializer
772 HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM = (1UL<<0),
774 /** \brief Assume that the selected backend provides the topology for the
775 * system on which we are running.
777 * This forces hwloc_topology_is_thissystem() to return 1, i.e. makes hwloc assume that
778 * the selected backend provides the topology for the system on which we are running,
779 * even if it is not the OS-specific backend but the XML backend for instance.
780 * This means making the binding functions actually call the OS-specific
781 * system calls and really do binding, while the XML backend would otherwise
782 * provide empty hooks just returning success.
784 * Setting the environment variable HWLOC_THISSYSTEM may also result in the
785 * same behavior.
787 * This can be used for efficiency reasons to first detect the topology once,
788 * save it to an XML file, and quickly reload it later through the XML
789 * backend, but still having binding functions actually do bind.
790 * \hideinitializer
792 HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM = (1UL<<1),
794 /** \brief Detect PCI devices.
796 * By default, I/O devices are ignored. This flag enables I/O device
797 * detection using the pci backend. Only the common PCI devices (GPUs,
798 * NICs, block devices, ...) and host bridges (objects that connect the host
799 * objects to an I/O subsystem) will be added to the topology.
800 * Additionally it also enables MemoryModule misc objects.
801 * Uncommon devices and other bridges (such as PCI-to-PCI bridges) will be
802 * ignored.
803 * \hideinitializer
805 HWLOC_TOPOLOGY_FLAG_IO_DEVICES = (1UL<<2),
807 /** \brief Detect PCI bridges.
809 * This flag should be combined with ::HWLOC_TOPOLOGY_FLAG_IO_DEVICES to enable
810 * the detection of both common devices and of all useful bridges (bridges that
811 * have at least one device behind them).
812 * \hideinitializer
814 HWLOC_TOPOLOGY_FLAG_IO_BRIDGES = (1UL<<3),
816 /** \brief Detect the whole PCI hierarchy.
818 * This flag enables detection of all I/O devices (even the uncommon ones
819 * such as DMA channels) and bridges (even those that have no device behind
820 * them) using the pci backend.
821 * This implies ::HWLOC_TOPOLOGY_FLAG_IO_DEVICES.
822 * \hideinitializer
824 HWLOC_TOPOLOGY_FLAG_WHOLE_IO = (1UL<<4),
826 /** \brief Detect instruction caches.
828 * This flag enables detection of Instruction caches,
829 * instead of only Data and Unified caches.
830 * \hideinitializer
832 HWLOC_TOPOLOGY_FLAG_ICACHES = (1UL<<5),
834 /** \brief Get the set of allowed resources from the local operating system even if the topology was loaded from XML or synthetic description.
836 * If the topology was loaded from XML or from a synthetic string,
837 * restrict it by applying the current process restrictions such as
838 * Linux Cgroup/Cpuset.
840 * This is useful when the topology is not loaded directly from
841 * the local machine (e.g. for performance reason) and it comes
842 * with all resources, while the running process is restricted
843 * to only parts of the machine.
845 * This flag is ignored unless ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM is
846 * also set since the loaded topology must match the underlying machine
847 * where restrictions will be gathered from.
849 * Setting the environment variable HWLOC_THISSYSTEM_ALLOWED_RESOURCES
850 * would result in the same behavior.
851 * \hideinitializer
853 HWLOC_TOPOLOGY_FLAG_THISSYSTEM_ALLOWED_RESOURCES = (1UL<<6)
856 /** \brief Set OR'ed flags to non-yet-loaded topology.
858 * Set a OR'ed set of ::hwloc_topology_flags_e onto a topology that was not yet loaded.
860 * If this function is called multiple times, the last invokation will erase
861 * and replace the set of flags that was previously set.
863 * The flags set in a topology may be retrieved with hwloc_topology_get_flags()
865 HWLOC_DECLSPEC int hwloc_topology_set_flags (hwloc_topology_t topology, unsigned long flags);
867 /** \brief Get OR'ed flags of a topology.
869 * Get the OR'ed set of ::hwloc_topology_flags_e of a topology.
871 * \return the flags previously set with hwloc_topology_set_flags().
873 HWLOC_DECLSPEC unsigned long hwloc_topology_get_flags (hwloc_topology_t topology);
875 /** \brief Change which process the topology is viewed from
877 * On some systems, processes may have different views of the machine, for
878 * instance the set of allowed CPUs. By default, hwloc exposes the view from
879 * the current process. Calling hwloc_topology_set_pid() permits to make it
880 * expose the topology of the machine from the point of view of another
881 * process.
883 * \note \p hwloc_pid_t is \p pid_t on Unix platforms,
884 * and \p HANDLE on native Windows platforms.
886 * \note -1 is returned and errno is set to ENOSYS on platforms that do not
887 * support this feature.
889 HWLOC_DECLSPEC int hwloc_topology_set_pid(hwloc_topology_t __hwloc_restrict topology, hwloc_pid_t pid);
891 /** \brief Change the file-system root path when building the topology from sysfs/procfs.
893 * On Linux system, use sysfs and procfs files as if they were mounted on the given
894 * \p fsroot_path instead of the main file-system root. Setting the environment
895 * variable HWLOC_FSROOT may also result in this behavior.
896 * Not using the main file-system root causes hwloc_topology_is_thissystem()
897 * to return 0.
899 * Note that this function does not actually load topology
900 * information; it just tells hwloc where to load it from. You'll
901 * still need to invoke hwloc_topology_load() to actually load the
902 * topology information.
904 * \return -1 with errno set to ENOSYS on non-Linux and on Linux systems that
905 * do not support it.
906 * \return -1 with the appropriate errno if \p fsroot_path cannot be used.
908 * \note For convenience, this backend provides empty binding hooks which just
909 * return success. To have hwloc still actually call OS-specific hooks, the
910 * ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM has to be set to assert that the loaded
911 * file is really the underlying system.
913 * \note On success, the Linux component replaces the previously enabled
914 * component (if any), but the topology is not actually modified until
915 * hwloc_topology_load().
917 HWLOC_DECLSPEC int hwloc_topology_set_fsroot(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict fsroot_path);
919 /** \brief Enable synthetic topology.
921 * Gather topology information from the given \p description,
922 * a space-separated string of numbers describing
923 * the arity of each level.
924 * Each number may be prefixed with a type and a colon to enforce the type
925 * of a level. If only some level types are enforced, hwloc will try to
926 * choose the other types according to usual topologies, but it may fail
927 * and you may have to specify more level types manually.
928 * See also the \ref synthetic.
930 * If \p description was properly parsed and describes a valid topology
931 * configuration, this function returns 0.
932 * Otherwise -1 is returned and errno is set to EINVAL.
934 * Note that this function does not actually load topology
935 * information; it just tells hwloc where to load it from. You'll
936 * still need to invoke hwloc_topology_load() to actually load the
937 * topology information.
939 * \note For convenience, this backend provides empty binding hooks which just
940 * return success.
942 * \note On success, the synthetic component replaces the previously enabled
943 * component (if any), but the topology is not actually modified until
944 * hwloc_topology_load().
946 HWLOC_DECLSPEC int hwloc_topology_set_synthetic(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict description);
948 /** \brief Enable XML-file based topology.
950 * Gather topology information from the XML file given at \p xmlpath.
951 * Setting the environment variable HWLOC_XMLFILE may also result in this behavior.
952 * This file may have been generated earlier with hwloc_topology_export_xml()
953 * or lstopo file.xml.
955 * Note that this function does not actually load topology
956 * information; it just tells hwloc where to load it from. You'll
957 * still need to invoke hwloc_topology_load() to actually load the
958 * topology information.
960 * \return -1 with errno set to EINVAL on failure to read the XML file.
962 * \note See also hwloc_topology_set_userdata_import_callback()
963 * for importing application-specific object userdata.
965 * \note For convenience, this backend provides empty binding hooks which just
966 * return success. To have hwloc still actually call OS-specific hooks, the
967 * ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM has to be set to assert that the loaded
968 * file is really the underlying system.
970 * \note On success, the XML component replaces the previously enabled
971 * component (if any), but the topology is not actually modified until
972 * hwloc_topology_load().
974 HWLOC_DECLSPEC int hwloc_topology_set_xml(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict xmlpath);
976 /** \brief Enable XML based topology using a memory buffer (instead of
977 * a file, as with hwloc_topology_set_xml()).
979 * Gather topology information from the XML memory buffer given at \p
980 * buffer and of length \p size. This buffer may have been filled
981 * earlier with hwloc_topology_export_xmlbuffer().
983 * Note that this function does not actually load topology
984 * information; it just tells hwloc where to load it from. You'll
985 * still need to invoke hwloc_topology_load() to actually load the
986 * topology information.
988 * \return -1 with errno set to EINVAL on failure to read the XML buffer.
990 * \note See also hwloc_topology_set_userdata_import_callback()
991 * for importing application-specific object userdata.
993 * \note For convenience, this backend provides empty binding hooks which just
994 * return success. To have hwloc still actually call OS-specific hooks, the
995 * ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM has to be set to assert that the loaded
996 * file is really the underlying system.
998 * \note On success, the XML component replaces the previously enabled
999 * component (if any), but the topology is not actually modified until
1000 * hwloc_topology_load().
1002 HWLOC_DECLSPEC int hwloc_topology_set_xmlbuffer(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict buffer, int size);
1004 /** \brief Prepare the topology for custom assembly.
1006 * The topology then contains a single root object.
1007 * It must then be built by inserting other topologies with
1008 * hwloc_custom_insert_topology() or single objects with
1009 * hwloc_custom_insert_group_object_by_parent().
1010 * hwloc_topology_load() must be called to finalize the new
1011 * topology as usual.
1013 * \note If nothing is inserted in the topology,
1014 * hwloc_topology_load() will fail with errno set to EINVAL.
1016 * \note The cpuset and nodeset of the root object are NULL because
1017 * these sets are meaningless when assembling multiple topologies.
1019 * \note On success, the custom component replaces the previously enabled
1020 * component (if any), but the topology is not actually modified until
1021 * hwloc_topology_load().
1023 HWLOC_DECLSPEC int hwloc_topology_set_custom(hwloc_topology_t topology);
1025 /** \brief Provide a distance matrix.
1027 * Provide the matrix of distances between a set of objects of the given type.
1028 * \p nbobjs must be at least 2.
1029 * The set may or may not contain all the existing objects of this type.
1030 * The objects are specified by their OS/physical index in the \p os_index
1031 * array. The \p distances matrix follows the same order.
1032 * The distance from object i to object j in the i*nbobjs+j.
1034 * A single latency matrix may be defined for each type.
1035 * If another distance matrix already exists for the given type,
1036 * either because the user specified it or because the OS offers it,
1037 * it will be replaced by the given one.
1038 * If \p nbobjs is \c 0, \p os_index is \c NULL and \p distances is \c NULL,
1039 * the existing distance matrix for the given type is removed.
1041 * \note Distance matrices are ignored in multi-node topologies.
1043 HWLOC_DECLSPEC int hwloc_topology_set_distance_matrix(hwloc_topology_t __hwloc_restrict topology,
1044 hwloc_obj_type_t type, unsigned nbobjs,
1045 unsigned *os_index, float *distances);
1047 /** \brief Does the topology context come from this system?
1049 * \return 1 if this topology context was built using the system
1050 * running this program.
1051 * \return 0 instead (for instance if using another file-system root,
1052 * a XML topology file, or a synthetic topology).
1054 HWLOC_DECLSPEC int hwloc_topology_is_thissystem(hwloc_topology_t __hwloc_restrict topology) __hwloc_attribute_pure;
1056 /** \brief Flags describing actual discovery support for this topology. */
1057 struct hwloc_topology_discovery_support {
1058 /** \brief Detecting the number of PU objects is supported. */
1059 unsigned char pu;
1062 /** \brief Flags describing actual PU binding support for this topology.
1064 * A flag may be set even if the feature isn't supported in all cases
1065 * (e.g. binding to random sets of non-contiguous objects).
1067 struct hwloc_topology_cpubind_support {
1068 /** Binding the whole current process is supported. */
1069 unsigned char set_thisproc_cpubind;
1070 /** Getting the binding of the whole current process is supported. */
1071 unsigned char get_thisproc_cpubind;
1072 /** Binding a whole given process is supported. */
1073 unsigned char set_proc_cpubind;
1074 /** Getting the binding of a whole given process is supported. */
1075 unsigned char get_proc_cpubind;
1076 /** Binding the current thread only is supported. */
1077 unsigned char set_thisthread_cpubind;
1078 /** Getting the binding of the current thread only is supported. */
1079 unsigned char get_thisthread_cpubind;
1080 /** Binding a given thread only is supported. */
1081 unsigned char set_thread_cpubind;
1082 /** Getting the binding of a given thread only is supported. */
1083 unsigned char get_thread_cpubind;
1084 /** Getting the last processors where the whole current process ran is supported */
1085 unsigned char get_thisproc_last_cpu_location;
1086 /** Getting the last processors where a whole process ran is supported */
1087 unsigned char get_proc_last_cpu_location;
1088 /** Getting the last processors where the current thread ran is supported */
1089 unsigned char get_thisthread_last_cpu_location;
1092 /** \brief Flags describing actual memory binding support for this topology.
1094 * A flag may be set even if the feature isn't supported in all cases
1095 * (e.g. binding to random sets of non-contiguous objects).
1097 struct hwloc_topology_membind_support {
1098 /** Binding the whole current process is supported. */
1099 unsigned char set_thisproc_membind;
1100 /** Getting the binding of the whole current process is supported. */
1101 unsigned char get_thisproc_membind;
1102 /** Binding a whole given process is supported. */
1103 unsigned char set_proc_membind;
1104 /** Getting the binding of a whole given process is supported. */
1105 unsigned char get_proc_membind;
1106 /** Binding the current thread only is supported. */
1107 unsigned char set_thisthread_membind;
1108 /** Getting the binding of the current thread only is supported. */
1109 unsigned char get_thisthread_membind;
1110 /** Binding a given memory area is supported. */
1111 unsigned char set_area_membind;
1112 /** Getting the binding of a given memory area is supported. */
1113 unsigned char get_area_membind;
1114 /** Allocating a bound memory area is supported. */
1115 unsigned char alloc_membind;
1116 /** First-touch policy is supported. */
1117 unsigned char firsttouch_membind;
1118 /** Bind policy is supported. */
1119 unsigned char bind_membind;
1120 /** Interleave policy is supported. */
1121 unsigned char interleave_membind;
1122 /** Replication policy is supported. */
1123 unsigned char replicate_membind;
1124 /** Next-touch migration policy is supported. */
1125 unsigned char nexttouch_membind;
1126 /** Migration flags is supported. */
1127 unsigned char migrate_membind;
1128 /** Getting the last NUMA nodes where a memory area was allocated is supported */
1129 unsigned char get_area_memlocation;
1132 /** \brief Set of flags describing actual support for this topology.
1134 * This is retrieved with hwloc_topology_get_support() and will be valid until
1135 * the topology object is destroyed. Note: the values are correct only after
1136 * discovery.
1138 struct hwloc_topology_support {
1139 struct hwloc_topology_discovery_support *discovery;
1140 struct hwloc_topology_cpubind_support *cpubind;
1141 struct hwloc_topology_membind_support *membind;
1144 /** \brief Retrieve the topology support.
1146 * Each flag indicates whether a feature is supported.
1147 * If set to 0, the feature is not supported.
1148 * If set to 1, the feature is supported, but the corresponding
1149 * call may still fail in some corner cases.
1151 * These features are also listed by hwloc-info \--support
1153 HWLOC_DECLSPEC const struct hwloc_topology_support *hwloc_topology_get_support(hwloc_topology_t __hwloc_restrict topology);
1155 /** \brief Set the topology-specific userdata pointer.
1157 * Each topology may store one application-given private data pointer.
1158 * It is initialized to \c NULL.
1159 * hwloc will never modify it.
1161 * Use it as you wish, after hwloc_topology_init() and until hwloc_topolog_destroy().
1163 * This pointer is not exported to XML.
1165 HWLOC_DECLSPEC void hwloc_topology_set_userdata(hwloc_topology_t topology, const void *userdata);
1167 /** \brief Retrieve the topology-specific userdata pointer.
1169 * Retrieve the application-given private data pointer that was
1170 * previously set with hwloc_topology_set_userdata().
1172 HWLOC_DECLSPEC void * hwloc_topology_get_userdata(hwloc_topology_t topology);
1174 /** @} */
1178 /** \defgroup hwlocality_levels Object levels, depths and types
1179 * @{
1181 * Be sure to see the figure in \ref termsanddefs that shows a
1182 * complete topology tree, including depths, child/sibling/cousin
1183 * relationships, and an example of an asymmetric topology where one
1184 * package has fewer caches than its peers.
1187 /** \brief Get the depth of the hierarchical tree of objects.
1189 * This is the depth of ::HWLOC_OBJ_PU objects plus one.
1191 * \note I/O and Misc objects are ignored when computing the depth
1192 * of the tree (they are placed on special levels, or none).
1194 HWLOC_DECLSPEC unsigned hwloc_topology_get_depth(hwloc_topology_t __hwloc_restrict topology) __hwloc_attribute_pure;
1196 /** \brief Returns the depth of objects of type \p type.
1198 * If no object of this type is present on the underlying architecture, or if
1199 * the OS doesn't provide this kind of information, the function returns
1200 * ::HWLOC_TYPE_DEPTH_UNKNOWN.
1202 * If type is absent but a similar type is acceptable, see also
1203 * hwloc_get_type_or_below_depth() and hwloc_get_type_or_above_depth().
1205 * If some objects of the given type exist in different levels,
1206 * for instance L1 and L2 caches, or L1i and L1d caches,
1207 * the function returns ::HWLOC_TYPE_DEPTH_MULTIPLE.
1208 * See hwloc_get_cache_type_depth() in hwloc/helper.h to better handle this
1209 * case.
1211 * If an I/O object type is given, the function returns a virtual value
1212 * because I/O objects are stored in special levels that are not CPU-related.
1213 * This virtual depth may be passed to other hwloc functions such as
1214 * hwloc_get_obj_by_depth() but it should not be considered as an actual
1215 * depth by the application. In particular, it should not be compared with
1216 * any other object depth or with the entire topology depth.
1218 * If ::HWLOC_OBJ_MISC is given, the function returns ::HWLOC_TYPE_DEPTH_UNKNOWN.
1220 HWLOC_DECLSPEC int hwloc_get_type_depth (hwloc_topology_t topology, hwloc_obj_type_t type);
1222 enum hwloc_get_type_depth_e {
1223 HWLOC_TYPE_DEPTH_UNKNOWN = -1, /**< \brief No object of given type exists in the topology. \hideinitializer */
1224 HWLOC_TYPE_DEPTH_MULTIPLE = -2, /**< \brief Objects of given type exist at different depth in the topology. \hideinitializer */
1225 HWLOC_TYPE_DEPTH_BRIDGE = -3, /**< \brief Virtual depth for bridge object level. \hideinitializer */
1226 HWLOC_TYPE_DEPTH_PCI_DEVICE = -4, /**< \brief Virtual depth for PCI device object level. \hideinitializer */
1227 HWLOC_TYPE_DEPTH_OS_DEVICE = -5 /**< \brief Virtual depth for software device object level. \hideinitializer */
1230 /** \brief Returns the depth of objects of type \p type or below
1232 * If no object of this type is present on the underlying architecture, the
1233 * function returns the depth of the first "present" object typically found
1234 * inside \p type.
1236 * This function is only meaningful for normal object types.
1237 * If an I/O object type is given, the corresponding virtual
1238 * depth is always returned (see hwloc_get_type_depth()).
1239 * If ::HWLOC_OBJ_MISC is given, the function returns ::HWLOC_TYPE_DEPTH_UNKNOWN.
1241 * If some objects of the given type exist in different levels, for instance
1242 * L1 and L2 caches, the function returns ::HWLOC_TYPE_DEPTH_MULTIPLE.
1244 static __hwloc_inline int
1245 hwloc_get_type_or_below_depth (hwloc_topology_t topology, hwloc_obj_type_t type) __hwloc_attribute_pure;
1247 /** \brief Returns the depth of objects of type \p type or above
1249 * If no object of this type is present on the underlying architecture, the
1250 * function returns the depth of the first "present" object typically
1251 * containing \p type.
1253 * This function is only meaningful for normal object types.
1254 * If an I/O object type is given, the corresponding virtual
1255 * depth is always returned (see hwloc_get_type_depth()).
1256 * If ::HWLOC_OBJ_MISC is given, the function returns ::HWLOC_TYPE_DEPTH_UNKNOWN.
1258 * If some objects of the given type exist in different levels, for instance
1259 * L1 and L2 caches, the function returns ::HWLOC_TYPE_DEPTH_MULTIPLE.
1261 static __hwloc_inline int
1262 hwloc_get_type_or_above_depth (hwloc_topology_t topology, hwloc_obj_type_t type) __hwloc_attribute_pure;
1264 /** \brief Returns the type of objects at depth \p depth.
1266 * \p depth should between 0 and hwloc_topology_get_depth()-1.
1268 * \return -1 if depth \p depth does not exist.
1270 HWLOC_DECLSPEC hwloc_obj_type_t hwloc_get_depth_type (hwloc_topology_t topology, unsigned depth) __hwloc_attribute_pure;
1272 /** \brief Returns the width of level at depth \p depth.
1274 HWLOC_DECLSPEC unsigned hwloc_get_nbobjs_by_depth (hwloc_topology_t topology, unsigned depth) __hwloc_attribute_pure;
1276 /** \brief Returns the width of level type \p type
1278 * If no object for that type exists, 0 is returned.
1279 * If there are several levels with objects of that type, -1 is returned.
1281 static __hwloc_inline int
1282 hwloc_get_nbobjs_by_type (hwloc_topology_t topology, hwloc_obj_type_t type) __hwloc_attribute_pure;
1284 /** \brief Returns the top-object of the topology-tree.
1286 * Its type is typically ::HWLOC_OBJ_MACHINE but it could be different
1287 * for complex topologies.
1289 static __hwloc_inline hwloc_obj_t
1290 hwloc_get_root_obj (hwloc_topology_t topology) __hwloc_attribute_pure;
1292 /** \brief Returns the topology object at logical index \p idx from depth \p depth */
1293 HWLOC_DECLSPEC hwloc_obj_t hwloc_get_obj_by_depth (hwloc_topology_t topology, unsigned depth, unsigned idx) __hwloc_attribute_pure;
1295 /** \brief Returns the topology object at logical index \p idx with type \p type
1297 * If no object for that type exists, \c NULL is returned.
1298 * If there are several levels with objects of that type, \c NULL is returned
1299 * and ther caller may fallback to hwloc_get_obj_by_depth().
1301 static __hwloc_inline hwloc_obj_t
1302 hwloc_get_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type, unsigned idx) __hwloc_attribute_pure;
1304 /** \brief Returns the next object at depth \p depth.
1306 * If \p prev is \c NULL, return the first object at depth \p depth.
1308 static __hwloc_inline hwloc_obj_t
1309 hwloc_get_next_obj_by_depth (hwloc_topology_t topology, unsigned depth, hwloc_obj_t prev);
1311 /** \brief Returns the next object of type \p type.
1313 * If \p prev is \c NULL, return the first object at type \p type. If
1314 * there are multiple or no depth for given type, return \c NULL and
1315 * let the caller fallback to hwloc_get_next_obj_by_depth().
1317 static __hwloc_inline hwloc_obj_t
1318 hwloc_get_next_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type,
1319 hwloc_obj_t prev);
1321 /** @} */
1325 /** \defgroup hwlocality_object_strings Converting between Object Types, Sets and Attributes, and Strings
1326 * @{
1329 /** \brief Return a constant stringified object type.
1331 * This function is the basic way to convert a generic type into a string.
1333 * hwloc_obj_type_snprintf() may return a more precise output for a specific
1334 * object, but it requires the caller to provide the output buffer.
1336 HWLOC_DECLSPEC const char * hwloc_obj_type_string (hwloc_obj_type_t type) __hwloc_attribute_const;
1338 /** \brief Stringify the type of a given topology object into a human-readable form.
1340 * Contrary to hwloc_obj_type_string(), this function includes object-specific
1341 * attributes (such as the Group depth, the Bridge type, or OS device type)
1342 * in the output, and it requires the caller to provide the output buffer.
1344 * The output is guaranteed to be the same for all objects of a same topology level.
1346 * If \p size is 0, \p string may safely be \c NULL.
1348 * \return the number of character that were actually written if not truncating,
1349 * or that would have been written (not including the ending \\0).
1351 HWLOC_DECLSPEC int hwloc_obj_type_snprintf(char * __hwloc_restrict string, size_t size, hwloc_obj_t obj,
1352 int verbose);
1354 /** \brief Stringify the attributes of a given topology object into a human-readable form.
1356 * Attribute values are separated by \p separator.
1358 * Only the major attributes are printed in non-verbose mode.
1360 * If \p size is 0, \p string may safely be \c NULL.
1362 * \return the number of character that were actually written if not truncating,
1363 * or that would have been written (not including the ending \\0).
1365 HWLOC_DECLSPEC int hwloc_obj_attr_snprintf(char * __hwloc_restrict string, size_t size, hwloc_obj_t obj, const char * __hwloc_restrict separator,
1366 int verbose);
1368 /** \brief Stringify the cpuset containing a set of objects.
1370 * If \p size is 0, \p string may safely be \c NULL.
1372 * \return the number of character that were actually written if not truncating,
1373 * or that would have been written (not including the ending \\0).
1375 HWLOC_DECLSPEC int hwloc_obj_cpuset_snprintf(char * __hwloc_restrict str, size_t size, size_t nobj, const hwloc_obj_t * __hwloc_restrict objs);
1377 /** \brief Return an object type and attributes from a type string.
1379 * Convert strings such as "Package" or "Cache" into the corresponding types.
1380 * Matching is case-insensitive, and only the first letters are actually
1381 * required to match.
1383 * This function is guaranteed to match any string returned by hwloc_obj_type_string()
1384 * or hwloc_obj_type_snprintf().
1386 * Types that have specific attributes, for instance caches and groups,
1387 * may be returned in \p depthattrp and \p typeattrp. They are ignored
1388 * when these pointers are \c NULL.
1390 * For instance "L2i" or "L2iCache" would return
1391 * type HWLOC_OBJ_CACHE in \p typep, 2 in \p depthattrp,
1392 * and HWLOC_OBJ_CACHE_TYPE_INSTRUCTION in \p typeattrp
1393 * (this last pointer should point to a hwloc_obj_cache_type_t).
1394 * "Group3" would return type HWLOC_OBJ_GROUP type and 3 in \p depthattrp.
1395 * Attributes that are not specified in the string (for instance "Group"
1396 * without a depth, or "L2Cache" without a cache type) are set to -1.
1398 * \p typeattrp is only filled if the size specified in \p typeattrsize
1399 * is large enough. It is currently only used for caches, and the required
1400 * size is at least the size of hwloc_obj_cache_type_t.
1402 * \return 0 if a type was correctly identified, otherwise -1.
1404 * \note This is an extended version of the now deprecated hwloc_obj_type_of_string()
1406 HWLOC_DECLSPEC int hwloc_obj_type_sscanf(const char *string,
1407 hwloc_obj_type_t *typep,
1408 int *depthattrp,
1409 void *typeattrp, size_t typeattrsize);
1411 /** @} */
1415 /** \defgroup hwlocality_info_attr Consulting and Adding Key-Value Info Attributes
1417 * @{
1420 /** \brief Search the given key name in object infos and return the corresponding value.
1422 * If multiple keys match the given name, only the first one is returned.
1424 * \return \c NULL if no such key exists.
1426 static __hwloc_inline const char *
1427 hwloc_obj_get_info_by_name(hwloc_obj_t obj, const char *name) __hwloc_attribute_pure;
1429 /** \brief Add the given info name and value pair to the given object.
1431 * The info is appended to the existing info array even if another key
1432 * with the same name already exists.
1434 * The input strings are copied before being added in the object infos.
1436 * \note This function may be used to enforce object colors in the lstopo
1437 * graphical output by using "lstopoStyle" as a name and "Background=#rrggbb"
1438 * as a value. See CUSTOM COLORS in the lstopo(1) manpage for details.
1440 * \note If \p value contains some non-printable characters, they will
1441 * be dropped when exporting to XML, see hwloc_topology_export_xml().
1443 HWLOC_DECLSPEC void hwloc_obj_add_info(hwloc_obj_t obj, const char *name, const char *value);
1445 /** @} */
1449 /** \defgroup hwlocality_cpubinding CPU binding
1451 * Some operating systems only support binding threads or processes to a single PU.
1452 * Others allow binding to larger sets such as entire Cores or Packages or
1453 * even random sets of invididual PUs. In such operating system, the scheduler
1454 * is free to run the task on one of these PU, then migrate it to another PU, etc.
1455 * It is often useful to call hwloc_bitmap_singlify() on the target CPU set before
1456 * passing it to the binding function to avoid these expensive migrations.
1457 * See the documentation of hwloc_bitmap_singlify() for details.
1459 * Some operating systems do not provide all hwloc-supported
1460 * mechanisms to bind processes, threads, etc.
1461 * hwloc_topology_get_support() may be used to query about the actual CPU
1462 * binding support in the currently used operating system.
1464 * When the requested binding operation is not available and the
1465 * ::HWLOC_CPUBIND_STRICT flag was passed, the function returns -1.
1466 * \p errno is set to \c ENOSYS when it is not possible to bind the requested kind of object
1467 * processes/threads. errno is set to \c EXDEV when the requested cpuset
1468 * can not be enforced (e.g. some systems only allow one CPU, and some
1469 * other systems only allow one NUMA node).
1471 * If ::HWLOC_CPUBIND_STRICT was not passed, the function may fail as well,
1472 * or the operating system may use a slightly different operation
1473 * (with side-effects, smaller binding set, etc.)
1474 * when the requested operation is not exactly supported.
1476 * The most portable version that should be preferred over the others,
1477 * whenever possible, is the following one which just binds the current program,
1478 * assuming it is single-threaded:
1480 * \code
1481 * hwloc_set_cpubind(topology, set, 0),
1482 * \endcode
1484 * If the program may be multithreaded, the following one should be preferred
1485 * to only bind the current thread:
1487 * \code
1488 * hwloc_set_cpubind(topology, set, HWLOC_CPUBIND_THREAD),
1489 * \endcode
1491 * \sa Some example codes are available under doc/examples/ in the source tree.
1493 * \note To unbind, just call the binding function with either a full cpuset or
1494 * a cpuset equal to the system cpuset.
1496 * \note On some operating systems, CPU binding may have effects on memory binding, see
1497 * ::HWLOC_CPUBIND_NOMEMBIND
1499 * \note Running lstopo \--top or hwloc-ps can be a very convenient tool to check
1500 * how binding actually happened.
1501 * @{
1504 /** \brief Process/Thread binding flags.
1506 * These bit flags can be used to refine the binding policy.
1508 * The default (0) is to bind the current process, assumed to be
1509 * single-threaded, in a non-strict way. This is the most portable
1510 * way to bind as all operating systems usually provide it.
1512 * \note Not all systems support all kinds of binding. See the
1513 * "Detailed Description" section of \ref hwlocality_cpubinding for a
1514 * description of errors that can occur.
1516 typedef enum {
1517 /** \brief Bind all threads of the current (possibly) multithreaded process.
1518 * \hideinitializer */
1519 HWLOC_CPUBIND_PROCESS = (1<<0),
1521 /** \brief Bind current thread of current process.
1522 * \hideinitializer */
1523 HWLOC_CPUBIND_THREAD = (1<<1),
1525 /** \brief Request for strict binding from the OS.
1527 * By default, when the designated CPUs are all busy while other
1528 * CPUs are idle, operating systems may execute the thread/process
1529 * on those other CPUs instead of the designated CPUs, to let them
1530 * progress anyway. Strict binding means that the thread/process
1531 * will _never_ execute on other cpus than the designated CPUs, even
1532 * when those are busy with other tasks and other CPUs are idle.
1534 * \note Depending on the operating system, strict binding may not
1535 * be possible (e.g., the OS does not implement it) or not allowed
1536 * (e.g., for an administrative reasons), and the function will fail
1537 * in that case.
1539 * When retrieving the binding of a process, this flag checks
1540 * whether all its threads actually have the same binding. If the
1541 * flag is not given, the binding of each thread will be
1542 * accumulated.
1544 * \note This flag is meaningless when retrieving the binding of a
1545 * thread.
1546 * \hideinitializer
1548 HWLOC_CPUBIND_STRICT = (1<<2),
1550 /** \brief Avoid any effect on memory binding
1552 * On some operating systems, some CPU binding function would also
1553 * bind the memory on the corresponding NUMA node. It is often not
1554 * a problem for the application, but if it is, setting this flag
1555 * will make hwloc avoid using OS functions that would also bind
1556 * memory. This will however reduce the support of CPU bindings,
1557 * i.e. potentially return -1 with errno set to ENOSYS in some
1558 * cases.
1560 * This flag is only meaningful when used with functions that set
1561 * the CPU binding. It is ignored when used with functions that get
1562 * CPU binding information.
1563 * \hideinitializer
1565 HWLOC_CPUBIND_NOMEMBIND = (1<<3)
1566 } hwloc_cpubind_flags_t;
1568 /** \brief Bind current process or thread on cpus given in physical bitmap \p set.
1570 * \return -1 with errno set to ENOSYS if the action is not supported
1571 * \return -1 with errno set to EXDEV if the binding cannot be enforced
1573 HWLOC_DECLSPEC int hwloc_set_cpubind(hwloc_topology_t topology, hwloc_const_cpuset_t set, int flags);
1575 /** \brief Get current process or thread binding.
1577 * Writes into \p set the physical cpuset which the process or thread (according to \e
1578 * flags) was last bound to.
1580 HWLOC_DECLSPEC int hwloc_get_cpubind(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
1582 /** \brief Bind a process \p pid on cpus given in physical bitmap \p set.
1584 * \note \p hwloc_pid_t is \p pid_t on Unix platforms,
1585 * and \p HANDLE on native Windows platforms.
1587 * \note As a special case on Linux, if a tid (thread ID) is supplied
1588 * instead of a pid (process ID) and ::HWLOC_CPUBIND_THREAD is passed in flags,
1589 * the binding is applied to that specific thread.
1591 * \note On non-Linux systems, ::HWLOC_CPUBIND_THREAD can not be used in \p flags.
1593 HWLOC_DECLSPEC int hwloc_set_proc_cpubind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_cpuset_t set, int flags);
1595 /** \brief Get the current physical binding of process \p pid.
1597 * \note \p hwloc_pid_t is \p pid_t on Unix platforms,
1598 * and \p HANDLE on native Windows platforms.
1600 * \note As a special case on Linux, if a tid (thread ID) is supplied
1601 * instead of a pid (process ID) and ::HWLOC_CPUBIND_THREAD is passed in flags,
1602 * the binding for that specific thread is returned.
1604 * \note On non-Linux systems, ::HWLOC_CPUBIND_THREAD can not be used in \p flags.
1606 HWLOC_DECLSPEC int hwloc_get_proc_cpubind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t set, int flags);
1608 #ifdef hwloc_thread_t
1609 /** \brief Bind a thread \p thread on cpus given in physical bitmap \p set.
1611 * \note \p hwloc_thread_t is \p pthread_t on Unix platforms,
1612 * and \p HANDLE on native Windows platforms.
1614 * \note ::HWLOC_CPUBIND_PROCESS can not be used in \p flags.
1616 HWLOC_DECLSPEC int hwloc_set_thread_cpubind(hwloc_topology_t topology, hwloc_thread_t thread, hwloc_const_cpuset_t set, int flags);
1617 #endif
1619 #ifdef hwloc_thread_t
1620 /** \brief Get the current physical binding of thread \p tid.
1622 * \note \p hwloc_thread_t is \p pthread_t on Unix platforms,
1623 * and \p HANDLE on native Windows platforms.
1625 * \note ::HWLOC_CPUBIND_PROCESS can not be used in \p flags.
1627 HWLOC_DECLSPEC int hwloc_get_thread_cpubind(hwloc_topology_t topology, hwloc_thread_t thread, hwloc_cpuset_t set, int flags);
1628 #endif
1630 /** \brief Get the last physical CPU where the current process or thread ran.
1632 * The operating system may move some tasks from one processor
1633 * to another at any time according to their binding,
1634 * so this function may return something that is already
1635 * outdated.
1637 * \p flags can include either ::HWLOC_CPUBIND_PROCESS or ::HWLOC_CPUBIND_THREAD to
1638 * specify whether the query should be for the whole process (union of all CPUs
1639 * on which all threads are running), or only the current thread. If the
1640 * process is single-threaded, flags can be set to zero to let hwloc use
1641 * whichever method is available on the underlying OS.
1643 HWLOC_DECLSPEC int hwloc_get_last_cpu_location(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
1645 /** \brief Get the last physical CPU where a process ran.
1647 * The operating system may move some tasks from one processor
1648 * to another at any time according to their binding,
1649 * so this function may return something that is already
1650 * outdated.
1652 * \note \p hwloc_pid_t is \p pid_t on Unix platforms,
1653 * and \p HANDLE on native Windows platforms.
1655 * \note As a special case on Linux, if a tid (thread ID) is supplied
1656 * instead of a pid (process ID) and ::HWLOC_CPUBIND_THREAD is passed in flags,
1657 * the last CPU location of that specific thread is returned.
1659 * \note On non-Linux systems, ::HWLOC_CPUBIND_THREAD can not be used in \p flags.
1661 HWLOC_DECLSPEC int hwloc_get_proc_last_cpu_location(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t set, int flags);
1663 /** @} */
1667 /** \defgroup hwlocality_membinding Memory binding
1669 * Memory binding can be done three ways:
1671 * - explicit memory allocation thanks to hwloc_alloc_membind() and friends:
1672 * the binding will have effect on the memory allocated by these functions.
1673 * - implicit memory binding through binding policy: hwloc_set_membind() and
1674 * friends only define the current policy of the process, which will be
1675 * applied to the subsequent calls to malloc() and friends.
1676 * - migration of existing memory ranges, thanks to hwloc_set_area_membind()
1677 * and friends, which move already-allocated data.
1679 * Not all operating systems support all three ways.
1680 * hwloc_topology_get_support() may be used to query about the actual memory
1681 * binding support in the currently used operating system.
1683 * When the requested binding operation is not available and the
1684 * ::HWLOC_MEMBIND_STRICT flag was passed, the function returns -1.
1685 * \p errno will be set to \c ENOSYS when the system does support
1686 * the specified action or policy
1687 * (e.g., some systems only allow binding memory on a per-thread
1688 * basis, whereas other systems only allow binding memory for all
1689 * threads in a process).
1690 * \p errno will be set to EXDEV when the requested set can not be enforced
1691 * (e.g., some systems only allow binding memory to a single NUMA node).
1693 * If ::HWLOC_MEMBIND_STRICT was not passed, the function may fail as well,
1694 * or the operating system may use a slightly different operation
1695 * (with side-effects, smaller binding set, etc.)
1696 * when the requested operation is not exactly supported.
1698 * The most portable form that should be preferred over the others
1699 * whenever possible is as follows.
1700 * It allocates some memory hopefully bound to the specified set.
1701 * To do so, hwloc will possibly have to change the current memory
1702 * binding policy in order to actually get the memory bound, if the OS
1703 * does not provide any other way to simply allocate bound memory
1704 * without changing the policy for all allocations. That is the
1705 * difference with hwloc_alloc_membind(), which will never change the
1706 * current memory binding policy.
1708 * \code
1709 * hwloc_alloc_membind_policy(topology, size, set,
1710 * HWLOC_MEMBIND_BIND, 0);
1711 * \endcode
1713 * Each hwloc memory binding function is available in two forms: one
1714 * that takes a bitmap argument (a CPU set by default, or a NUMA memory
1715 * node set if the flag ::HWLOC_MEMBIND_BYNODESET is specified),
1716 * and another one (whose name ends with _nodeset) that always takes
1717 * a NUMA memory node set.
1718 * See \ref hwlocality_object_sets and \ref hwlocality_bitmap for a
1719 * discussion of CPU sets and NUMA memory node sets.
1720 * It is also possible to convert between CPU set and node set using
1721 * hwloc_cpuset_to_nodeset() or hwloc_cpuset_from_nodeset().
1723 * Memory binding by CPU set cannot work for CPU-less NUMA memory nodes.
1724 * Binding by nodeset should therefore be preferred whenever possible.
1726 * \sa Some example codes are available under doc/examples/ in the source tree.
1728 * \note On some operating systems, memory binding affects the CPU
1729 * binding; see ::HWLOC_MEMBIND_NOCPUBIND
1730 * @{
1733 /** \brief Memory binding policy.
1735 * These constants can be used to choose the binding policy. Only one policy can
1736 * be used at a time (i.e., the values cannot be OR'ed together).
1738 * Not all systems support all kinds of binding.
1739 * hwloc_topology_get_support() may be used to query about the actual memory
1740 * binding policy support in the currently used operating system.
1741 * See the "Detailed Description" section of \ref hwlocality_membinding
1742 * for a description of errors that can occur.
1744 typedef enum {
1745 /** \brief Reset the memory allocation policy to the system default.
1746 * Depending on the operating system, this may correspond to
1747 * ::HWLOC_MEMBIND_FIRSTTOUCH (Linux),
1748 * or ::HWLOC_MEMBIND_BIND (AIX, HP-UX, OSF, Solaris, Windows).
1749 * This policy is never returned by get membind functions when running
1750 * on normal machines.
1751 * It is only returned when binding hooks are empty because the topology
1752 * was loaded from XML, or HWLOC_THISSYSTEM=0, etc.
1753 * \hideinitializer */
1754 HWLOC_MEMBIND_DEFAULT = 0,
1756 /** \brief Allocate memory
1757 * but do not immediately bind it to a specific locality. Instead,
1758 * each page in the allocation is bound only when it is first
1759 * touched. Pages are individually bound to the local NUMA node of
1760 * the first thread that touches it. If there is not enough memory
1761 * on the node, allocation may be done in the specified nodes
1762 * before allocating on other nodes.
1763 * \hideinitializer */
1764 HWLOC_MEMBIND_FIRSTTOUCH = 1,
1766 /** \brief Allocate memory on the specified nodes.
1767 * \hideinitializer */
1768 HWLOC_MEMBIND_BIND = 2,
1770 /** \brief Allocate memory on the given nodes in an interleaved
1771 * / round-robin manner. The precise layout of the memory across
1772 * multiple NUMA nodes is OS/system specific. Interleaving can be
1773 * useful when threads distributed across the specified NUMA nodes
1774 * will all be accessing the whole memory range concurrently, since
1775 * the interleave will then balance the memory references.
1776 * \hideinitializer */
1777 HWLOC_MEMBIND_INTERLEAVE = 3,
1779 /** \brief Replicate memory on the given nodes; reads from this
1780 * memory will attempt to be serviced from the NUMA node local to
1781 * the reading thread. Replicating can be useful when multiple
1782 * threads from the specified NUMA nodes will be sharing the same
1783 * read-only data.
1785 * This policy can only be used with existing memory allocations
1786 * (i.e., the hwloc_set_*membind*() functions); it cannot be used
1787 * with functions that allocate new memory (i.e., the hwloc_alloc*()
1788 * functions).
1789 * \hideinitializer */
1790 HWLOC_MEMBIND_REPLICATE = 4,
1792 /** \brief For each page bound with this policy, by next time
1793 * it is touched (and next time only), it is moved from its current
1794 * location to the local NUMA node of the thread where the memory
1795 * reference occurred (if it needs to be moved at all).
1796 * \hideinitializer */
1797 HWLOC_MEMBIND_NEXTTOUCH = 5,
1799 /** \brief Returned by get_membind() functions when multiple
1800 * threads or parts of a memory area have differing memory binding
1801 * policies.
1802 * \hideinitializer */
1803 HWLOC_MEMBIND_MIXED = -1
1804 } hwloc_membind_policy_t;
1806 /** \brief Memory binding flags.
1808 * These flags can be used to refine the binding policy.
1809 * All flags can be logically OR'ed together with the exception of
1810 * ::HWLOC_MEMBIND_PROCESS and ::HWLOC_MEMBIND_THREAD;
1811 * these two flags are mutually exclusive.
1813 * Not all systems support all kinds of binding.
1814 * hwloc_topology_get_support() may be used to query about the actual memory
1815 * binding support in the currently used operating system.
1816 * See the "Detailed Description" section of \ref hwlocality_membinding
1817 * for a description of errors that can occur.
1819 typedef enum {
1820 /** \brief Set policy for all threads of the specified (possibly
1821 * multithreaded) process. This flag is mutually exclusive with
1822 * ::HWLOC_MEMBIND_THREAD.
1823 * \hideinitializer */
1824 HWLOC_MEMBIND_PROCESS = (1<<0),
1826 /** \brief Set policy for a specific thread of the current process.
1827 * This flag is mutually exclusive with ::HWLOC_MEMBIND_PROCESS.
1828 * \hideinitializer */
1829 HWLOC_MEMBIND_THREAD = (1<<1),
1831 /** Request strict binding from the OS. The function will fail if
1832 * the binding can not be guaranteed / completely enforced.
1834 * This flag has slightly different meanings depending on which
1835 * function it is used with.
1836 * \hideinitializer */
1837 HWLOC_MEMBIND_STRICT = (1<<2),
1839 /** \brief Migrate existing allocated memory. If the memory cannot
1840 * be migrated and the ::HWLOC_MEMBIND_STRICT flag is passed, an error
1841 * will be returned.
1842 * \hideinitializer */
1843 HWLOC_MEMBIND_MIGRATE = (1<<3),
1845 /** \brief Avoid any effect on CPU binding.
1847 * On some operating systems, some underlying memory binding
1848 * functions also bind the application to the corresponding CPU(s).
1849 * Using this flag will cause hwloc to avoid using OS functions that
1850 * could potentially affect CPU bindings. Note, however, that using
1851 * NOCPUBIND may reduce hwloc's overall memory binding
1852 * support. Specifically: some of hwloc's memory binding functions
1853 * may fail with errno set to ENOSYS when used with NOCPUBIND.
1854 * \hideinitializer
1856 HWLOC_MEMBIND_NOCPUBIND = (1<<4),
1858 /** \brief Consider the bitmap argument as a nodeset.
1860 * Functions whose name ends with _nodeset() take a nodeset argument.
1861 * Other functions take a bitmap argument that is considered a nodeset
1862 * if this flag is given, or a cpuset otherwise.
1864 * Memory binding by CPU set cannot work for CPU-less NUMA memory nodes.
1865 * Binding by nodeset should therefore be preferred whenever possible.
1866 * \hideinitializer
1868 HWLOC_MEMBIND_BYNODESET = (1<<5)
1869 } hwloc_membind_flags_t;
1871 /** \brief Set the default memory binding policy of the current
1872 * process or thread to prefer the NUMA node(s) specified by \p nodeset
1874 * If neither ::HWLOC_MEMBIND_PROCESS nor ::HWLOC_MEMBIND_THREAD is
1875 * specified, the current process is assumed to be single-threaded.
1876 * This is the most portable form as it permits hwloc to use either
1877 * process-based OS functions or thread-based OS functions, depending
1878 * on which are available.
1880 * \return -1 with errno set to ENOSYS if the action is not supported
1881 * \return -1 with errno set to EXDEV if the binding cannot be enforced
1883 HWLOC_DECLSPEC int hwloc_set_membind_nodeset(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags);
1885 /** \brief Set the default memory binding policy of the current
1886 * process or thread to prefer the NUMA node(s) specified by \p set
1888 * If neither ::HWLOC_MEMBIND_PROCESS nor ::HWLOC_MEMBIND_THREAD is
1889 * specified, the current process is assumed to be single-threaded.
1890 * This is the most portable form as it permits hwloc to use either
1891 * process-based OS functions or thread-based OS functions, depending
1892 * on which are available.
1894 * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset.
1895 * Otherwise it's a cpuset.
1897 * \return -1 with errno set to ENOSYS if the action is not supported
1898 * \return -1 with errno set to EXDEV if the binding cannot be enforced
1900 HWLOC_DECLSPEC int hwloc_set_membind(hwloc_topology_t topology, hwloc_const_bitmap_t set, hwloc_membind_policy_t policy, int flags);
1902 /** \brief Query the default memory binding policy and physical locality of the
1903 * current process or thread.
1905 * This function has two output parameters: \p nodeset and \p policy.
1906 * The values returned in these parameters depend on both the \p flags
1907 * passed in and the current memory binding policies and nodesets in
1908 * the queried target.
1910 * Passing the ::HWLOC_MEMBIND_PROCESS flag specifies that the query
1911 * target is the current policies and nodesets for all the threads in
1912 * the current process. Passing ::HWLOC_MEMBIND_THREAD specifies that
1913 * the query target is the current policy and nodeset for only the
1914 * thread invoking this function.
1916 * If neither of these flags are passed (which is the most portable
1917 * method), the process is assumed to be single threaded. This allows
1918 * hwloc to use either process-based OS functions or thread-based OS
1919 * functions, depending on which are available.
1921 * ::HWLOC_MEMBIND_STRICT is only meaningful when ::HWLOC_MEMBIND_PROCESS
1922 * is also specified. In this case, hwloc will check the default
1923 * memory policies and nodesets for all threads in the process. If
1924 * they are not identical, -1 is returned and errno is set to EXDEV.
1925 * If they are identical, the values are returned in \p nodeset and \p
1926 * policy.
1928 * Otherwise, if ::HWLOC_MEMBIND_PROCESS is specified (and
1929 * ::HWLOC_MEMBIND_STRICT is \em not specified), \p nodeset is set to
1930 * the logical OR of all threads' default nodeset.
1931 * If all threads' default policies are the same, \p policy is set to
1932 * that policy. If they are different, \p policy is set to
1933 * ::HWLOC_MEMBIND_MIXED.
1935 * In the ::HWLOC_MEMBIND_THREAD case (or when neither
1936 * ::HWLOC_MEMBIND_PROCESS or ::HWLOC_MEMBIND_THREAD is specified), there
1937 * is only one nodeset and policy; they are returned in \p nodeset and
1938 * \p policy, respectively.
1940 * If any other flags are specified, -1 is returned and errno is set
1941 * to EINVAL.
1943 HWLOC_DECLSPEC int hwloc_get_membind_nodeset(hwloc_topology_t topology, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags);
1945 /** \brief Query the default memory binding policy and physical locality of the
1946 * current process or thread.
1948 * This function has two output parameters: \p set and \p policy.
1949 * The values returned in these parameters depend on both the \p flags
1950 * passed in and the current memory binding policies and nodesets in
1951 * the queried target.
1953 * Passing the ::HWLOC_MEMBIND_PROCESS flag specifies that the query
1954 * target is the current policies and nodesets for all the threads in
1955 * the current process. Passing ::HWLOC_MEMBIND_THREAD specifies that
1956 * the query target is the current policy and nodeset for only the
1957 * thread invoking this function.
1959 * If neither of these flags are passed (which is the most portable
1960 * method), the process is assumed to be single threaded. This allows
1961 * hwloc to use either process-based OS functions or thread-based OS
1962 * functions, depending on which are available.
1964 * ::HWLOC_MEMBIND_STRICT is only meaningful when ::HWLOC_MEMBIND_PROCESS
1965 * is also specified. In this case, hwloc will check the default
1966 * memory policies and nodesets for all threads in the process. If
1967 * they are not identical, -1 is returned and errno is set to EXDEV.
1968 * If they are identical, the values are returned in \p set and \p
1969 * policy.
1971 * Otherwise, if ::HWLOC_MEMBIND_PROCESS is specified (and
1972 * ::HWLOC_MEMBIND_STRICT is \em not specified), the default set
1973 * from each thread is logically OR'ed together.
1974 * If all threads' default policies are the same, \p policy is set to
1975 * that policy. If they are different, \p policy is set to
1976 * ::HWLOC_MEMBIND_MIXED.
1978 * In the ::HWLOC_MEMBIND_THREAD case (or when neither
1979 * ::HWLOC_MEMBIND_PROCESS or ::HWLOC_MEMBIND_THREAD is specified), there
1980 * is only one set and policy; they are returned in \p set and
1981 * \p policy, respectively.
1983 * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset.
1984 * Otherwise it's a cpuset.
1986 * If any other flags are specified, -1 is returned and errno is set
1987 * to EINVAL.
1989 HWLOC_DECLSPEC int hwloc_get_membind(hwloc_topology_t topology, hwloc_bitmap_t set, hwloc_membind_policy_t * policy, int flags);
1991 /** \brief Set the default memory binding policy of the specified
1992 * process to prefer the NUMA node(s) specified by \p nodeset
1994 * \return -1 with errno set to ENOSYS if the action is not supported
1995 * \return -1 with errno set to EXDEV if the binding cannot be enforced
1997 * \note \p hwloc_pid_t is \p pid_t on Unix platforms,
1998 * and \p HANDLE on native Windows platforms.
2000 HWLOC_DECLSPEC int hwloc_set_proc_membind_nodeset(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags);
2002 /** \brief Set the default memory binding policy of the specified
2003 * process to prefer the NUMA node(s) specified by \p set
2005 * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset.
2006 * Otherwise it's a cpuset.
2008 * \return -1 with errno set to ENOSYS if the action is not supported
2009 * \return -1 with errno set to EXDEV if the binding cannot be enforced
2011 * \note \p hwloc_pid_t is \p pid_t on Unix platforms,
2012 * and \p HANDLE on native Windows platforms.
2014 HWLOC_DECLSPEC int hwloc_set_proc_membind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_bitmap_t set, hwloc_membind_policy_t policy, int flags);
2016 /** \brief Query the default memory binding policy and physical locality of the
2017 * specified process.
2019 * This function has two output parameters: \p nodeset and \p policy.
2020 * The values returned in these parameters depend on both the \p flags
2021 * passed in and the current memory binding policies and nodesets in
2022 * the queried target.
2024 * Passing the ::HWLOC_MEMBIND_PROCESS flag specifies that the query
2025 * target is the current policies and nodesets for all the threads in
2026 * the specified process. If ::HWLOC_MEMBIND_PROCESS is not specified
2027 * (which is the most portable method), the process is assumed to be
2028 * single threaded. This allows hwloc to use either process-based OS
2029 * functions or thread-based OS functions, depending on which are
2030 * available.
2032 * Note that it does not make sense to pass ::HWLOC_MEMBIND_THREAD to
2033 * this function.
2035 * If ::HWLOC_MEMBIND_STRICT is specified, hwloc will check the default
2036 * memory policies and nodesets for all threads in the specified
2037 * process. If they are not identical, -1 is returned and errno is
2038 * set to EXDEV. If they are identical, the values are returned in \p
2039 * nodeset and \p policy.
2041 * Otherwise, \p nodeset is set to the logical OR of all threads'
2042 * default nodeset. If all threads' default policies are the same, \p
2043 * policy is set to that policy. If they are different, \p policy is
2044 * set to ::HWLOC_MEMBIND_MIXED.
2046 * If any other flags are specified, -1 is returned and errno is set
2047 * to EINVAL.
2049 * \note \p hwloc_pid_t is \p pid_t on Unix platforms,
2050 * and \p HANDLE on native Windows platforms.
2052 HWLOC_DECLSPEC int hwloc_get_proc_membind_nodeset(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags);
2054 /** \brief Query the default memory binding policy and physical locality of the
2055 * specified process.
2057 * This function has two output parameters: \p set and \p policy.
2058 * The values returned in these parameters depend on both the \p flags
2059 * passed in and the current memory binding policies and nodesets in
2060 * the queried target.
2062 * Passing the ::HWLOC_MEMBIND_PROCESS flag specifies that the query
2063 * target is the current policies and nodesets for all the threads in
2064 * the specified process. If ::HWLOC_MEMBIND_PROCESS is not specified
2065 * (which is the most portable method), the process is assumed to be
2066 * single threaded. This allows hwloc to use either process-based OS
2067 * functions or thread-based OS functions, depending on which are
2068 * available.
2070 * Note that it does not make sense to pass ::HWLOC_MEMBIND_THREAD to
2071 * this function.
2073 * If ::HWLOC_MEMBIND_STRICT is specified, hwloc will check the default
2074 * memory policies and nodesets for all threads in the specified
2075 * process. If they are not identical, -1 is returned and errno is
2076 * set to EXDEV. If they are identical, the values are returned in \p
2077 * set and \p policy.
2079 * Otherwise, \p set is set to the logical OR of all threads'
2080 * default set. If all threads' default policies
2081 * are the same, \p policy is set to that policy. If they are
2082 * different, \p policy is set to ::HWLOC_MEMBIND_MIXED.
2084 * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset.
2085 * Otherwise it's a cpuset.
2087 * If any other flags are specified, -1 is returned and errno is set
2088 * to EINVAL.
2090 * \note \p hwloc_pid_t is \p pid_t on Unix platforms,
2091 * and \p HANDLE on native Windows platforms.
2093 HWLOC_DECLSPEC int hwloc_get_proc_membind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_bitmap_t set, hwloc_membind_policy_t * policy, int flags);
2095 /** \brief Bind the already-allocated memory identified by (addr, len)
2096 * to the NUMA node(s) specified by \p nodeset.
2098 * \return 0 if \p len is 0.
2099 * \return -1 with errno set to ENOSYS if the action is not supported
2100 * \return -1 with errno set to EXDEV if the binding cannot be enforced
2102 HWLOC_DECLSPEC int hwloc_set_area_membind_nodeset(hwloc_topology_t topology, const void *addr, size_t len, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags);
2104 /** \brief Bind the already-allocated memory identified by (addr, len)
2105 * to the NUMA node(s) specified by \p set.
2107 * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset.
2108 * Otherwise it's a cpuset.
2110 * \return 0 if \p len is 0.
2111 * \return -1 with errno set to ENOSYS if the action is not supported
2112 * \return -1 with errno set to EXDEV if the binding cannot be enforced
2114 HWLOC_DECLSPEC int hwloc_set_area_membind(hwloc_topology_t topology, const void *addr, size_t len, hwloc_const_bitmap_t set, hwloc_membind_policy_t policy, int flags);
2116 /** \brief Query the physical NUMA node(s) and binding policy of the memory
2117 * identified by (\p addr, \p len ).
2119 * This function has two output parameters: \p nodeset and \p policy.
2120 * The values returned in these parameters depend on both the \p flags
2121 * passed in and the memory binding policies and nodesets of the pages
2122 * in the address range.
2124 * If ::HWLOC_MEMBIND_STRICT is specified, the target pages are first
2125 * checked to see if they all have the same memory binding policy and
2126 * nodeset. If they do not, -1 is returned and errno is set to EXDEV.
2127 * If they are identical across all pages, the nodeset and policy are
2128 * returned in \p nodeset and \p policy, respectively.
2130 * If ::HWLOC_MEMBIND_STRICT is not specified, \p nodeset is set to the
2131 * union of all NUMA node(s) containing pages in the address range.
2132 * If all pages in the target have the same policy, it is returned in
2133 * \p policy. Otherwise, \p policy is set to ::HWLOC_MEMBIND_MIXED.
2135 * If \p len is 0, -1 is returned and errno is set to EINVAL.
2137 * If any other flags are specified, -1 is returned and errno is set
2138 * to EINVAL.
2140 HWLOC_DECLSPEC int hwloc_get_area_membind_nodeset(hwloc_topology_t topology, const void *addr, size_t len, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags);
2142 /** \brief Query the CPUs near the physical NUMA node(s) and binding policy of
2143 * the memory identified by (\p addr, \p len ).
2145 * This function has two output parameters: \p set and \p policy.
2146 * The values returned in these parameters depend on both the \p flags
2147 * passed in and the memory binding policies and nodesets of the pages
2148 * in the address range.
2150 * If ::HWLOC_MEMBIND_STRICT is specified, the target pages are first
2151 * checked to see if they all have the same memory binding policy and
2152 * nodeset. If they do not, -1 is returned and errno is set to EXDEV.
2153 * If they are identical across all pages, the set and policy are
2154 * returned in \p set and \p policy, respectively.
2156 * If ::HWLOC_MEMBIND_STRICT is not specified, the union of all NUMA
2157 * node(s) containing pages in the address range is calculated.
2158 * If all pages in the target have the same policy, it is returned in
2159 * \p policy. Otherwise, \p policy is set to ::HWLOC_MEMBIND_MIXED.
2161 * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset.
2162 * Otherwise it's a cpuset.
2164 * If \p len is 0, -1 is returned and errno is set to EINVAL.
2166 * If any other flags are specified, -1 is returned and errno is set
2167 * to EINVAL.
2169 HWLOC_DECLSPEC int hwloc_get_area_membind(hwloc_topology_t topology, const void *addr, size_t len, hwloc_bitmap_t set, hwloc_membind_policy_t * policy, int flags);
2171 /** \brief Get the NUMA nodes where memory identified by (\p addr, \p len ) is physically allocated.
2173 * Fills \p set according to the NUMA nodes where the memory area pages
2174 * are physically allocated. If no page is actually allocated yet,
2175 * \p set may be empty.
2177 * If pages spread to multiple nodes, it is not specified whether they spread
2178 * equitably, or whether most of them are on a single node, etc.
2180 * The operating system may move memory pages from one processor
2181 * to another at any time according to their binding,
2182 * so this function may return something that is already
2183 * outdated.
2185 * If ::HWLOC_MEMBIND_BYNODESET is specified in \p flags, set is
2186 * considered a nodeset. Otherwise it's a cpuset.
2188 * If \p len is 0, \p set is emptied.
2190 HWLOC_DECLSPEC int hwloc_get_area_memlocation(hwloc_topology_t topology, const void *addr, size_t len, hwloc_bitmap_t set, int flags);
2192 /** \brief Allocate some memory
2194 * This is equivalent to malloc(), except that it tries to allocate
2195 * page-aligned memory from the OS.
2197 * \note The allocated memory should be freed with hwloc_free().
2199 HWLOC_DECLSPEC void *hwloc_alloc(hwloc_topology_t topology, size_t len);
2201 /** \brief Allocate some memory on NUMA memory nodes specified by \p nodeset
2203 * \return NULL with errno set to ENOSYS if the action is not supported
2204 * and ::HWLOC_MEMBIND_STRICT is given
2205 * \return NULL with errno set to EXDEV if the binding cannot be enforced
2206 * and ::HWLOC_MEMBIND_STRICT is given
2207 * \return NULL with errno set to ENOMEM if the memory allocation failed
2208 * even before trying to bind.
2210 * \note The allocated memory should be freed with hwloc_free().
2212 HWLOC_DECLSPEC void *hwloc_alloc_membind_nodeset(hwloc_topology_t topology, size_t len, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags) __hwloc_attribute_malloc;
2214 /** \brief Allocate some memory on NUMA memory nodes specified by \p set
2216 * \return NULL with errno set to ENOSYS if the action is not supported
2217 * and ::HWLOC_MEMBIND_STRICT is given
2218 * \return NULL with errno set to EXDEV if the binding cannot be enforced
2219 * and ::HWLOC_MEMBIND_STRICT is given
2220 * \return NULL with errno set to ENOMEM if the memory allocation failed
2221 * even before trying to bind.
2223 * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset.
2224 * Otherwise it's a cpuset.
2226 * \note The allocated memory should be freed with hwloc_free().
2228 HWLOC_DECLSPEC void *hwloc_alloc_membind(hwloc_topology_t topology, size_t len, hwloc_const_bitmap_t set, hwloc_membind_policy_t policy, int flags) __hwloc_attribute_malloc;
2230 /** \brief Allocate some memory on NUMA memory nodes specified by \p nodeset
2232 * This is similar to hwloc_alloc_membind() except that it is allowed to change
2233 * the current memory binding policy, thus providing more binding support, at
2234 * the expense of changing the current state.
2236 static __hwloc_inline void *
2237 hwloc_alloc_membind_policy_nodeset(hwloc_topology_t topology, size_t len, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags) __hwloc_attribute_malloc;
2239 /** \brief Allocate some memory on NUMA memory nodes specified by \p set
2241 * This is similar to hwloc_alloc_membind_nodeset() except that it is allowed to change
2242 * the current memory binding policy, thus providing more binding support, at
2243 * the expense of changing the current state.
2245 * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset.
2246 * Otherwise it's a cpuset.
2248 static __hwloc_inline void *
2249 hwloc_alloc_membind_policy(hwloc_topology_t topology, size_t len, hwloc_const_bitmap_t set, hwloc_membind_policy_t policy, int flags) __hwloc_attribute_malloc;
2251 /** \brief Free memory that was previously allocated by hwloc_alloc()
2252 * or hwloc_alloc_membind().
2254 HWLOC_DECLSPEC int hwloc_free(hwloc_topology_t topology, void *addr, size_t len);
2256 /** @} */
2260 /** \defgroup hwlocality_tinker Modifying a loaded Topology
2261 * @{
2264 /** \brief Add a MISC object to the topology
2266 * A new MISC object will be created and inserted into the topology at the
2267 * position given by bitmap \p cpuset. This offers a way to add new
2268 * intermediate levels to the topology hierarchy.
2270 * \p cpuset and \p name will be copied to setup the new object attributes.
2272 * \return the newly-created object.
2273 * \return \c NULL if the insertion conflicts with the existing topology tree.
2275 * \note If \p name contains some non-printable characters, they will
2276 * be dropped when exporting to XML, see hwloc_topology_export_xml().
2278 HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_insert_misc_object_by_cpuset(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset, const char *name);
2280 /** \brief Add a MISC object as a leaf of the topology
2282 * A new MISC object will be created and inserted into the topology at the
2283 * position given by parent. It is appended to the list of existing children,
2284 * without ever adding any intermediate hierarchy level. This is useful for
2285 * annotating the topology without actually changing the hierarchy.
2287 * \p name will be copied to the setup the new object attributes.
2288 * However, the new leaf object will not have any \p cpuset.
2290 * \return the newly-created object
2292 * \note If \p name contains some non-printable characters, they will
2293 * be dropped when exporting to XML, see hwloc_topology_export_xml().
2295 HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_insert_misc_object_by_parent(hwloc_topology_t topology, hwloc_obj_t parent, const char *name);
2297 /** \brief Flags to be given to hwloc_topology_restrict(). */
2298 enum hwloc_restrict_flags_e {
2299 /** \brief Adapt distance matrices according to objects being removed during restriction.
2300 * If this flag is not set, distance matrices are removed.
2301 * \hideinitializer
2303 HWLOC_RESTRICT_FLAG_ADAPT_DISTANCES = (1<<0),
2305 /** \brief Move Misc objects to ancestors if their parents are removed during restriction.
2306 * If this flag is not set, Misc objects are removed when their parents are removed.
2307 * \hideinitializer
2309 HWLOC_RESTRICT_FLAG_ADAPT_MISC = (1<<1),
2311 /** \brief Move I/O objects to ancestors if their parents are removed during restriction.
2312 * If this flag is not set, I/O devices and bridges are removed when their parents are removed.
2313 * \hideinitializer
2315 HWLOC_RESTRICT_FLAG_ADAPT_IO = (1<<2)
2318 /** \brief Restrict the topology to the given CPU set.
2320 * Topology \p topology is modified so as to remove all objects that
2321 * are not included (or partially included) in the CPU set \p cpuset.
2322 * All objects CPU and node sets are restricted accordingly.
2324 * \p flags is a OR'ed set of ::hwloc_restrict_flags_e.
2326 * \note This call may not be reverted by restricting back to a larger
2327 * cpuset. Once dropped during restriction, objects may not be brought
2328 * back, except by loading another topology with hwloc_topology_load().
2330 * \return 0 on success.
2332 * \return -1 with errno set to EINVAL if the input cpuset is invalid.
2333 * The topology is not modified in this case.
2335 * \return -1 with errno set to ENOMEM on failure to allocate internal data.
2336 * The topology is reinitialized in this case. It should be either
2337 * destroyed with hwloc_topology_destroy() or configured and loaded again.
2339 HWLOC_DECLSPEC int hwloc_topology_restrict(hwloc_topology_t __hwloc_restrict topology, hwloc_const_cpuset_t cpuset, unsigned long flags);
2341 /** @} */
2345 /** \defgroup hwlocality_custom Building Custom Topologies
2347 * A custom topology may be initialized by calling hwloc_topology_set_custom()
2348 * after hwloc_topology_init(). It may then be modified by inserting objects
2349 * or entire topologies. Once done assembling, hwloc_topology_load() should
2350 * be invoked as usual to finalize the topology.
2351 * @{
2354 /** \brief Insert an existing topology inside a custom topology
2356 * Duplicate the existing topology \p oldtopology inside a new
2357 * custom topology \p newtopology as a leaf of object \p newparent.
2359 * If \p oldroot is not \c NULL, duplicate \p oldroot and all its
2360 * children instead of the entire \p oldtopology. Passing the root
2361 * object of \p oldtopology in \p oldroot is equivalent to passing
2362 * \c NULL.
2364 * The custom topology \p newtopology must have been prepared with
2365 * hwloc_topology_set_custom() and not loaded with hwloc_topology_load()
2366 * yet.
2368 * \p newparent may be either the root of \p newtopology or an object
2369 * that was added through hwloc_custom_insert_group_object_by_parent().
2371 * \note The cpuset and nodeset of the \p newparent object are not
2372 * modified based on the contents of \p oldtopology.
2374 HWLOC_DECLSPEC int hwloc_custom_insert_topology(hwloc_topology_t newtopology, hwloc_obj_t newparent, hwloc_topology_t oldtopology, hwloc_obj_t oldroot);
2376 /** \brief Insert a new group object inside a custom topology
2378 * An object with type ::HWLOC_OBJ_GROUP is inserted as a new child
2379 * of object \p parent.
2381 * \p groupdepth is the depth attribute to be given to the new object.
2382 * It may for instance be 0 for top-level groups, 1 for their children,
2383 * and so on.
2385 * The custom topology \p newtopology must have been prepared with
2386 * hwloc_topology_set_custom() and not loaded with hwloc_topology_load()
2387 * yet.
2389 * \p parent may be either the root of \p topology or an object that
2390 * was added earlier through hwloc_custom_insert_group_object_by_parent().
2392 * \note The cpuset and nodeset of the new group object are NULL because
2393 * these sets are meaningless when assembling multiple topologies.
2395 * \note The cpuset and nodeset of the \p parent object are not modified.
2397 HWLOC_DECLSPEC hwloc_obj_t hwloc_custom_insert_group_object_by_parent(hwloc_topology_t topology, hwloc_obj_t parent, int groupdepth);
2399 /** @} */
2403 /** \defgroup hwlocality_xmlexport Exporting Topologies to XML
2404 * @{
2407 /** \brief Export the topology into an XML file.
2409 * This file may be loaded later through hwloc_topology_set_xml().
2411 * \return -1 if a failure occured.
2413 * \note See also hwloc_topology_set_userdata_export_callback()
2414 * for exporting application-specific object userdata.
2416 * \note The topology-specific userdata pointer is ignored when exporting to XML.
2418 * \note Only printable characters may be exported to XML string attributes.
2419 * Any other character, especially any non-ASCII character, will be silently
2420 * dropped.
2422 * \note If \p name is "-", the XML output is sent to the standard output.
2424 HWLOC_DECLSPEC int hwloc_topology_export_xml(hwloc_topology_t topology, const char *xmlpath);
2426 /** \brief Export the topology into a newly-allocated XML memory buffer.
2428 * \p xmlbuffer is allocated by the callee and should be freed with
2429 * hwloc_free_xmlbuffer() later in the caller.
2431 * This memory buffer may be loaded later through hwloc_topology_set_xmlbuffer().
2433 * The returned buffer ends with a \0 that is included in the returned
2434 * length.
2436 * \return -1 if a failure occured.
2438 * \note See also hwloc_topology_set_userdata_export_callback()
2439 * for exporting application-specific object userdata.
2441 * \note The topology-specific userdata pointer is ignored when exporting to XML.
2443 * \note Only printable characters may be exported to XML string attributes.
2444 * Any other character, especially any non-ASCII character, will be silently
2445 * dropped.
2447 HWLOC_DECLSPEC int hwloc_topology_export_xmlbuffer(hwloc_topology_t topology, char **xmlbuffer, int *buflen);
2449 /** \brief Free a buffer allocated by hwloc_topology_export_xmlbuffer() */
2450 HWLOC_DECLSPEC void hwloc_free_xmlbuffer(hwloc_topology_t topology, char *xmlbuffer);
2452 /** \brief Set the application-specific callback for exporting object userdata
2454 * The object userdata pointer is not exported to XML by default because hwloc
2455 * does not know what it contains.
2457 * This function lets applications set \p export_cb to a callback function
2458 * that converts this opaque userdata into an exportable string.
2460 * \p export_cb is invoked during XML export for each object whose
2461 * \p userdata pointer is not \c NULL.
2462 * The callback should use hwloc_export_obj_userdata() or
2463 * hwloc_export_obj_userdata_base64() to actually export
2464 * something to XML (possibly multiple times per object).
2466 * \p export_cb may be set to \c NULL if userdata should not be exported to XML.
2468 * \note The topology-specific userdata pointer is ignored when exporting to XML.
2470 HWLOC_DECLSPEC void hwloc_topology_set_userdata_export_callback(hwloc_topology_t topology,
2471 void (*export_cb)(void *reserved, hwloc_topology_t topology, hwloc_obj_t obj));
2473 /** \brief Export some object userdata to XML
2475 * This function may only be called from within the export() callback passed
2476 * to hwloc_topology_set_userdata_export_callback().
2477 * It may be invoked one of multiple times to export some userdata to XML.
2478 * The \p buffer content of length \p length is stored with optional name
2479 * \p name.
2481 * When importing this XML file, the import() callback (if set) will be
2482 * called exactly as many times as hwloc_export_obj_userdata() was called
2483 * during export(). It will receive the corresponding \p name, \p buffer
2484 * and \p length arguments.
2486 * \p reserved, \p topology and \p obj must be the first three parameters
2487 * that were given to the export callback.
2489 * Only printable characters may be exported to XML string attributes.
2490 * If a non-printable character is passed in \p name or \p buffer,
2491 * the function returns -1 with errno set to EINVAL.
2493 * If exporting binary data, the application should first encode into
2494 * printable characters only (or use hwloc_export_obj_userdata_base64()).
2495 * It should also take care of portability issues if the export may
2496 * be reimported on a different architecture.
2498 HWLOC_DECLSPEC int hwloc_export_obj_userdata(void *reserved, hwloc_topology_t topology, hwloc_obj_t obj, const char *name, const void *buffer, size_t length);
2500 /** \brief Encode and export some object userdata to XML
2502 * This function is similar to hwloc_export_obj_userdata() but it encodes
2503 * the input buffer into printable characters before exporting.
2504 * On import, decoding is automatically performed before the data is given
2505 * to the import() callback if any.
2507 * This function may only be called from within the export() callback passed
2508 * to hwloc_topology_set_userdata_export_callback().
2510 * The function does not take care of portability issues if the export
2511 * may be reimported on a different architecture.
2513 HWLOC_DECLSPEC int hwloc_export_obj_userdata_base64(void *reserved, hwloc_topology_t topology, hwloc_obj_t obj, const char *name, const void *buffer, size_t length);
2515 /** \brief Set the application-specific callback for importing userdata
2517 * On XML import, userdata is ignored by default because hwloc does not know
2518 * how to store it in memory.
2520 * This function lets applications set \p import_cb to a callback function
2521 * that will get the XML-stored userdata and store it in the object as expected
2522 * by the application.
2524 * \p import_cb is called during hwloc_topology_load() as many times as
2525 * hwloc_export_obj_userdata() was called during export. The topology
2526 * is not entirely setup yet. Object attributes are ready to consult,
2527 * but links between objects are not.
2529 * \p import_cb may be \c NULL if userdata should be ignored during import.
2531 * \note \p buffer contains \p length characters followed by a null byte ('\0').
2533 * \note This function should be called before hwloc_topology_load().
2535 * \note The topology-specific userdata pointer is ignored when importing from XML.
2537 HWLOC_DECLSPEC void hwloc_topology_set_userdata_import_callback(hwloc_topology_t topology,
2538 void (*import_cb)(hwloc_topology_t topology, hwloc_obj_t obj, const char *name, const void *buffer, size_t length));
2540 /** @} */
2543 /** \defgroup hwlocality_syntheticexport Exporting Topologies to Synthetic
2544 * @{
2547 /** \brief Flags for exporting synthetic topologies.
2549 * Flags to be given as a OR'ed set to hwloc_topology_export_synthetic().
2551 enum hwloc_topology_export_synthetic_flags_e {
2552 /** \brief Export extended types such as L2dcache as basic types such as Cache.
2554 * This is required if loading the synthetic description with hwloc < 1.9.
2555 * \hideinitializer
2557 HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_NO_EXTENDED_TYPES = (1UL<<0),
2559 /** \brief Do not export level attributes.
2561 * Ignore level attributes such as memory/cache sizes or PU indexes.
2562 * This is required if loading the synthetic description with hwloc < 1.10.
2563 * \hideinitializer
2565 HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_NO_ATTRS = (1UL<<1)
2568 /** \brief Export the topology as a synthetic string.
2570 * At most \p buflen characters will be written in \p buffer,
2571 * including the terminating \0.
2573 * This exported string may be given back to hwloc_topology_set_synthetic().
2575 * \p flags is a OR'ed set of hwloc_topology_export_synthetic_flags_e.
2577 * \return The number of characters that were written,
2578 * not including the terminating \0.
2580 * \return -1 if the topology could not be exported,
2581 * for instance if it is not symmetric.
2583 * \note A 1024-byte buffer should be large enough for exporting
2584 * topologies in the vast majority of cases.
2586 HWLOC_DECLSPEC int hwloc_topology_export_synthetic(hwloc_topology_t topology, char *buffer, size_t buflen, unsigned long flags);
2588 /** @} */
2592 #ifdef __cplusplus
2593 } /* extern "C" */
2594 #endif
2597 /* high-level helpers */
2598 #include <hwloc/helper.h>
2600 /* inline code of some functions above */
2601 #include <hwloc/inlines.h>
2603 /* topology diffs */
2604 #include <hwloc/diff.h>
2606 /* deprecated headers */
2607 #include <hwloc/deprecated.h>
2609 #endif /* HWLOC_H */