Hardware Locality (hwloc)  1.11.12
hwloc.h
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  */
8 
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  *=====================================================================
16  *
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.
20  *
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.
26  *
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!
30  *
31  * There are entire paragraph-length descriptions, discussions, and
32  * pretty prictures to explain subtle corner cases, provide concrete
33  * examples, etc.
34  *
35  * Please, go read the documentation. :-)
36  *
37  * Moreover there are several examples of hwloc use under doc/examples
38  * in the source tree.
39  *
40  *=====================================================================*/
41 
50 #ifndef HWLOC_H
51 #define HWLOC_H
52 
53 #include <hwloc/autogen/config.h>
54 #include <sys/types.h>
55 #include <stdio.h>
56 #include <string.h>
57 #include <limits.h>
58 
59 /*
60  * Symbol transforms
61  */
62 #include <hwloc/rename.h>
63 
64 /*
65  * Bitmap definitions
66  */
67 
68 #include <hwloc/bitmap.h>
69 #include <hwloc/cpuset.h>
70 
71 
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75 
76 
89 #define HWLOC_API_VERSION 0x00010b06
90 
95 HWLOC_DECLSPEC unsigned hwloc_get_api_version(void);
96 
98 #define HWLOC_COMPONENT_ABI 4
99 
136 
156 
171 typedef enum {
172  /* ***************************************************************
173  WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
174 
175  If new enum values are added here, you MUST also go update the
176  obj_type_order[] and obj_order_type[] arrays in src/topology.c.
177 
178  WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
179  *************************************************************** */
180 
260  /* ***************************************************************
261  WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
262 
263  If new enum values are added here, you MUST also go update the
264  obj_type_order[] and obj_order_type[] arrays in src/topology.c.
265 
266  WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
267  *************************************************************** */
269 
277 
283 
303 
321 HWLOC_DECLSPEC int hwloc_compare_types (hwloc_obj_type_t type1, hwloc_obj_type_t type2) __hwloc_attribute_const;
322 
325 };
326 
335 union hwloc_obj_attr_u;
336 
339  hwloc_uint64_t total_memory;
340  hwloc_uint64_t local_memory;
343  unsigned page_types_len;
350  hwloc_uint64_t size;
351  hwloc_uint64_t count;
352  } * page_types;
353 };
354 
359 struct hwloc_obj {
360  /* physical information */
363  unsigned os_index;
367  char *name;
377  /* global position */
378  unsigned depth;
393  unsigned logical_index;
397  signed os_level;
399  /* cousins are all objects of the same type (and depth) across the entire topology */
403  /* children of the same parent are siblings, even if they may have different type and depth */
404  struct hwloc_obj *parent;
405  unsigned sibling_rank;
409  /* children array below this object */
410  unsigned arity;
411  struct hwloc_obj **children;
415  /* misc */
416  void *userdata;
421  /* cpusets and nodesets */
422  hwloc_cpuset_t cpuset;
435  hwloc_cpuset_t complete_cpuset;
446  hwloc_cpuset_t online_cpuset;
454  hwloc_cpuset_t allowed_cpuset;
465  hwloc_nodeset_t nodeset;
482  hwloc_nodeset_t complete_nodeset;
496  hwloc_nodeset_t allowed_nodeset;
510  unsigned distances_count;
511 
513  unsigned infos_count;
520 };
524 typedef struct hwloc_obj * hwloc_obj_t;
525 
530  hwloc_uint64_t size;
531  unsigned depth;
532  unsigned linesize;
536  } cache;
539  unsigned depth;
540  } group;
543  unsigned short domain;
544  unsigned char bus, dev, func;
545  unsigned short class_id;
547  unsigned char revision;
548  float linkspeed; /* in GB/s */
549  } pcidev;
552  union {
554  } upstream;
556  union {
557  struct {
558  unsigned short domain;
560  } pci;
561  } downstream;
563  unsigned depth;
564  } bridge;
568  } osdev;
569 };
570 
585  unsigned relative_depth;
587  unsigned nbobjs;
592  float *latency;
604  float latency_max;
605  float latency_base;
609 };
610 
616  char *name;
617  char *value;
618 };
619 
628 struct hwloc_topology;
633 typedef struct hwloc_topology * hwloc_topology_t;
634 
641 HWLOC_DECLSPEC int hwloc_topology_init (hwloc_topology_t *topologyp);
642 
663 HWLOC_DECLSPEC int hwloc_topology_load(hwloc_topology_t topology);
664 
669 HWLOC_DECLSPEC void hwloc_topology_destroy (hwloc_topology_t topology);
670 
681 HWLOC_DECLSPEC int hwloc_topology_dup(hwloc_topology_t *newtopology, hwloc_topology_t oldtopology);
682 
694 HWLOC_DECLSPEC void hwloc_topology_check(hwloc_topology_t topology);
695 
732 HWLOC_DECLSPEC int hwloc_topology_ignore_type(hwloc_topology_t topology, hwloc_obj_type_t type);
733 
742 HWLOC_DECLSPEC int hwloc_topology_ignore_type_keep_structure(hwloc_topology_t topology, hwloc_obj_type_t type);
743 
750 HWLOC_DECLSPEC int hwloc_topology_ignore_all_keep_structure(hwloc_topology_t topology);
751 
774 
794 
807 
816 
826 
834 
855 };
856 
866 HWLOC_DECLSPEC int hwloc_topology_set_flags (hwloc_topology_t topology, unsigned long flags);
867 
874 HWLOC_DECLSPEC unsigned long hwloc_topology_get_flags (hwloc_topology_t topology);
875 
890 HWLOC_DECLSPEC int hwloc_topology_set_pid(hwloc_topology_t __hwloc_restrict topology, hwloc_pid_t pid);
891 
918 HWLOC_DECLSPEC int hwloc_topology_set_fsroot(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict fsroot_path);
919 
947 HWLOC_DECLSPEC int hwloc_topology_set_synthetic(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict description);
948 
975 HWLOC_DECLSPEC int hwloc_topology_set_xml(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict xmlpath);
976 
1003 HWLOC_DECLSPEC int hwloc_topology_set_xmlbuffer(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict buffer, int size);
1004 
1024 HWLOC_DECLSPEC int hwloc_topology_set_custom(hwloc_topology_t topology);
1025 
1044 HWLOC_DECLSPEC int hwloc_topology_set_distance_matrix(hwloc_topology_t __hwloc_restrict topology,
1045  hwloc_obj_type_t type, unsigned nbobjs,
1046  unsigned *os_index, float *distances);
1047 
1055 HWLOC_DECLSPEC int hwloc_topology_is_thissystem(hwloc_topology_t __hwloc_restrict topology) __hwloc_attribute_pure;
1056 
1060  unsigned char pu;
1061 };
1062 
1070  unsigned char set_thisproc_cpubind;
1072  unsigned char get_thisproc_cpubind;
1074  unsigned char set_proc_cpubind;
1076  unsigned char get_proc_cpubind;
1078  unsigned char set_thisthread_cpubind;
1080  unsigned char get_thisthread_cpubind;
1082  unsigned char set_thread_cpubind;
1084  unsigned char get_thread_cpubind;
1091 };
1092 
1100  unsigned char set_thisproc_membind;
1102  unsigned char get_thisproc_membind;
1104  unsigned char set_proc_membind;
1106  unsigned char get_proc_membind;
1108  unsigned char set_thisthread_membind;
1110  unsigned char get_thisthread_membind;
1112  unsigned char set_area_membind;
1114  unsigned char get_area_membind;
1116  unsigned char alloc_membind;
1118  unsigned char firsttouch_membind;
1120  unsigned char bind_membind;
1122  unsigned char interleave_membind;
1124  unsigned char replicate_membind;
1126  unsigned char nexttouch_membind;
1128  unsigned char migrate_membind;
1130  unsigned char get_area_memlocation;
1131 };
1132 
1143 };
1144 
1154 HWLOC_DECLSPEC const struct hwloc_topology_support *hwloc_topology_get_support(hwloc_topology_t __hwloc_restrict topology);
1155 
1166 HWLOC_DECLSPEC void hwloc_topology_set_userdata(hwloc_topology_t topology, const void *userdata);
1167 
1173 HWLOC_DECLSPEC void * hwloc_topology_get_userdata(hwloc_topology_t topology);
1174 
1195 HWLOC_DECLSPEC unsigned hwloc_topology_get_depth(hwloc_topology_t __hwloc_restrict topology) __hwloc_attribute_pure;
1196 
1221 HWLOC_DECLSPEC int hwloc_get_type_depth (hwloc_topology_t topology, hwloc_obj_type_t type);
1222 
1229 };
1230 
1245 static __hwloc_inline int
1246 hwloc_get_type_or_below_depth (hwloc_topology_t topology, hwloc_obj_type_t type) __hwloc_attribute_pure;
1247 
1262 static __hwloc_inline int
1263 hwloc_get_type_or_above_depth (hwloc_topology_t topology, hwloc_obj_type_t type) __hwloc_attribute_pure;
1264 
1271 HWLOC_DECLSPEC hwloc_obj_type_t hwloc_get_depth_type (hwloc_topology_t topology, unsigned depth) __hwloc_attribute_pure;
1272 
1275 HWLOC_DECLSPEC unsigned hwloc_get_nbobjs_by_depth (hwloc_topology_t topology, unsigned depth) __hwloc_attribute_pure;
1276 
1282 static __hwloc_inline int
1283 hwloc_get_nbobjs_by_type (hwloc_topology_t topology, hwloc_obj_type_t type) __hwloc_attribute_pure;
1284 
1290 static __hwloc_inline hwloc_obj_t
1291 hwloc_get_root_obj (hwloc_topology_t topology) __hwloc_attribute_pure;
1292 
1294 HWLOC_DECLSPEC hwloc_obj_t hwloc_get_obj_by_depth (hwloc_topology_t topology, unsigned depth, unsigned idx) __hwloc_attribute_pure;
1295 
1302 static __hwloc_inline hwloc_obj_t
1303 hwloc_get_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type, unsigned idx) __hwloc_attribute_pure;
1304 
1309 static __hwloc_inline hwloc_obj_t
1310 hwloc_get_next_obj_by_depth (hwloc_topology_t topology, unsigned depth, hwloc_obj_t prev);
1311 
1318 static __hwloc_inline hwloc_obj_t
1319 hwloc_get_next_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type,
1320  hwloc_obj_t prev);
1321 
1337 HWLOC_DECLSPEC const char * hwloc_obj_type_string (hwloc_obj_type_t type) __hwloc_attribute_const;
1338 
1352 HWLOC_DECLSPEC int hwloc_obj_type_snprintf(char * __hwloc_restrict string, size_t size, hwloc_obj_t obj,
1353  int verbose);
1354 
1366 HWLOC_DECLSPEC int hwloc_obj_attr_snprintf(char * __hwloc_restrict string, size_t size, hwloc_obj_t obj, const char * __hwloc_restrict separator,
1367  int verbose);
1368 
1376 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 
1407 HWLOC_DECLSPEC int hwloc_obj_type_sscanf(const char *string,
1408  hwloc_obj_type_t *typep,
1409  int *depthattrp,
1410  void *typeattrp, size_t typeattrsize);
1411 
1427 static __hwloc_inline const char *
1428 hwloc_obj_get_info_by_name(hwloc_obj_t obj, const char *name) __hwloc_attribute_pure;
1429 
1444 HWLOC_DECLSPEC void hwloc_obj_add_info(hwloc_obj_t obj, const char *name, const char *value);
1445 
1517 typedef enum {
1521 
1525 
1550 
1568 
1574 HWLOC_DECLSPEC int hwloc_set_cpubind(hwloc_topology_t topology, hwloc_const_cpuset_t set, int flags);
1575 
1581 HWLOC_DECLSPEC int hwloc_get_cpubind(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
1582 
1594 HWLOC_DECLSPEC int hwloc_set_proc_cpubind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_cpuset_t set, int flags);
1595 
1607 HWLOC_DECLSPEC int hwloc_get_proc_cpubind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t set, int flags);
1608 
1609 #ifdef hwloc_thread_t
1610 
1617 HWLOC_DECLSPEC int hwloc_set_thread_cpubind(hwloc_topology_t topology, hwloc_thread_t thread, hwloc_const_cpuset_t set, int flags);
1618 #endif
1619 
1620 #ifdef hwloc_thread_t
1621 
1628 HWLOC_DECLSPEC int hwloc_get_thread_cpubind(hwloc_topology_t topology, hwloc_thread_t thread, hwloc_cpuset_t set, int flags);
1629 #endif
1630 
1644 HWLOC_DECLSPEC int hwloc_get_last_cpu_location(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
1645 
1662 HWLOC_DECLSPEC int hwloc_get_proc_last_cpu_location(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t set, int flags);
1663 
1745 typedef enum {
1756 
1766 
1770 
1779 
1792 
1799 
1806 
1820 typedef enum {
1826 
1831 
1839 
1845 
1858 
1871 
1884 HWLOC_DECLSPEC int hwloc_set_membind_nodeset(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags);
1885 
1901 HWLOC_DECLSPEC int hwloc_set_membind(hwloc_topology_t topology, hwloc_const_bitmap_t set, hwloc_membind_policy_t policy, int flags);
1902 
1944 HWLOC_DECLSPEC int hwloc_get_membind_nodeset(hwloc_topology_t topology, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags);
1945 
1990 HWLOC_DECLSPEC int hwloc_get_membind(hwloc_topology_t topology, hwloc_bitmap_t set, hwloc_membind_policy_t * policy, int flags);
1991 
2001 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 
2015 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 
2053 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 
2094 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 
2103 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 
2115 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 
2141 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 
2170 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 
2191 HWLOC_DECLSPEC int hwloc_get_area_memlocation(hwloc_topology_t topology, const void *addr, size_t len, hwloc_bitmap_t set, int flags);
2192 
2200 HWLOC_DECLSPEC void *hwloc_alloc(hwloc_topology_t topology, size_t len);
2201 
2213 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 
2229 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 
2237 static __hwloc_inline void *
2238 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 
2249 static __hwloc_inline void *
2250 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 
2255 HWLOC_DECLSPEC int hwloc_free(hwloc_topology_t topology, void *addr, size_t len);
2256 
2279 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 
2296 HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_insert_misc_object_by_parent(hwloc_topology_t topology, hwloc_obj_t parent, const char *name);
2297 
2305 
2311 
2317 };
2318 
2340 HWLOC_DECLSPEC int hwloc_topology_restrict(hwloc_topology_t __hwloc_restrict topology, hwloc_const_cpuset_t cpuset, unsigned long flags);
2341 
2375 HWLOC_DECLSPEC int hwloc_custom_insert_topology(hwloc_topology_t newtopology, hwloc_obj_t newparent, hwloc_topology_t oldtopology, hwloc_obj_t oldroot);
2376 
2398 HWLOC_DECLSPEC hwloc_obj_t hwloc_custom_insert_group_object_by_parent(hwloc_topology_t topology, hwloc_obj_t parent, int groupdepth);
2399 
2425 HWLOC_DECLSPEC int hwloc_topology_export_xml(hwloc_topology_t topology, const char *xmlpath);
2426 
2448 HWLOC_DECLSPEC int hwloc_topology_export_xmlbuffer(hwloc_topology_t topology, char **xmlbuffer, int *buflen);
2449 
2451 HWLOC_DECLSPEC void hwloc_free_xmlbuffer(hwloc_topology_t topology, char *xmlbuffer);
2452 
2471 HWLOC_DECLSPEC void hwloc_topology_set_userdata_export_callback(hwloc_topology_t topology,
2472  void (*export_cb)(void *reserved, hwloc_topology_t topology, hwloc_obj_t obj));
2473 
2499 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 
2514 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 
2538 HWLOC_DECLSPEC void hwloc_topology_set_userdata_import_callback(hwloc_topology_t topology,
2539  void (*import_cb)(hwloc_topology_t topology, hwloc_obj_t obj, const char *name, const void *buffer, size_t length));
2540 
2559 
2567 };
2568 
2587  HWLOC_DECLSPEC int hwloc_topology_export_synthetic(hwloc_topology_t topology, char *buffer, size_t buflen, unsigned long flags);
2588 
2593 #ifdef __cplusplus
2594 } /* extern "C" */
2595 #endif
2596 
2597 
2598 /* high-level helpers */
2599 #include <hwloc/helper.h>
2600 
2601 /* inline code of some functions above */
2602 #include <hwloc/inlines.h>
2603 
2604 /* topology diffs */
2605 #include <hwloc/diff.h>
2606 
2607 /* deprecated headers */
2608 #include <hwloc/deprecated.h>
2609 
2610 #endif /* HWLOC_H */