Open MPI logo

Portable Hardware Locality (hwloc) Documentation: v1.5.2

  |   Home   |   Support   |   FAQ   |  
hwloc.h
1 /*
2  * Copyright © 2009 CNRS
3  * Copyright © 2009-2012 inria. All rights reserved.
4  * Copyright © 2009-2012 Université Bordeaux 1
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  *=====================================================================*/
38 
46 #ifndef HWLOC_H
47 #define HWLOC_H
48 
49 #include <hwloc/autogen/config.h>
50 #include <sys/types.h>
51 #include <stdio.h>
52 #include <string.h>
53 #include <limits.h>
54 
55 /*
56  * Symbol transforms
57  */
58 #include <hwloc/rename.h>
59 
60 /*
61  * Bitmap definitions
62  */
63 
64 #include <hwloc/bitmap.h>
65 
66 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 
71 
77 #define HWLOC_API_VERSION 0x00010500
78 
80  unsigned hwloc_get_api_version(void);
81 
90 struct hwloc_topology;
95 typedef struct hwloc_topology * hwloc_topology_t;
96 
130 
148 
163 typedef enum {
164  /* ***************************************************************
165  WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
166 
167  If new enum values are added here, you MUST also go update the
168  obj_type_order[] and obj_order_type[] arrays in src/topology.c.
169 
170  WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
171  *************************************************************** */
172 
244  /* ***************************************************************
245  WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
246 
247  If new enum values are added here, you MUST also go update the
248  obj_type_order[] and obj_order_type[] arrays in src/topology.c.
249 
250  WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
251  *************************************************************** */
253 
261 
267 
281 
300 
303 };
304 
313 union hwloc_obj_attr_u;
314 
317  hwloc_uint64_t total_memory;
318  hwloc_uint64_t local_memory;
320  unsigned page_types_len;
327  hwloc_uint64_t size;
328  hwloc_uint64_t count;
329  } * page_types;
330 };
331 
336 struct hwloc_obj {
337  /* physical information */
339  unsigned os_index;
340  char *name;
347  /* global position */
348  unsigned depth;
353  unsigned logical_index;
355  signed os_level;
357  /* cousins are all objects of the same type (and depth) across the entire topology */
361  /* children of the same parent are siblings, even if they may have different type and depth */
362  struct hwloc_obj *parent;
363  unsigned sibling_rank;
367  /* children array below this object */
368  unsigned arity;
369  struct hwloc_obj **children;
373  /* misc */
374  void *userdata;
376  /* cpusets and nodesets */
377  hwloc_cpuset_t cpuset;
390  hwloc_cpuset_t complete_cpuset;
401  hwloc_cpuset_t online_cpuset;
409  hwloc_cpuset_t allowed_cpuset;
420  hwloc_nodeset_t nodeset;
437  hwloc_nodeset_t complete_nodeset;
451  hwloc_nodeset_t allowed_nodeset;
465  unsigned distances_count;
466 
468  unsigned infos_count;
475 };
479 typedef struct hwloc_obj * hwloc_obj_t;
480 
485  hwloc_uint64_t size;
486  unsigned depth;
487  unsigned linesize;
491  } cache;
494  unsigned depth;
495  } group;
498  unsigned short domain;
499  unsigned char bus, dev, func;
500  unsigned short class_id;
502  unsigned char revision;
503  float linkspeed; /* in GB/s */
504  } pcidev;
507  union {
509  } upstream;
511  union {
512  struct {
513  unsigned short domain;
515  } pci;
516  } downstream;
518  unsigned depth;
519  } bridge;
523  } osdev;
524 };
525 
541  unsigned relative_depth;
543  unsigned nbobjs;
548  float *latency;
553  float latency_max;
554  float latency_base;
558 };
559 
562  char *name;
563  char *value;
564 };
565 
580  int hwloc_topology_init (hwloc_topology_t *topologyp);
581 
594  int hwloc_topology_load(hwloc_topology_t topology);
595 
600  void hwloc_topology_destroy (hwloc_topology_t topology);
601 
613  void hwloc_topology_check(hwloc_topology_t topology);
614 
649  int hwloc_topology_ignore_type(hwloc_topology_t topology, hwloc_obj_type_t type);
650 
659  int hwloc_topology_ignore_type_keep_structure(hwloc_topology_t topology, hwloc_obj_type_t type);
660 
668  int hwloc_topology_ignore_all_keep_structure(hwloc_topology_t topology);
669 
714 
722 
730 
737 };
738 
746  int hwloc_topology_set_flags (hwloc_topology_t topology, unsigned long flags);
747 
762  int hwloc_topology_set_pid(hwloc_topology_t restrict topology, hwloc_pid_t pid);
763 
788  int hwloc_topology_set_fsroot(hwloc_topology_t restrict topology, const char * restrict fsroot_path);
789 
814  int hwloc_topology_set_synthetic(hwloc_topology_t restrict topology, const char * restrict description);
815 
837  int hwloc_topology_set_xml(hwloc_topology_t restrict topology, const char * restrict xmlpath);
838 
860  int hwloc_topology_set_xmlbuffer(hwloc_topology_t restrict topology, const char * restrict buffer, int size);
861 
871  int hwloc_topology_set_custom(hwloc_topology_t topology);
872 
890  int hwloc_topology_set_distance_matrix(hwloc_topology_t restrict topology,
891  hwloc_obj_type_t type, unsigned nbobjs,
892  unsigned *os_index, float *distances);
893 
897  unsigned char pu;
898 };
899 
903  unsigned char set_thisproc_cpubind;
905  unsigned char get_thisproc_cpubind;
907  unsigned char set_proc_cpubind;
909  unsigned char get_proc_cpubind;
911  unsigned char set_thisthread_cpubind;
913  unsigned char get_thisthread_cpubind;
915  unsigned char set_thread_cpubind;
917  unsigned char get_thread_cpubind;
924 };
925 
929  unsigned char set_thisproc_membind;
931  unsigned char get_thisproc_membind;
933  unsigned char set_proc_membind;
935  unsigned char get_proc_membind;
937  unsigned char set_thisthread_membind;
939  unsigned char get_thisthread_membind;
941  unsigned char set_area_membind;
943  unsigned char get_area_membind;
945  unsigned char alloc_membind;
947  unsigned char firsttouch_membind;
949  unsigned char bind_membind;
951  unsigned char interleave_membind;
953  unsigned char replicate_membind;
955  unsigned char nexttouch_membind;
956 
958  unsigned char migrate_membind;
959 };
960 
971 };
972 
974  const struct hwloc_topology_support *hwloc_topology_get_support(hwloc_topology_t restrict topology);
975 
994  int hwloc_topology_export_xml(hwloc_topology_t topology, const char *xmlpath);
995 
1009  int hwloc_topology_export_xmlbuffer(hwloc_topology_t topology, char **xmlbuffer, int *buflen);
1010 
1012  void hwloc_free_xmlbuffer(hwloc_topology_t topology, char *xmlbuffer);
1013 
1028  hwloc_obj_t hwloc_topology_insert_misc_object_by_cpuset(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset, const char *name);
1029 
1045  hwloc_obj_t hwloc_topology_insert_misc_object_by_parent(hwloc_topology_t topology, hwloc_obj_t parent, const char *name);
1046 
1064 };
1065 
1078  int hwloc_topology_restrict(hwloc_topology_t restrict topology, hwloc_const_cpuset_t cpuset, unsigned long flags);
1079 
1097  unsigned hwloc_topology_get_depth(hwloc_topology_t restrict topology) ;
1098 
1121  int hwloc_get_type_depth (hwloc_topology_t topology, hwloc_obj_type_t type);
1122 
1129 };
1130 
1135  hwloc_obj_type_t hwloc_get_depth_type (hwloc_topology_t topology, unsigned depth) ;
1136 
1139  unsigned hwloc_get_nbobjs_by_depth (hwloc_topology_t topology, unsigned depth) ;
1140 
1146 static inline int
1147 hwloc_get_nbobjs_by_type (hwloc_topology_t topology, hwloc_obj_type_t type) ;
1148 static inline int
1149 hwloc_get_nbobjs_by_type (hwloc_topology_t topology, hwloc_obj_type_t type)
1150 {
1151  int depth = hwloc_get_type_depth(topology, type);
1152  if (depth == HWLOC_TYPE_DEPTH_UNKNOWN)
1153  return 0;
1154  if (depth == HWLOC_TYPE_DEPTH_MULTIPLE)
1155  return -1; /* FIXME: agregate nbobjs from different levels? */
1156  return hwloc_get_nbobjs_by_depth(topology, depth);
1157 }
1158 
1166  int hwloc_topology_is_thissystem(hwloc_topology_t restrict topology) ;
1167 
1182  hwloc_obj_t hwloc_get_obj_by_depth (hwloc_topology_t topology, unsigned depth, unsigned idx) ;
1183 
1190 static inline hwloc_obj_t
1191 hwloc_get_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type, unsigned idx) ;
1192 static inline hwloc_obj_t
1193 hwloc_get_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type, unsigned idx)
1194 {
1195  int depth = hwloc_get_type_depth(topology, type);
1196  if (depth == HWLOC_TYPE_DEPTH_UNKNOWN)
1197  return NULL;
1198  if (depth == HWLOC_TYPE_DEPTH_MULTIPLE)
1199  return NULL;
1200  return hwloc_get_obj_by_depth(topology, depth, idx);
1201 }
1202 
1212  const char * hwloc_obj_type_string (hwloc_obj_type_t type) ;
1213 
1218  hwloc_obj_type_t hwloc_obj_type_of_string (const char * string) ;
1219 
1230  int hwloc_obj_type_snprintf(char * restrict string, size_t size, hwloc_obj_t obj,
1231  int verbose);
1232 
1244  int hwloc_obj_attr_snprintf(char * restrict string, size_t size, hwloc_obj_t obj, const char * restrict separator,
1245  int verbose);
1246 
1267  int hwloc_obj_snprintf(char * restrict string, size_t size,
1268  hwloc_topology_t topology, hwloc_obj_t obj,
1269  const char * restrict indexprefix, int verbose);
1270 
1278  int hwloc_obj_cpuset_snprintf(char * restrict str, size_t size, size_t nobj, const hwloc_obj_t * restrict objs);
1279 
1286 static inline const char *
1287 hwloc_obj_get_info_by_name(hwloc_obj_t obj, const char *name) ;
1288 static inline const char *
1289 hwloc_obj_get_info_by_name(hwloc_obj_t obj, const char *name)
1290 {
1291  unsigned i;
1292  for(i=0; i<obj->infos_count; i++)
1293  if (!strcmp(obj->infos[i].name, name))
1294  return obj->infos[i].value;
1295  return NULL;
1296 }
1297 
1308  void hwloc_obj_add_info(hwloc_obj_t obj, const char *name, const char *value);
1309 
1367 typedef enum {
1422 
1428  int hwloc_set_cpubind(hwloc_topology_t topology, hwloc_const_cpuset_t set, int flags);
1429 
1435  int hwloc_get_cpubind(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
1436 
1444  int hwloc_set_proc_cpubind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_cpuset_t set, int flags);
1445 
1457  int hwloc_get_proc_cpubind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t set, int flags);
1458 
1459 #ifdef hwloc_thread_t
1460 
1467  int hwloc_set_thread_cpubind(hwloc_topology_t topology, hwloc_thread_t thread, hwloc_const_cpuset_t set, int flags);
1468 #endif
1469 
1470 #ifdef hwloc_thread_t
1471 
1478  int hwloc_get_thread_cpubind(hwloc_topology_t topology, hwloc_thread_t thread, hwloc_cpuset_t set, int flags);
1479 #endif
1480 
1494  int hwloc_get_last_cpu_location(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
1495 
1510  int hwloc_get_proc_last_cpu_location(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t set, int flags);
1511 
1579 typedef enum {
1651 
1663 typedef enum {
1720 
1733  int hwloc_set_membind_nodeset(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags);
1734 
1748  int hwloc_set_membind(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset, hwloc_membind_policy_t policy, int flags);
1749 
1790  int hwloc_get_membind_nodeset(hwloc_topology_t topology, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags);
1791 
1837  int hwloc_get_membind(hwloc_topology_t topology, hwloc_cpuset_t cpuset, hwloc_membind_policy_t * policy, int flags);
1838 
1848  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);
1849 
1859  int hwloc_set_proc_membind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_cpuset_t cpuset, hwloc_membind_policy_t policy, int flags);
1860 
1897  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);
1898 
1938  int hwloc_get_proc_membind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t cpuset, hwloc_membind_policy_t * policy, int flags);
1939 
1946  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);
1947 
1954  int hwloc_set_area_membind(hwloc_topology_t topology, const void *addr, size_t len, hwloc_const_cpuset_t cpuset, hwloc_membind_policy_t policy, int flags);
1955 
1978  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);
1979 
2004  int hwloc_get_area_membind(hwloc_topology_t topology, const void *addr, size_t len, hwloc_cpuset_t cpuset, hwloc_membind_policy_t * policy, int flags);
2005 
2013  void *hwloc_alloc(hwloc_topology_t topology, size_t len);
2014 
2024  void *hwloc_alloc_membind_nodeset(hwloc_topology_t topology, size_t len, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags) ;
2025 
2035  void *hwloc_alloc_membind(hwloc_topology_t topology, size_t len, hwloc_const_cpuset_t cpuset, hwloc_membind_policy_t policy, int flags) ;
2036 
2040  int hwloc_free(hwloc_topology_t topology, void *addr, size_t len);
2041 
2072  int hwloc_custom_insert_topology(hwloc_topology_t newtopology, hwloc_obj_t newparent, hwloc_topology_t oldtopology, hwloc_obj_t oldroot);
2073 
2090  hwloc_obj_t hwloc_custom_insert_group_object_by_parent(hwloc_topology_t topology, hwloc_obj_t parent, int groupdepth);
2091 
2096 #ifdef __cplusplus
2097 } /* extern "C" */
2098 #endif
2099 
2100 
2101 /* high-level helpers */
2102 #include <hwloc/helper.h>
2103 
2104 
2105 #endif /* HWLOC_H */