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 } group;
00585 struct hwloc_pcidev_attr_s {
00586 unsigned short domain;
00587 unsigned char bus, dev, func;
00588 unsigned short class_id;
00589 unsigned short vendor_id, device_id, subvendor_id, subdevice_id;
00590 unsigned char revision;
00591 float linkspeed;
00592 } pcidev;
00594 struct hwloc_bridge_attr_s {
00595 union {
00596 struct hwloc_pcidev_attr_s pci;
00597 } upstream;
00598 hwloc_obj_bridge_type_t upstream_type;
00599 union {
00600 struct {
00601 unsigned short domain;
00602 unsigned char secondary_bus, subordinate_bus;
00603 } pci;
00604 } downstream;
00605 hwloc_obj_bridge_type_t downstream_type;
00606 unsigned depth;
00607 } bridge;
00609 struct hwloc_osdev_attr_s {
00610 hwloc_obj_osdev_type_t type;
00611 } osdev;
00612 };
00613
00618 struct hwloc_info_s {
00619 char *name;
00620 char *value;
00621 };
00622
00631 struct hwloc_topology;
00636 typedef struct hwloc_topology * hwloc_topology_t;
00637
00644 HWLOC_DECLSPEC int hwloc_topology_init (hwloc_topology_t *topologyp);
00645
00666 HWLOC_DECLSPEC int hwloc_topology_load(hwloc_topology_t topology);
00667
00672 HWLOC_DECLSPEC void hwloc_topology_destroy (hwloc_topology_t topology);
00673
00684 HWLOC_DECLSPEC int hwloc_topology_dup(hwloc_topology_t *newtopology, hwloc_topology_t oldtopology);
00685
00703 HWLOC_DECLSPEC int hwloc_topology_abi_check(hwloc_topology_t topology);
00704
00716 HWLOC_DECLSPEC void hwloc_topology_check(hwloc_topology_t topology);
00717
00738 HWLOC_DECLSPEC int hwloc_topology_get_depth(hwloc_topology_t __hwloc_restrict topology) __hwloc_attribute_pure;
00739
00763 HWLOC_DECLSPEC int hwloc_get_type_depth (hwloc_topology_t topology, hwloc_obj_type_t type);
00764
00765 enum hwloc_get_type_depth_e {
00766 HWLOC_TYPE_DEPTH_UNKNOWN = -1,
00767 HWLOC_TYPE_DEPTH_MULTIPLE = -2,
00768 HWLOC_TYPE_DEPTH_NUMANODE = -3,
00769 HWLOC_TYPE_DEPTH_BRIDGE = -4,
00770 HWLOC_TYPE_DEPTH_PCI_DEVICE = -5,
00771 HWLOC_TYPE_DEPTH_OS_DEVICE = -6,
00772 HWLOC_TYPE_DEPTH_MISC = -7
00773 };
00774
00794 HWLOC_DECLSPEC int hwloc_get_memory_parents_depth (hwloc_topology_t topology);
00795
00809 static __hwloc_inline int
00810 hwloc_get_type_or_below_depth (hwloc_topology_t topology, hwloc_obj_type_t type) __hwloc_attribute_pure;
00811
00825 static __hwloc_inline int
00826 hwloc_get_type_or_above_depth (hwloc_topology_t topology, hwloc_obj_type_t type) __hwloc_attribute_pure;
00827
00834 HWLOC_DECLSPEC hwloc_obj_type_t hwloc_get_depth_type (hwloc_topology_t topology, int depth) __hwloc_attribute_pure;
00835
00838 HWLOC_DECLSPEC unsigned hwloc_get_nbobjs_by_depth (hwloc_topology_t topology, int depth) __hwloc_attribute_pure;
00839
00845 static __hwloc_inline int
00846 hwloc_get_nbobjs_by_type (hwloc_topology_t topology, hwloc_obj_type_t type) __hwloc_attribute_pure;
00847
00852 static __hwloc_inline hwloc_obj_t
00853 hwloc_get_root_obj (hwloc_topology_t topology) __hwloc_attribute_pure;
00854
00856 HWLOC_DECLSPEC hwloc_obj_t hwloc_get_obj_by_depth (hwloc_topology_t topology, int depth, unsigned idx) __hwloc_attribute_pure;
00857
00864 static __hwloc_inline hwloc_obj_t
00865 hwloc_get_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type, unsigned idx) __hwloc_attribute_pure;
00866
00871 static __hwloc_inline hwloc_obj_t
00872 hwloc_get_next_obj_by_depth (hwloc_topology_t topology, int depth, hwloc_obj_t prev);
00873
00880 static __hwloc_inline hwloc_obj_t
00881 hwloc_get_next_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type,
00882 hwloc_obj_t prev);
00883
00900 HWLOC_DECLSPEC const char * hwloc_obj_type_string (hwloc_obj_type_t type) __hwloc_attribute_const;
00901
00919 HWLOC_DECLSPEC int hwloc_obj_type_snprintf(char * __hwloc_restrict string, size_t size,
00920 hwloc_obj_t obj,
00921 int verbose);
00922
00934 HWLOC_DECLSPEC int hwloc_obj_attr_snprintf(char * __hwloc_restrict string, size_t size,
00935 hwloc_obj_t obj, const char * __hwloc_restrict separator,
00936 int verbose);
00937
00961 HWLOC_DECLSPEC int hwloc_type_sscanf(const char *string,
00962 hwloc_obj_type_t *typep,
00963 union hwloc_obj_attr_u *attrp, size_t attrsize);
00964
00986 HWLOC_DECLSPEC int hwloc_type_sscanf_as_depth(const char *string,
00987 hwloc_obj_type_t *typep,
00988 hwloc_topology_t topology, int *depthp);
00989
01005 static __hwloc_inline const char *
01006 hwloc_obj_get_info_by_name(hwloc_obj_t obj, const char *name) __hwloc_attribute_pure;
01007
01024 HWLOC_DECLSPEC int hwloc_obj_add_info(hwloc_obj_t obj, const char *name, const char *value);
01025
01097 typedef enum {
01100 HWLOC_CPUBIND_PROCESS = (1<<0),
01101
01104 HWLOC_CPUBIND_THREAD = (1<<1),
01105
01129 HWLOC_CPUBIND_STRICT = (1<<2),
01130
01146 HWLOC_CPUBIND_NOMEMBIND = (1<<3)
01147 } hwloc_cpubind_flags_t;
01148
01154 HWLOC_DECLSPEC int hwloc_set_cpubind(hwloc_topology_t topology, hwloc_const_cpuset_t set, int flags);
01155
01161 HWLOC_DECLSPEC int hwloc_get_cpubind(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
01162
01174 HWLOC_DECLSPEC int hwloc_set_proc_cpubind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_cpuset_t set, int flags);
01175
01187 HWLOC_DECLSPEC int hwloc_get_proc_cpubind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t set, int flags);
01188
01189 #ifdef hwloc_thread_t
01190
01197 HWLOC_DECLSPEC int hwloc_set_thread_cpubind(hwloc_topology_t topology, hwloc_thread_t thread, hwloc_const_cpuset_t set, int flags);
01198 #endif
01199
01200 #ifdef hwloc_thread_t
01201
01208 HWLOC_DECLSPEC int hwloc_get_thread_cpubind(hwloc_topology_t topology, hwloc_thread_t thread, hwloc_cpuset_t set, int flags);
01209 #endif
01210
01224 HWLOC_DECLSPEC int hwloc_get_last_cpu_location(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
01225
01242 HWLOC_DECLSPEC int hwloc_get_proc_last_cpu_location(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t set, int flags);
01243
01323 typedef enum {
01331 HWLOC_MEMBIND_DEFAULT = 0,
01332
01342 HWLOC_MEMBIND_FIRSTTOUCH = 1,
01343
01346 HWLOC_MEMBIND_BIND = 2,
01347
01355 HWLOC_MEMBIND_INTERLEAVE = 3,
01356
01362 HWLOC_MEMBIND_NEXTTOUCH = 4,
01363
01370 HWLOC_MEMBIND_MIXED = -1
01371 } hwloc_membind_policy_t;
01372
01386 typedef enum {
01391 HWLOC_MEMBIND_PROCESS = (1<<0),
01392
01396 HWLOC_MEMBIND_THREAD = (1<<1),
01397
01404 HWLOC_MEMBIND_STRICT = (1<<2),
01405
01410 HWLOC_MEMBIND_MIGRATE = (1<<3),
01411
01423 HWLOC_MEMBIND_NOCPUBIND = (1<<4),
01424
01434 HWLOC_MEMBIND_BYNODESET = (1<<5)
01435 } hwloc_membind_flags_t;
01436
01452 HWLOC_DECLSPEC int hwloc_set_membind(hwloc_topology_t topology, hwloc_const_bitmap_t set, hwloc_membind_policy_t policy, int flags);
01453
01498 HWLOC_DECLSPEC int hwloc_get_membind(hwloc_topology_t topology, hwloc_bitmap_t set, hwloc_membind_policy_t * policy, int flags);
01499
01512 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);
01513
01553 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);
01554
01565 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);
01566
01594 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);
01595
01615 HWLOC_DECLSPEC int hwloc_get_area_memlocation(hwloc_topology_t topology, const void *addr, size_t len, hwloc_bitmap_t set, int flags);
01616
01624 HWLOC_DECLSPEC void *hwloc_alloc(hwloc_topology_t topology, size_t len);
01625
01640 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;
01641
01651 static __hwloc_inline void *
01652 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;
01653
01657 HWLOC_DECLSPEC int hwloc_free(hwloc_topology_t topology, void *addr, size_t len);
01658
01695 HWLOC_DECLSPEC int hwloc_topology_set_pid(hwloc_topology_t __hwloc_restrict topology, hwloc_pid_t pid);
01696
01725 HWLOC_DECLSPEC int hwloc_topology_set_synthetic(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict description);
01726
01753 HWLOC_DECLSPEC int hwloc_topology_set_xml(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict xmlpath);
01754
01781 HWLOC_DECLSPEC int hwloc_topology_set_xmlbuffer(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict buffer, int size);
01782
01801 enum hwloc_topology_flags_e {
01823 HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM = (1UL<<0),
01824
01843 HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM = (1UL<<1),
01844
01864 HWLOC_TOPOLOGY_FLAG_THISSYSTEM_ALLOWED_RESOURCES = (1UL<<2)
01865 };
01866
01876 HWLOC_DECLSPEC int hwloc_topology_set_flags (hwloc_topology_t topology, unsigned long flags);
01877
01884 HWLOC_DECLSPEC unsigned long hwloc_topology_get_flags (hwloc_topology_t topology);
01885
01893 HWLOC_DECLSPEC int hwloc_topology_is_thissystem(hwloc_topology_t __hwloc_restrict topology) __hwloc_attribute_pure;
01894
01896 struct hwloc_topology_discovery_support {
01898 unsigned char pu;
01900 unsigned char numa;
01902 unsigned char numa_memory;
01903 };
01904
01910 struct hwloc_topology_cpubind_support {
01912 unsigned char set_thisproc_cpubind;
01914 unsigned char get_thisproc_cpubind;
01916 unsigned char set_proc_cpubind;
01918 unsigned char get_proc_cpubind;
01920 unsigned char set_thisthread_cpubind;
01922 unsigned char get_thisthread_cpubind;
01924 unsigned char set_thread_cpubind;
01926 unsigned char get_thread_cpubind;
01928 unsigned char get_thisproc_last_cpu_location;
01930 unsigned char get_proc_last_cpu_location;
01932 unsigned char get_thisthread_last_cpu_location;
01933 };
01934
01940 struct hwloc_topology_membind_support {
01942 unsigned char set_thisproc_membind;
01944 unsigned char get_thisproc_membind;
01946 unsigned char set_proc_membind;
01948 unsigned char get_proc_membind;
01950 unsigned char set_thisthread_membind;
01952 unsigned char get_thisthread_membind;
01954 unsigned char set_area_membind;
01956 unsigned char get_area_membind;
01958 unsigned char alloc_membind;
01960 unsigned char firsttouch_membind;
01962 unsigned char bind_membind;
01964 unsigned char interleave_membind;
01966 unsigned char nexttouch_membind;
01968 unsigned char migrate_membind;
01970 unsigned char get_area_memlocation;
01971 };
01972
01979 struct hwloc_topology_support {
01980 struct hwloc_topology_discovery_support *discovery;
01981 struct hwloc_topology_cpubind_support *cpubind;
01982 struct hwloc_topology_membind_support *membind;
01983 };
01984
01994 HWLOC_DECLSPEC const struct hwloc_topology_support *hwloc_topology_get_support(hwloc_topology_t __hwloc_restrict topology);
01995
02005 enum hwloc_type_filter_e {
02011 HWLOC_TYPE_FILTER_KEEP_ALL = 0,
02012
02019 HWLOC_TYPE_FILTER_KEEP_NONE = 1,
02020
02033 HWLOC_TYPE_FILTER_KEEP_STRUCTURE = 2,
02034
02048 HWLOC_TYPE_FILTER_KEEP_IMPORTANT = 3
02049 };
02050
02053 HWLOC_DECLSPEC int hwloc_topology_set_type_filter(hwloc_topology_t topology, hwloc_obj_type_t type, enum hwloc_type_filter_e filter);
02054
02057 HWLOC_DECLSPEC int hwloc_topology_get_type_filter(hwloc_topology_t topology, hwloc_obj_type_t type, enum hwloc_type_filter_e *filter);
02058
02063 HWLOC_DECLSPEC int hwloc_topology_set_all_types_filter(hwloc_topology_t topology, enum hwloc_type_filter_e filter);
02064
02067 HWLOC_DECLSPEC int hwloc_topology_set_cache_types_filter(hwloc_topology_t topology, enum hwloc_type_filter_e filter);
02068
02071 HWLOC_DECLSPEC int hwloc_topology_set_icache_types_filter(hwloc_topology_t topology, enum hwloc_type_filter_e filter);
02072
02075 HWLOC_DECLSPEC int hwloc_topology_set_io_types_filter(hwloc_topology_t topology, enum hwloc_type_filter_e filter);
02076
02087 HWLOC_DECLSPEC void hwloc_topology_set_userdata(hwloc_topology_t topology, const void *userdata);
02088
02094 HWLOC_DECLSPEC void * hwloc_topology_get_userdata(hwloc_topology_t topology);
02095
02105 enum hwloc_restrict_flags_e {
02110 HWLOC_RESTRICT_FLAG_REMOVE_CPULESS = (1UL<<0),
02111
02116 HWLOC_RESTRICT_FLAG_ADAPT_MISC = (1UL<<1),
02117
02122 HWLOC_RESTRICT_FLAG_ADAPT_IO = (1UL<<2)
02123 };
02124
02146 HWLOC_DECLSPEC int hwloc_topology_restrict(hwloc_topology_t __hwloc_restrict topology, hwloc_const_cpuset_t cpuset, unsigned long flags);
02147
02169 HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_insert_misc_object(hwloc_topology_t topology, hwloc_obj_t parent, const char *name);
02170
02191 HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_alloc_group_object(hwloc_topology_t topology);
02192
02226 HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_insert_group_object(hwloc_topology_t topology, hwloc_obj_t group);
02227
02237 HWLOC_DECLSPEC int hwloc_obj_add_other_obj_sets(hwloc_obj_t dst, hwloc_obj_t src);
02238
02243 #ifdef __cplusplus
02244 }
02245 #endif
02246
02247
02248
02249 #include <hwloc/helper.h>
02250
02251
02252 #include <hwloc/inlines.h>
02253
02254
02255 #include <hwloc/export.h>
02256
02257
02258 #include <hwloc/distances.h>
02259
02260
02261 #include <hwloc/diff.h>
02262
02263
02264 #include <hwloc/deprecated.h>
02265
02266 #endif