Hardware Locality (hwloc)
v2.0-20191027.0400.gite37e7d8
|
00001 /* 00002 * Copyright © 2010-2019 Inria. All rights reserved. 00003 * See COPYING in top-level directory. 00004 */ 00005 00010 #ifndef HWLOC_DISTANCES_H 00011 #define HWLOC_DISTANCES_H 00012 00013 #ifndef HWLOC_H 00014 #error Please include the main hwloc.h instead 00015 #endif 00016 00017 00018 #ifdef __cplusplus 00019 extern "C" { 00020 #elif 0 00021 } 00022 #endif 00023 00024 00041 struct hwloc_distances_s { 00042 unsigned nbobjs; 00043 hwloc_obj_t *objs; 00048 unsigned long kind; 00049 hwloc_uint64_t *values; 00054 }; 00055 00067 enum hwloc_distances_kind_e { 00071 HWLOC_DISTANCES_KIND_FROM_OS = (1UL<<0), 00075 HWLOC_DISTANCES_KIND_FROM_USER = (1UL<<1), 00076 00083 HWLOC_DISTANCES_KIND_MEANS_LATENCY = (1UL<<2), 00090 HWLOC_DISTANCES_KIND_MEANS_BANDWIDTH = (1UL<<3) 00091 }; 00092 00116 HWLOC_DECLSPEC int 00117 hwloc_distances_get(hwloc_topology_t topology, 00118 unsigned *nr, struct hwloc_distances_s **distances, 00119 unsigned long kind, unsigned long flags); 00120 00125 HWLOC_DECLSPEC int 00126 hwloc_distances_get_by_depth(hwloc_topology_t topology, int depth, 00127 unsigned *nr, struct hwloc_distances_s **distances, 00128 unsigned long kind, unsigned long flags); 00129 00134 static __hwloc_inline int 00135 hwloc_distances_get_by_type(hwloc_topology_t topology, hwloc_obj_type_t type, 00136 unsigned *nr, struct hwloc_distances_s **distances, 00137 unsigned long kind, unsigned long flags) 00138 { 00139 int depth = hwloc_get_type_depth(topology, type); 00140 if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE) { 00141 *nr = 0; 00142 return 0; 00143 } 00144 return hwloc_distances_get_by_depth(topology, depth, nr, distances, kind, flags); 00145 } 00146 00148 HWLOC_DECLSPEC void 00149 hwloc_distances_release(hwloc_topology_t topology, struct hwloc_distances_s *distances); 00150 00163 static __hwloc_inline int 00164 hwloc_distances_obj_index(struct hwloc_distances_s *distances, hwloc_obj_t obj) 00165 { 00166 unsigned i; 00167 for(i=0; i<distances->nbobjs; i++) 00168 if (distances->objs[i] == obj) 00169 return (int)i; 00170 return -1; 00171 } 00172 00180 static __hwloc_inline int 00181 hwloc_distances_obj_pair_values(struct hwloc_distances_s *distances, 00182 hwloc_obj_t obj1, hwloc_obj_t obj2, 00183 hwloc_uint64_t *value1to2, hwloc_uint64_t *value2to1) 00184 { 00185 int i1 = hwloc_distances_obj_index(distances, obj1); 00186 int i2 = hwloc_distances_obj_index(distances, obj2); 00187 if (i1 < 0 || i2 < 0) 00188 return -1; 00189 *value1to2 = distances->values[i1 * distances->nbobjs + i2]; 00190 *value2to1 = distances->values[i2 * distances->nbobjs + i1]; 00191 return 0; 00192 } 00193 00203 enum hwloc_distances_add_flag_e { 00207 HWLOC_DISTANCES_ADD_FLAG_GROUP = (1UL<<0), 00213 HWLOC_DISTANCES_ADD_FLAG_GROUP_INACCURATE = (1UL<<1) 00214 }; 00215 00230 HWLOC_DECLSPEC int hwloc_distances_add(hwloc_topology_t topology, 00231 unsigned nbobjs, hwloc_obj_t *objs, hwloc_uint64_t *values, 00232 unsigned long kind, unsigned long flags); 00233 00242 HWLOC_DECLSPEC int hwloc_distances_remove(hwloc_topology_t topology); 00243 00248 HWLOC_DECLSPEC int hwloc_distances_remove_by_depth(hwloc_topology_t topology, int depth); 00249 00254 static __hwloc_inline int 00255 hwloc_distances_remove_by_type(hwloc_topology_t topology, hwloc_obj_type_t type) 00256 { 00257 int depth = hwloc_get_type_depth(topology, type); 00258 if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE) 00259 return 0; 00260 return hwloc_distances_remove_by_depth(topology, depth); 00261 } 00262 00266 #ifdef __cplusplus 00267 } /* extern "C" */ 00268 #endif 00269 00270 00271 #endif /* HWLOC_DISTANCES_H */