Hardware Locality (hwloc) 2.4.1

distances.h
1 /*
2 * Copyright © 2010-2020 Inria. All rights reserved.
3 * See COPYING in top-level directory.
4 */
5
10 #ifndef HWLOC_DISTANCES_H
11 #define HWLOC_DISTANCES_H
12
13 #ifndef HWLOC_H
14 #error Please include the main hwloc.h instead
15 #endif
16
17
18 #ifdef __cplusplus
19 extern "C" {
20 #elif 0
21 }
22 #endif
23
24
42 struct hwloc_distances_s {
43 unsigned nbobjs;
44 hwloc_obj_t *objs;
49 unsigned long kind;
50 hwloc_uint64_t *values;
55 };
56
68 enum hwloc_distances_kind_e {
72 HWLOC_DISTANCES_KIND_FROM_OS = (1UL<<0),
76 HWLOC_DISTANCES_KIND_FROM_USER = (1UL<<1),
77
84 HWLOC_DISTANCES_KIND_MEANS_LATENCY = (1UL<<2),
91 HWLOC_DISTANCES_KIND_MEANS_BANDWIDTH = (1UL<<3),
92
96 HWLOC_DISTANCES_KIND_HETEROGENEOUS_TYPES = (1UL<<4)
97 };
98
122 HWLOC_DECLSPEC int
123 hwloc_distances_get(hwloc_topology_t topology,
124 unsigned *nr, struct hwloc_distances_s **distances,
125 unsigned long kind, unsigned long flags);
126
131 HWLOC_DECLSPEC int
132 hwloc_distances_get_by_depth(hwloc_topology_t topology, int depth,
133 unsigned *nr, struct hwloc_distances_s **distances,
134 unsigned long kind, unsigned long flags);
135
140 HWLOC_DECLSPEC int
141 hwloc_distances_get_by_type(hwloc_topology_t topology, hwloc_obj_type_t type,
142 unsigned *nr, struct hwloc_distances_s **distances,
143 unsigned long kind, unsigned long flags);
144
151 HWLOC_DECLSPEC int
152 hwloc_distances_get_by_name(hwloc_topology_t topology, const char *name,
153 unsigned *nr, struct hwloc_distances_s **distances,
154 unsigned long flags);
155
161 HWLOC_DECLSPEC const char *
162 hwloc_distances_get_name(hwloc_topology_t topology, struct hwloc_distances_s *distances);
163
168 HWLOC_DECLSPEC void
169 hwloc_distances_release(hwloc_topology_t topology, struct hwloc_distances_s *distances);
170
183 static __hwloc_inline int
184 hwloc_distances_obj_index(struct hwloc_distances_s *distances, hwloc_obj_t obj)
185 {
186 unsigned i;
187 for(i=0; i<distances->nbobjs; i++)
188 if (distances->objs[i] == obj)
189 return (int)i;
190 return -1;
191 }
192
200 static __hwloc_inline int
201 hwloc_distances_obj_pair_values(struct hwloc_distances_s *distances,
202 hwloc_obj_t obj1, hwloc_obj_t obj2,
203 hwloc_uint64_t *value1to2, hwloc_uint64_t *value2to1)
204 {
205 int i1 = hwloc_distances_obj_index(distances, obj1);
206 int i2 = hwloc_distances_obj_index(distances, obj2);
207 if (i1 < 0 || i2 < 0)
208 return -1;
209 *value1to2 = distances->values[i1 * distances->nbobjs + i2];
210 *value2to1 = distances->values[i2 * distances->nbobjs + i1];
211 return 0;
212 }
213
223 enum hwloc_distances_add_flag_e {
227 HWLOC_DISTANCES_ADD_FLAG_GROUP = (1UL<<0),
233 HWLOC_DISTANCES_ADD_FLAG_GROUP_INACCURATE = (1UL<<1)
234 };
235
250 HWLOC_DECLSPEC int hwloc_distances_add(hwloc_topology_t topology,
251 unsigned nbobjs, hwloc_obj_t *objs, hwloc_uint64_t *values,
252 unsigned long kind, unsigned long flags);
253
262 HWLOC_DECLSPEC int hwloc_distances_remove(hwloc_topology_t topology);
263
268 HWLOC_DECLSPEC int hwloc_distances_remove_by_depth(hwloc_topology_t topology, int depth);
269
274 static __hwloc_inline int
275 hwloc_distances_remove_by_type(hwloc_topology_t topology, hwloc_obj_type_t type)
276 {
277 int depth = hwloc_get_type_depth(topology, type);
278 if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
279 return 0;
280 return hwloc_distances_remove_by_depth(topology, depth);
281 }
282
287 HWLOC_DECLSPEC int hwloc_distances_release_remove(hwloc_topology_t topology, struct hwloc_distances_s *distances);
288
292 #ifdef __cplusplus
293 } /* extern "C" */
294 #endif
295
296
297 #endif /* HWLOC_DISTANCES_H */
hwloc_obj_type_t
hwloc_obj_type_t
Type of topology object.
Definition: hwloc.h:176
hwloc_topology_t
struct hwloc_topology * hwloc_topology_t
Topology context.
Definition: hwloc.h:691
hwloc_get_type_depth
int hwloc_get_type_depth(hwloc_topology_t topology, hwloc_obj_type_t type)
Returns the depth of objects of type type.
HWLOC_TYPE_DEPTH_UNKNOWN
@ HWLOC_TYPE_DEPTH_UNKNOWN
No object of given type exists in the topology.
Definition: hwloc.h:821
HWLOC_TYPE_DEPTH_MULTIPLE
@ HWLOC_TYPE_DEPTH_MULTIPLE
Objects of given type exist at different depth in the topology (only for Groups).
Definition: hwloc.h:822
hwloc_distances_release
void hwloc_distances_release(hwloc_topology_t topology, struct hwloc_distances_s *distances)
Release a distance matrix structure previously returned by hwloc_distances_get().
hwloc_distances_get_by_depth
int hwloc_distances_get_by_depth(hwloc_topology_t topology, int depth, unsigned *nr, struct hwloc_distances_s **distances, unsigned long kind, unsigned long flags)
Retrieve distance matrices for object at a specific depth in the topology.
hwloc_distances_get
int hwloc_distances_get(hwloc_topology_t topology, unsigned *nr, struct hwloc_distances_s **distances, unsigned long kind, unsigned long flags)
Retrieve distance matrices.
hwloc_distances_get_by_name
int hwloc_distances_get_by_name(hwloc_topology_t topology, const char *name, unsigned *nr, struct hwloc_distances_s **distances, unsigned long flags)
Retrieve a distance matrix with the given name.
hwloc_distances_get_name
const char * hwloc_distances_get_name(hwloc_topology_t topology, struct hwloc_distances_s *distances)
Get a description of what a distances structure contains.
hwloc_distances_get_by_type
int hwloc_distances_get_by_type(hwloc_topology_t topology, hwloc_obj_type_t type, unsigned *nr, struct hwloc_distances_s **distances, unsigned long kind, unsigned long flags)
Retrieve distance matrices for object of a specific type.
hwloc_distances_kind_e
hwloc_distances_kind_e
Kinds of distance matrices.
Definition: distances.h:68
HWLOC_DISTANCES_KIND_FROM_USER
@ HWLOC_DISTANCES_KIND_FROM_USER
These distances were provided by the user.
Definition: distances.h:76
HWLOC_DISTANCES_KIND_MEANS_BANDWIDTH
@ HWLOC_DISTANCES_KIND_MEANS_BANDWIDTH
Distance values are similar to bandwidths between objects. Values are higher for closer objects,...
Definition: distances.h:91
HWLOC_DISTANCES_KIND_FROM_OS
@ HWLOC_DISTANCES_KIND_FROM_OS
These distances were obtained from the operating system or hardware.
Definition: distances.h:72
HWLOC_DISTANCES_KIND_HETEROGENEOUS_TYPES
@ HWLOC_DISTANCES_KIND_HETEROGENEOUS_TYPES
This distances structure covers objects of different types.
Definition: distances.h:96
HWLOC_DISTANCES_KIND_MEANS_LATENCY
@ HWLOC_DISTANCES_KIND_MEANS_LATENCY
Distance values are similar to latencies between objects. Values are smaller for closer objects,...
Definition: distances.h:84
hwloc_distances_obj_pair_values
static int hwloc_distances_obj_pair_values(struct hwloc_distances_s *distances, hwloc_obj_t obj1, hwloc_obj_t obj2, hwloc_uint64_t *value1to2, hwloc_uint64_t *value2to1)
Find the values between two objects in a distance matrices.
Definition: distances.h:201
hwloc_distances_obj_index
static int hwloc_distances_obj_index(struct hwloc_distances_s *distances, hwloc_obj_t obj)
Find the index of an object in a distances structure.
Definition: distances.h:184
hwloc_distances_add_flag_e
hwloc_distances_add_flag_e
Flags for adding a new distances to a topology.
Definition: distances.h:223
hwloc_distances_release_remove
int hwloc_distances_release_remove(hwloc_topology_t topology, struct hwloc_distances_s *distances)
Release and remove the given distance matrice from the topology.
hwloc_distances_remove_by_type
static int hwloc_distances_remove_by_type(hwloc_topology_t topology, hwloc_obj_type_t type)
Remove distance matrices for objects of a specific type in the topology.
Definition: distances.h:275
hwloc_distances_remove_by_depth
int hwloc_distances_remove_by_depth(hwloc_topology_t topology, int depth)
Remove distance matrices for objects at a specific depth in the topology.
hwloc_distances_remove
int hwloc_distances_remove(hwloc_topology_t topology)
Remove all distance matrices from a topology.
hwloc_distances_add
int hwloc_distances_add(hwloc_topology_t topology, unsigned nbobjs, hwloc_obj_t *objs, hwloc_uint64_t *values, unsigned long kind, unsigned long flags)
Provide a new distance matrix.
HWLOC_DISTANCES_ADD_FLAG_GROUP_INACCURATE
@ HWLOC_DISTANCES_ADD_FLAG_GROUP_INACCURATE
If grouping, consider the distance values as inaccurate and relax the comparisons during the grouping...
Definition: distances.h:233
HWLOC_DISTANCES_ADD_FLAG_GROUP
@ HWLOC_DISTANCES_ADD_FLAG_GROUP
Try to group objects based on the newly provided distance information.
Definition: distances.h:227
hwloc_obj
Structure of a topology object.
Definition: hwloc.h:395
hwloc_distances_s
Matrix of distances between a set of objects.
Definition: distances.h:42
hwloc_distances_s::nbobjs
unsigned nbobjs
Number of objects described by the distance matrix.
Definition: distances.h:43
hwloc_distances_s::values
hwloc_uint64_t * values
Matrix of distances between objects, stored as a one-dimension array.
Definition: distances.h:50
hwloc_distances_s::kind
unsigned long kind
OR'ed set of hwloc_distances_kind_e.
Definition: distances.h:49
hwloc_distances_s::objs
hwloc_obj_t * objs
Array of objects described by the distance matrix. These objects are not in any particular order,...
Definition: distances.h:44