00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00053 #ifndef HWLOC_H
00054 #define HWLOC_H
00055
00056 #include <hwloc/autogen/config.h>
00057 #include <sys/types.h>
00058 #include <stdio.h>
00059 #include <string.h>
00060 #include <limits.h>
00061
00062
00063
00064
00065 #include <hwloc/rename.h>
00066
00067
00068
00069
00070
00071 #include <hwloc/bitmap.h>
00072
00073
00074 #ifdef __cplusplus
00075 extern "C" {
00076 #endif
00077
00078
00095 #define HWLOC_API_VERSION 0x00020000
00096
00101 HWLOC_DECLSPEC unsigned hwloc_get_api_version(void);
00102
00104 #define HWLOC_COMPONENT_ABI 5
00105
00139 typedef hwloc_bitmap_t hwloc_cpuset_t;
00141 typedef hwloc_const_bitmap_t hwloc_const_cpuset_t;
00142
00156 typedef hwloc_bitmap_t hwloc_nodeset_t;
00159 typedef hwloc_const_bitmap_t hwloc_const_nodeset_t;
00160
00175 #define HWLOC_OBJ_TYPE_MIN HWLOC_OBJ_MACHINE
00176 typedef enum {
00177 HWLOC_OBJ_MACHINE,
00186 HWLOC_OBJ_PACKAGE,
00191 HWLOC_OBJ_CORE,
00195 HWLOC_OBJ_PU,
00207 HWLOC_OBJ_L1CACHE,
00208 HWLOC_OBJ_L2CACHE,
00209 HWLOC_OBJ_L3CACHE,
00210 HWLOC_OBJ_L4CACHE,
00211 HWLOC_OBJ_L5CACHE,
00213 HWLOC_OBJ_L1ICACHE,
00214 HWLOC_OBJ_L2ICACHE,
00215 HWLOC_OBJ_L3ICACHE,
00217 HWLOC_OBJ_GROUP,
00230 HWLOC_OBJ_NUMANODE,
00247 HWLOC_OBJ_BRIDGE,
00256 HWLOC_OBJ_PCI_DEVICE,
00263 HWLOC_OBJ_OS_DEVICE,
00271 HWLOC_OBJ_MISC,
00282 HWLOC_OBJ_TYPE_MAX
00283 } hwloc_obj_type_t;
00284
00286 typedef enum hwloc_obj_cache_type_e {
00287 HWLOC_OBJ_CACHE_UNIFIED,
00288 HWLOC_OBJ_CACHE_DATA,
00289 HWLOC_OBJ_CACHE_INSTRUCTION
00290 } hwloc_obj_cache_type_t;
00291
00293 typedef enum hwloc_obj_bridge_type_e {
00294 HWLOC_OBJ_BRIDGE_HOST,
00295 HWLOC_OBJ_BRIDGE_PCI
00296 } hwloc_obj_bridge_type_t;
00297
00299 typedef enum hwloc_obj_osdev_type_e {
00300 HWLOC_OBJ_OSDEV_BLOCK,
00302 HWLOC_OBJ_OSDEV_GPU,
00305 HWLOC_OBJ_OSDEV_NETWORK,
00307 HWLOC_OBJ_OSDEV_OPENFABRICS,
00310 HWLOC_OBJ_OSDEV_DMA,
00312 HWLOC_OBJ_OSDEV_COPROC
00316 } hwloc_obj_osdev_type_t;
00317
00337 HWLOC_DECLSPEC int hwloc_compare_types (hwloc_obj_type_t type1, hwloc_obj_type_t type2) __hwloc_attribute_const;
00338
00339 enum hwloc_compare_types_e {
00340 HWLOC_TYPE_UNORDERED = INT_MAX
00341 };
00342
00351 union hwloc_obj_attr_u;
00352
00357 struct hwloc_obj {
00358
00359 hwloc_obj_type_t type;
00360 char *subtype;
00362 unsigned os_index;
00367 #define HWLOC_UNKNOWN_INDEX (unsigned)-1
00368
00369 char *name;
00374 hwloc_uint64_t total_memory;
00376 union hwloc_obj_attr_u *attr;
00379
00380 int depth;
00395 unsigned logical_index;
00402
00403 struct hwloc_obj *next_cousin;
00404 struct hwloc_obj *prev_cousin;
00406
00407 struct hwloc_obj *parent;
00408 unsigned sibling_rank;
00409 struct hwloc_obj *next_sibling;
00410 struct hwloc_obj *prev_sibling;
00413 unsigned arity;
00417 struct hwloc_obj **children;
00418 struct hwloc_obj *first_child;
00419 struct hwloc_obj *last_child;
00422 int symmetric_subtree;
00433 unsigned memory_arity;
00436 struct hwloc_obj *memory_first_child;
00445 unsigned io_arity;
00448 struct hwloc_obj *io_first_child;
00457 unsigned misc_arity;
00460 struct hwloc_obj *misc_first_child;
00466
00467 hwloc_cpuset_t cpuset;
00482 hwloc_cpuset_t complete_cpuset;
00495 hwloc_nodeset_t nodeset;
00515 hwloc_nodeset_t complete_nodeset;
00531 struct hwloc_info_s *infos;
00532 unsigned infos_count;
00534
00535 void *userdata;
00540 hwloc_uint64_t gp_index;
00545 };
00549 typedef struct hwloc_obj * hwloc_obj_t;
00550
00552 union hwloc_obj_attr_u {
00554 struct hwloc_numanode_attr_s {
00555 hwloc_uint64_t local_memory;
00556 unsigned page_types_len;
00562 struct hwloc_memory_page_type_s {
00563 hwloc_uint64_t size;
00564 hwloc_uint64_t count;
00565 } * page_types;
00566 } numanode;
00567
00569 struct hwloc_cache_attr_s {
00570 hwloc_uint64_t size;
00571 unsigned depth;
00572 unsigned linesize;
00573 int associativity;
00575 hwloc_obj_cache_type_t type;
00576 } cache;
00578 struct hwloc_group_attr_s {
00579 unsigned depth;
00581 unsigned kind;
00582 unsigned subkind;
00583 unsigned char dont_merge;
00584 } group;
00586 struct hwloc_pcidev_attr_s {
00587 unsigned short domain;
00588 unsigned char bus, dev, func;
00589 unsigned short class_id;
00590 unsigned short vendor_id, device_id, subvendor_id, subdevice_id;
00591 unsigned char revision;
00592 float linkspeed;
00593 } pcidev;
00595 struct hwloc_bridge_attr_s {
00596 union {
00597 struct hwloc_pcidev_attr_s pci;
00598 } upstream;
00599 hwloc_obj_bridge_type_t upstream_type;
00600 union {
00601 struct {
00602 unsigned short domain;
00603 unsigned char secondary_bus, subordinate_bus;
00604 } pci;
00605 } downstream;
00606 hwloc_obj_bridge_type_t downstream_type;
00607 unsigned depth;
00608 } bridge;
00610 struct hwloc_osdev_attr_s {
00611 hwloc_obj_osdev_type_t type;
00612 } osdev;
00613 };
00614
00619 struct hwloc_info_s {
00620 char *name;
00621 char *value;
00622 };
00623
00632 struct hwloc_topology;
00637 typedef struct hwloc_topology * hwloc_topology_t;
00638
00645 HWLOC_DECLSPEC int hwloc_topology_init (hwloc_topology_t *topologyp);
00646
00667 HWLOC_DECLSPEC int hwloc_topology_load(hwloc_topology_t topology);
00668
00673 HWLOC_DECLSPEC void hwloc_topology_destroy (hwloc_topology_t topology);
00674
00685 HWLOC_DECLSPEC int hwloc_topology_dup(hwloc_topology_t *newtopology, hwloc_topology_t oldtopology);
00686
00704 HWLOC_DECLSPEC int hwloc_topology_abi_check(hwloc_topology_t topology);
00705
00717 HWLOC_DECLSPEC void hwloc_topology_check(hwloc_topology_t topology);
00718
00739 HWLOC_DECLSPEC int hwloc_topology_get_depth(hwloc_topology_t __hwloc_restrict topology) __hwloc_attribute_pure;
00740
00764 HWLOC_DECLSPEC int hwloc_get_type_depth (hwloc_topology_t topology, hwloc_obj_type_t type);
00765
00766 enum hwloc_get_type_depth_e {
00767 HWLOC_TYPE_DEPTH_UNKNOWN = -1,
00768 HWLOC_TYPE_DEPTH_MULTIPLE = -2,
00769 HWLOC_TYPE_DEPTH_NUMANODE = -3,
00770 HWLOC_TYPE_DEPTH_BRIDGE = -4,
00771 HWLOC_TYPE_DEPTH_PCI_DEVICE = -5,
00772 HWLOC_TYPE_DEPTH_OS_DEVICE = -6,
00773 HWLOC_TYPE_DEPTH_MISC = -7
00774 };
00775
00795 HWLOC_DECLSPEC int hwloc_get_memory_parents_depth (hwloc_topology_t topology);
00796
00810 static __hwloc_inline int
00811 hwloc_get_type_or_below_depth (hwloc_topology_t topology, hwloc_obj_type_t type) __hwloc_attribute_pure;
00812
00826 static __hwloc_inline int
00827 hwloc_get_type_or_above_depth (hwloc_topology_t topology, hwloc_obj_type_t type) __hwloc_attribute_pure;
00828
00835 HWLOC_DECLSPEC hwloc_obj_type_t hwloc_get_depth_type (hwloc_topology_t topology, int depth) __hwloc_attribute_pure;
00836
00839 HWLOC_DECLSPEC unsigned hwloc_get_nbobjs_by_depth (hwloc_topology_t topology, int depth) __hwloc_attribute_pure;
00840
00846 static __hwloc_inline int
00847 hwloc_get_nbobjs_by_type (hwloc_topology_t topology, hwloc_obj_type_t type) __hwloc_attribute_pure;
00848
00853 static __hwloc_inline hwloc_obj_t
00854 hwloc_get_root_obj (hwloc_topology_t topology) __hwloc_attribute_pure;
00855
00857 HWLOC_DECLSPEC hwloc_obj_t hwloc_get_obj_by_depth (hwloc_topology_t topology, int depth, unsigned idx) __hwloc_attribute_pure;
00858
00865 static __hwloc_inline hwloc_obj_t
00866 hwloc_get_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type, unsigned idx) __hwloc_attribute_pure;
00867
00872 static __hwloc_inline hwloc_obj_t
00873 hwloc_get_next_obj_by_depth (hwloc_topology_t topology, int depth, hwloc_obj_t prev);
00874
00881 static __hwloc_inline hwloc_obj_t
00882 hwloc_get_next_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type,
00883 hwloc_obj_t prev);
00884
00901 HWLOC_DECLSPEC const char * hwloc_obj_type_string (hwloc_obj_type_t type) __hwloc_attribute_const;
00902
00920 HWLOC_DECLSPEC int hwloc_obj_type_snprintf(char * __hwloc_restrict string, size_t size,
00921 hwloc_obj_t obj,
00922 int verbose);
00923
00935 HWLOC_DECLSPEC int hwloc_obj_attr_snprintf(char * __hwloc_restrict string, size_t size,
00936 hwloc_obj_t obj, const char * __hwloc_restrict separator,
00937 int verbose);
00938
00962 HWLOC_DECLSPEC int hwloc_type_sscanf(const char *string,
00963 hwloc_obj_type_t *typep,
00964 union hwloc_obj_attr_u *attrp, size_t attrsize);
00965
00987 HWLOC_DECLSPEC int hwloc_type_sscanf_as_depth(const char *string,
00988 hwloc_obj_type_t *typep,
00989 hwloc_topology_t topology, int *depthp);
00990
01006 static __hwloc_inline const char *
01007 hwloc_obj_get_info_by_name(hwloc_obj_t obj, const char *name) __hwloc_attribute_pure;
01008
01025 HWLOC_DECLSPEC int hwloc_obj_add_info(hwloc_obj_t obj, const char *name, const char *value);
01026
01098 typedef enum {
01101 HWLOC_CPUBIND_PROCESS = (1<<0),
01102
01105 HWLOC_CPUBIND_THREAD = (1<<1),
01106
01130 HWLOC_CPUBIND_STRICT = (1<<2),
01131
01147 HWLOC_CPUBIND_NOMEMBIND = (1<<3)
01148 } hwloc_cpubind_flags_t;
01149
01155 HWLOC_DECLSPEC int hwloc_set_cpubind(hwloc_topology_t topology, hwloc_const_cpuset_t set, int flags);
01156
01162 HWLOC_DECLSPEC int hwloc_get_cpubind(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
01163
01175 HWLOC_DECLSPEC int hwloc_set_proc_cpubind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_cpuset_t set, int flags);
01176
01188 HWLOC_DECLSPEC int hwloc_get_proc_cpubind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t set, int flags);
01189
01190 #ifdef hwloc_thread_t
01191
01198 HWLOC_DECLSPEC int hwloc_set_thread_cpubind(hwloc_topology_t topology, hwloc_thread_t thread, hwloc_const_cpuset_t set, int flags);
01199 #endif
01200
01201 #ifdef hwloc_thread_t
01202
01209 HWLOC_DECLSPEC int hwloc_get_thread_cpubind(hwloc_topology_t topology, hwloc_thread_t thread, hwloc_cpuset_t set, int flags);
01210 #endif
01211
01225 HWLOC_DECLSPEC int hwloc_get_last_cpu_location(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
01226
01243 HWLOC_DECLSPEC int hwloc_get_proc_last_cpu_location(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t set, int flags);
01244
01324 typedef enum {
01332 HWLOC_MEMBIND_DEFAULT = 0,
01333
01343 HWLOC_MEMBIND_FIRSTTOUCH = 1,
01344
01347 HWLOC_MEMBIND_BIND = 2,
01348
01356 HWLOC_MEMBIND_INTERLEAVE = 3,
01357
01363 HWLOC_MEMBIND_NEXTTOUCH = 4,
01364
01371 HWLOC_MEMBIND_MIXED = -1
01372 } hwloc_membind_policy_t;
01373
01387 typedef enum {
01392 HWLOC_MEMBIND_PROCESS = (1<<0),
01393
01397 HWLOC_MEMBIND_THREAD = (1<<1),
01398
01405 HWLOC_MEMBIND_STRICT = (1<<2),
01406
01411 HWLOC_MEMBIND_MIGRATE = (1<<3),
01412
01424 HWLOC_MEMBIND_NOCPUBIND = (1<<4),
01425
01435 HWLOC_MEMBIND_BYNODESET = (1<<5)
01436 } hwloc_membind_flags_t;
01437
01453 HWLOC_DECLSPEC int hwloc_set_membind(hwloc_topology_t topology, hwloc_const_bitmap_t set, hwloc_membind_policy_t policy, int flags);
01454
01499 HWLOC_DECLSPEC int hwloc_get_membind(hwloc_topology_t topology, hwloc_bitmap_t set, hwloc_membind_policy_t * policy, int flags);
01500
01513 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);
01514
01554 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);
01555
01566 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);
01567
01595 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);
01596
01616 HWLOC_DECLSPEC int hwloc_get_area_memlocation(hwloc_topology_t topology, const void *addr, size_t len, hwloc_bitmap_t set, int flags);
01617
01625 HWLOC_DECLSPEC void *hwloc_alloc(hwloc_topology_t topology, size_t len);
01626
01641 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;
01642
01652 static __hwloc_inline void *
01653 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;
01654
01658 HWLOC_DECLSPEC int hwloc_free(hwloc_topology_t topology, void *addr, size_t len);
01659
01696 HWLOC_DECLSPEC int hwloc_topology_set_pid(hwloc_topology_t __hwloc_restrict topology, hwloc_pid_t pid);
01697
01726 HWLOC_DECLSPEC int hwloc_topology_set_synthetic(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict description);
01727
01754 HWLOC_DECLSPEC int hwloc_topology_set_xml(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict xmlpath);
01755
01782 HWLOC_DECLSPEC int hwloc_topology_set_xmlbuffer(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict buffer, int size);
01783
01802 enum hwloc_topology_flags_e {
01824 HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM = (1UL<<0),
01825
01844 HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM = (1UL<<1),
01845
01865 HWLOC_TOPOLOGY_FLAG_THISSYSTEM_ALLOWED_RESOURCES = (1UL<<2)
01866 };
01867
01877 HWLOC_DECLSPEC int hwloc_topology_set_flags (hwloc_topology_t topology, unsigned long flags);
01878
01885 HWLOC_DECLSPEC unsigned long hwloc_topology_get_flags (hwloc_topology_t topology);
01886
01894 HWLOC_DECLSPEC int hwloc_topology_is_thissystem(hwloc_topology_t __hwloc_restrict topology) __hwloc_attribute_pure;
01895
01897 struct hwloc_topology_discovery_support {
01899 unsigned char pu;
01901 unsigned char numa;
01903 unsigned char numa_memory;
01904 };
01905
01911 struct hwloc_topology_cpubind_support {
01913 unsigned char set_thisproc_cpubind;
01915 unsigned char get_thisproc_cpubind;
01917 unsigned char set_proc_cpubind;
01919 unsigned char get_proc_cpubind;
01921 unsigned char set_thisthread_cpubind;
01923 unsigned char get_thisthread_cpubind;
01925 unsigned char set_thread_cpubind;
01927 unsigned char get_thread_cpubind;
01929 unsigned char get_thisproc_last_cpu_location;
01931 unsigned char get_proc_last_cpu_location;
01933 unsigned char get_thisthread_last_cpu_location;
01934 };
01935
01941 struct hwloc_topology_membind_support {
01943 unsigned char set_thisproc_membind;
01945 unsigned char get_thisproc_membind;
01947 unsigned char set_proc_membind;
01949 unsigned char get_proc_membind;
01951 unsigned char set_thisthread_membind;
01953 unsigned char get_thisthread_membind;
01955 unsigned char set_area_membind;
01957 unsigned char get_area_membind;
01959 unsigned char alloc_membind;
01961 unsigned char firsttouch_membind;
01963 unsigned char bind_membind;
01965 unsigned char interleave_membind;
01967 unsigned char nexttouch_membind;
01969 unsigned char migrate_membind;
01971 unsigned char get_area_memlocation;
01972 };
01973
01980 struct hwloc_topology_support {
01981 struct hwloc_topology_discovery_support *discovery;
01982 struct hwloc_topology_cpubind_support *cpubind;
01983 struct hwloc_topology_membind_support *membind;
01984 };
01985
01995 HWLOC_DECLSPEC const struct hwloc_topology_support *hwloc_topology_get_support(hwloc_topology_t __hwloc_restrict topology);
01996
02006 enum hwloc_type_filter_e {
02012 HWLOC_TYPE_FILTER_KEEP_ALL = 0,
02013
02020 HWLOC_TYPE_FILTER_KEEP_NONE = 1,
02021
02034 HWLOC_TYPE_FILTER_KEEP_STRUCTURE = 2,
02035
02049 HWLOC_TYPE_FILTER_KEEP_IMPORTANT = 3
02050 };
02051
02054 HWLOC_DECLSPEC int hwloc_topology_set_type_filter(hwloc_topology_t topology, hwloc_obj_type_t type, enum hwloc_type_filter_e filter);
02055
02058 HWLOC_DECLSPEC int hwloc_topology_get_type_filter(hwloc_topology_t topology, hwloc_obj_type_t type, enum hwloc_type_filter_e *filter);
02059
02064 HWLOC_DECLSPEC int hwloc_topology_set_all_types_filter(hwloc_topology_t topology, enum hwloc_type_filter_e filter);
02065
02068 HWLOC_DECLSPEC int hwloc_topology_set_cache_types_filter(hwloc_topology_t topology, enum hwloc_type_filter_e filter);
02069
02072 HWLOC_DECLSPEC int hwloc_topology_set_icache_types_filter(hwloc_topology_t topology, enum hwloc_type_filter_e filter);
02073
02076 HWLOC_DECLSPEC int hwloc_topology_set_io_types_filter(hwloc_topology_t topology, enum hwloc_type_filter_e filter);
02077
02088 HWLOC_DECLSPEC void hwloc_topology_set_userdata(hwloc_topology_t topology, const void *userdata);
02089
02095 HWLOC_DECLSPEC void * hwloc_topology_get_userdata(hwloc_topology_t topology);
02096
02106 enum hwloc_restrict_flags_e {
02111 HWLOC_RESTRICT_FLAG_REMOVE_CPULESS = (1UL<<0),
02112
02117 HWLOC_RESTRICT_FLAG_ADAPT_MISC = (1UL<<1),
02118
02123 HWLOC_RESTRICT_FLAG_ADAPT_IO = (1UL<<2)
02124 };
02125
02147 HWLOC_DECLSPEC int hwloc_topology_restrict(hwloc_topology_t __hwloc_restrict topology, hwloc_const_cpuset_t cpuset, unsigned long flags);
02148
02170 HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_insert_misc_object(hwloc_topology_t topology, hwloc_obj_t parent, const char *name);
02171
02192 HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_alloc_group_object(hwloc_topology_t topology);
02193
02230 HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_insert_group_object(hwloc_topology_t topology, hwloc_obj_t group);
02231
02241 HWLOC_DECLSPEC int hwloc_obj_add_other_obj_sets(hwloc_obj_t dst, hwloc_obj_t src);
02242
02247 #ifdef __cplusplus
02248 }
02249 #endif
02250
02251
02252
02253 #include <hwloc/helper.h>
02254
02255
02256 #include <hwloc/inlines.h>
02257
02258
02259 #include <hwloc/export.h>
02260
02261
02262 #include <hwloc/distances.h>
02263
02264
02265 #include <hwloc/diff.h>
02266
02267
02268 #include <hwloc/deprecated.h>
02269
02270 #endif