File indexing completed on 2026-07-30 09:10:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef HWLOC_INLINES_H
0015 #define HWLOC_INLINES_H
0016
0017 #ifndef HWLOC_H
0018 #error Please include the main hwloc.h instead
0019 #endif
0020
0021 #include <stdlib.h>
0022 #include <errno.h>
0023
0024
0025 #ifdef __cplusplus
0026 extern "C" {
0027 #endif
0028
0029 static __hwloc_inline int
0030 hwloc_get_type_or_below_depth (hwloc_topology_t topology, hwloc_obj_type_t type)
0031 {
0032 int depth = hwloc_get_type_depth(topology, type);
0033
0034 if (depth != HWLOC_TYPE_DEPTH_UNKNOWN)
0035 return depth;
0036
0037
0038 for(depth = hwloc_get_type_depth(topology, HWLOC_OBJ_PU); ; depth--)
0039 if (hwloc_compare_types(hwloc_get_depth_type(topology, depth), type) < 0)
0040 return depth+1;
0041
0042
0043
0044 }
0045
0046 static __hwloc_inline int
0047 hwloc_get_type_or_above_depth (hwloc_topology_t topology, hwloc_obj_type_t type)
0048 {
0049 int depth = hwloc_get_type_depth(topology, type);
0050
0051 if (depth != HWLOC_TYPE_DEPTH_UNKNOWN)
0052 return depth;
0053
0054
0055 for(depth = 0; ; depth++)
0056 if (hwloc_compare_types(hwloc_get_depth_type(topology, depth), type) > 0)
0057 return depth-1;
0058
0059
0060
0061 }
0062
0063 static __hwloc_inline int
0064 hwloc_get_nbobjs_by_type (hwloc_topology_t topology, hwloc_obj_type_t type)
0065 {
0066 int depth = hwloc_get_type_depth(topology, type);
0067 if (depth == HWLOC_TYPE_DEPTH_UNKNOWN)
0068 return 0;
0069 if (depth == HWLOC_TYPE_DEPTH_MULTIPLE)
0070 return -1;
0071 return (int) hwloc_get_nbobjs_by_depth(topology, depth);
0072 }
0073
0074 static __hwloc_inline hwloc_obj_t
0075 hwloc_get_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type, unsigned idx)
0076 {
0077 int depth = hwloc_get_type_depth(topology, type);
0078 if (depth == HWLOC_TYPE_DEPTH_UNKNOWN)
0079 return NULL;
0080 if (depth == HWLOC_TYPE_DEPTH_MULTIPLE)
0081 return NULL;
0082 return hwloc_get_obj_by_depth(topology, depth, idx);
0083 }
0084
0085 static __hwloc_inline hwloc_obj_t
0086 hwloc_get_next_obj_by_depth (hwloc_topology_t topology, int depth, hwloc_obj_t prev)
0087 {
0088 if (!prev)
0089 return hwloc_get_obj_by_depth (topology, depth, 0);
0090 if (prev->depth != depth)
0091 return NULL;
0092 return prev->next_cousin;
0093 }
0094
0095 static __hwloc_inline hwloc_obj_t
0096 hwloc_get_next_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type,
0097 hwloc_obj_t prev)
0098 {
0099 int depth = hwloc_get_type_depth(topology, type);
0100 if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
0101 return NULL;
0102 return hwloc_get_next_obj_by_depth (topology, depth, prev);
0103 }
0104
0105 static __hwloc_inline hwloc_obj_t
0106 hwloc_get_root_obj (hwloc_topology_t topology)
0107 {
0108 return hwloc_get_obj_by_depth (topology, 0, 0);
0109 }
0110
0111 static __hwloc_inline const char *
0112 hwloc_obj_get_info_by_name(hwloc_obj_t obj, const char *name)
0113 {
0114 unsigned i;
0115 for(i=0; i<obj->infos_count; i++) {
0116 struct hwloc_info_s *info = &obj->infos[i];
0117 if (!strcmp(info->name, name))
0118 return info->value;
0119 }
0120 return NULL;
0121 }
0122
0123 static __hwloc_inline void *
0124 hwloc_alloc_membind_policy(hwloc_topology_t topology, size_t len, hwloc_const_cpuset_t set, hwloc_membind_policy_t policy, int flags)
0125 {
0126 void *p = hwloc_alloc_membind(topology, len, set, policy, flags);
0127 if (p)
0128 return p;
0129
0130 if (hwloc_set_membind(topology, set, policy, flags) < 0)
0131
0132 return NULL;
0133
0134 p = hwloc_alloc(topology, len);
0135 if (p && policy != HWLOC_MEMBIND_FIRSTTOUCH)
0136
0137 memset(p, 0, len);
0138 return p;
0139 }
0140
0141
0142 #ifdef __cplusplus
0143 }
0144 #endif
0145
0146
0147 #endif