Skip to content

Commit b95d0df

Browse files
committed
distances: add HOPS kind of values
Better than LATENCY (or BANDWIDTH) for XGMIHops. Convert between HOPS and LATENCY when importing/exporting from/to xml v2 Signed-off-by: Brice Goglin <[email protected]>
1 parent 0490968 commit b95d0df

File tree

9 files changed

+53
-18
lines changed

9 files changed

+53
-18
lines changed

NEWS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ Version 3.0.0
5151
See "Custom string infos" in the documentation for details.
5252
- hwloc_cpukinds_get_info() and hwloc_cpukinds_register() now manipulate
5353
infos as such a structure.
54-
+ Distances structure "MEANS" kinds are renamed to "VALUE".
54+
+ Distances structure "MEANS" kinds are renamed to "VALUE", and the new
55+
"HOPS" kind is used for the XGMIHops matrix instead of "LATENCY.
5556
* Tools
5657
+ lstopo has a new --osf option to tune the displaying of object
5758
attributes and units.

doc/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ man3_distances_DATA = \
649649
$(DOX_MAN_DIR)/man3/HWLOC_DISTANCES_KIND_FROM_USER.3 \
650650
$(DOX_MAN_DIR)/man3/HWLOC_DISTANCES_KIND_VALUE_LATENCY.3 \
651651
$(DOX_MAN_DIR)/man3/HWLOC_DISTANCES_KIND_VALUE_BANDWIDTH.3 \
652+
$(DOX_MAN_DIR)/man3/HWLOC_DISTANCES_KIND_VALUE_HOPS.3 \
652653
$(DOX_MAN_DIR)/man3/hwloc_distances_get.3 \
653654
$(DOX_MAN_DIR)/man3/hwloc_distances_get_by_depth.3 \
654655
$(DOX_MAN_DIR)/man3/hwloc_distances_get_by_type.3 \

doc/hwloc.doxy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4783,6 +4783,10 @@ of in each object.
47834783

47844784
HWLOC_DISTANCES_KIND_MEANS_LATENCY and HWLOC_DISTANCES_KIND_MEANS_BANDWIDTH
47854785
are renamed to ::HWLOC_DISTANCES_KIND_VALUE_LATENCY and ::HWLOC_DISTANCES_KIND_VALUE_BANDWIDTH.
4786+
<br/>
4787+
4788+
The XGMIHops distance matrix is now of the new kind
4789+
::HWLOC_DISTANCES_KIND_VALUE_HOPS instead of latency.
47864790

47874791

47884792
\section upgrade_to_api_3x_xml XML changes

hwloc/distances.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ int hwloc_internal_distances_add(hwloc_topology_t topology, const char *name,
607607
*/
608608

609609
#define HWLOC_DISTANCES_KIND_FROM_ALL (HWLOC_DISTANCES_KIND_FROM_OS|HWLOC_DISTANCES_KIND_FROM_USER)
610-
#define HWLOC_DISTANCES_KIND_VALUE_ALL (HWLOC_DISTANCES_KIND_VALUE_LATENCY|HWLOC_DISTANCES_KIND_VALUE_BANDWIDTH)
610+
#define HWLOC_DISTANCES_KIND_VALUE_ALL (HWLOC_DISTANCES_KIND_VALUE_LATENCY|HWLOC_DISTANCES_KIND_VALUE_BANDWIDTH|HWLOC_DISTANCES_KIND_VALUE_HOPS)
611611
#define HWLOC_DISTANCES_KIND_ALL (HWLOC_DISTANCES_KIND_FROM_ALL|HWLOC_DISTANCES_KIND_VALUE_ALL|HWLOC_DISTANCES_KIND_HETEROGENEOUS_TYPES)
612612
#define HWLOC_DISTANCES_ADD_FLAG_ALL (HWLOC_DISTANCES_ADD_FLAG_GROUP|HWLOC_DISTANCES_ADD_FLAG_GROUP_INACCURATE)
613613

hwloc/topology-rsmi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ hwloc__rsmi_add_xgmi_hops(hwloc_topology_t topology,
5555
int err;
5656

5757
handle = hwloc_backend_distances_add_create(topology, "XGMIHops",
58-
HWLOC_DISTANCES_KIND_FROM_OS|HWLOC_DISTANCES_KIND_VALUE_LATENCY,
58+
HWLOC_DISTANCES_KIND_FROM_OS|HWLOC_DISTANCES_KIND_VALUE_HOPS,
5959
0);
6060
if (!handle)
6161
goto out;

hwloc/topology-xml.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,7 @@ hwloc__xml_import_support(hwloc_topology_t topology,
11041104

11051105
static int
11061106
hwloc__xml_import_distances(hwloc_topology_t topology,
1107+
struct hwloc_xml_backend_data_s *data,
11071108
hwloc__xml_import_state_t state,
11081109
int heterotypes)
11091110
{
@@ -1347,6 +1348,12 @@ hwloc__xml_import_distances(hwloc_topology_t topology,
13471348
if (topology->flags & HWLOC_TOPOLOGY_FLAG_NO_DISTANCES)
13481349
goto out_ignore;
13491350

1351+
if (data->version_major < 3) {
1352+
/* XGMIHops was latency in v2 */
1353+
if ((kind & HWLOC_DISTANCES_KIND_VALUE_LATENCY) && !strcmp(name, "XGMIHops"))
1354+
kind = (kind & ~HWLOC_DISTANCES_KIND_VALUE_LATENCY) | HWLOC_DISTANCES_KIND_VALUE_HOPS;
1355+
}
1356+
13501357
hwloc_internal_distances_add_by_index(topology, name, unique_type, different_types, nbobjs, indexes, u64values, kind, 0 /* assume grouping was applied when this matrix was discovered before exporting to XML */);
13511358

13521359
/* prevent freeing below */
@@ -1859,11 +1866,11 @@ hwloc_look_xml(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus)
18591866
if (!ret)
18601867
break;
18611868
if (!strcmp(tag, "distances2")) {
1862-
ret = hwloc__xml_import_distances(topology, &childstate, 0);
1869+
ret = hwloc__xml_import_distances(topology, data, &childstate, 0);
18631870
if (ret < 0)
18641871
goto failed;
18651872
} else if (!strcmp(tag, "distances2hetero")) {
1866-
ret = hwloc__xml_import_distances(topology, &childstate, 1);
1873+
ret = hwloc__xml_import_distances(topology, data, &childstate, 1);
18671874
if (ret < 0)
18681875
goto failed;
18691876
} else if (!strcmp(tag, "support")) {
@@ -2413,11 +2420,12 @@ hwloc__xml_v2export_object (hwloc__xml_export_state_t parentstate, hwloc_topolog
24132420
} while (0)
24142421

24152422
static void
2416-
hwloc___xml_v2export_distances(hwloc__xml_export_state_t parentstate, struct hwloc_internal_distances_s *dist)
2423+
hwloc___xml_v2export_distances(hwloc__xml_export_state_t parentstate, struct hwloc_internal_distances_s *dist, unsigned long flags)
24172424
{
24182425
char tmp[255];
24192426
unsigned nbobjs = dist->nbobjs;
24202427
struct hwloc__xml_export_state_s state;
2428+
unsigned long kind = dist->kind;
24212429

24222430
if (dist->different_types) {
24232431
parentstate->new_child(parentstate, &state, "distances2hetero");
@@ -2428,7 +2436,12 @@ hwloc___xml_v2export_distances(hwloc__xml_export_state_t parentstate, struct hwl
24282436

24292437
sprintf(tmp, "%u", nbobjs);
24302438
state.new_prop(&state, "nbobjs", tmp);
2431-
sprintf(tmp, "%lu", dist->kind);
2439+
if (flags & HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V2) {
2440+
/* HOPS was LATENCY in v2 */
2441+
if (kind & HWLOC_DISTANCES_KIND_VALUE_HOPS)
2442+
kind = (kind & ~HWLOC_DISTANCES_KIND_VALUE_HOPS) | HWLOC_DISTANCES_KIND_VALUE_LATENCY;
2443+
}
2444+
sprintf(tmp, "%lu", kind);
24322445
state.new_prop(&state, "kind", tmp);
24332446
if (dist->name)
24342447
state.new_prop(&state, "name", dist->name);
@@ -2449,16 +2462,16 @@ hwloc___xml_v2export_distances(hwloc__xml_export_state_t parentstate, struct hwl
24492462
}
24502463

24512464
static void
2452-
hwloc__xml_v2export_distances(hwloc__xml_export_state_t parentstate, hwloc_topology_t topology)
2465+
hwloc__xml_v2export_distances(hwloc__xml_export_state_t parentstate, hwloc_topology_t topology, unsigned long flags)
24532466
{
24542467
struct hwloc_internal_distances_s *dist;
24552468
for(dist = topology->first_dist; dist; dist = dist->next)
24562469
if (!dist->different_types)
2457-
hwloc___xml_v2export_distances(parentstate, dist);
2470+
hwloc___xml_v2export_distances(parentstate, dist, flags);
24582471
/* export homogeneous distances first in case the importer doesn't support heterogeneous and stops there */
24592472
for(dist = topology->first_dist; dist; dist = dist->next)
24602473
if (dist->different_types)
2461-
hwloc___xml_v2export_distances(parentstate, dist);
2474+
hwloc___xml_v2export_distances(parentstate, dist, flags);
24622475
}
24632476

24642477
static void
@@ -2659,7 +2672,7 @@ hwloc__xml_export_topology(hwloc__xml_export_state_t state, hwloc_topology_t top
26592672
hwloc_obj_t root = hwloc_get_root_obj(topology);
26602673

26612674
hwloc__xml_v2export_object (state, topology, root, flags);
2662-
hwloc__xml_v2export_distances (state, topology);
2675+
hwloc__xml_v2export_distances (state, topology, flags);
26632676
env = getenv("HWLOC_XML_EXPORT_SUPPORT");
26642677
if (!env || atoi(env))
26652678
hwloc__xml_v2export_support(state, topology);

include/hwloc/distances.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ extern "C" {
3636
* The corresponding kind is ::HWLOC_DISTANCES_KIND_MEANS_LATENCY | ::HWLOC_DISTANCES_KIND_FROM_USER.
3737
* The name of this distances structure is "NUMALatency".
3838
*
39-
* The matrix may also contain bandwidths between random sets of objects,
40-
* possibly provided by the user, as specified in the \p kind attribute.
39+
* The matrix may also contain bandwidths or number of hops between
40+
* random sets of objects, possibly provided by the user, as specified
41+
* in the \p kind attribute.
4142
* Others common distance structures include and "XGMIBandwidth", "XGMIHops",
4243
* "XeLinkBandwidth" and "NVLinkBandwidth".
4344
*
@@ -73,7 +74,8 @@ struct hwloc_distances_s {
7374
* Each distance matrix may have only one kind among HWLOC_DISTANCES_KIND_FROM_*
7475
* specifying where distance information comes from,
7576
* and one kind among HWLOC_DISTANCES_KIND_VALUE_* specifying
76-
* whether values are latencies or bandwidths.
77+
* and exactly one kind HWLOC_DISTANCES_KIND_VALUE_* specifying
78+
* whether values are latencies or bandwidths, etc.
7779
*/
7880
enum hwloc_distances_kind_e {
7981
/** \brief These distances were obtained from the operating system or hardware.
@@ -88,7 +90,6 @@ enum hwloc_distances_kind_e {
8890
/** \brief Distance values are similar to latencies between objects.
8991
* Values are smaller for closer objects, hence minimal on the diagonal
9092
* of the matrix (distance between an object and itself).
91-
* It could also be the number of network hops between objects, etc.
9293
* \hideinitializer
9394
*/
9495
HWLOC_DISTANCES_KIND_VALUE_LATENCY = (1UL<<2),
@@ -99,6 +100,12 @@ enum hwloc_distances_kind_e {
99100
* \hideinitializer
100101
*/
101102
HWLOC_DISTANCES_KIND_VALUE_BANDWIDTH = (1UL<<3),
103+
/** \brief Distance values are numbers of hops between objects.
104+
* Values are smaller for closer objects, zero on the diagonal
105+
* of the matrix (no hop between an object and itself).
106+
* \hideinitializer
107+
*/
108+
HWLOC_DISTANCES_KIND_VALUE_HOPS = (1UL<<5),
102109

103110
/** \brief This distances structure covers objects of different types.
104111
* This may apply to the "NVLinkBandwidth" structure in presence
@@ -117,8 +124,8 @@ enum hwloc_distances_kind_e {
117124
* \p kind serves as a filter. If \c 0, all distance matrices are returned.
118125
* If it contains some HWLOC_DISTANCES_KIND_FROM_*, only distance matrices
119126
* whose kind matches one of these are returned.
120-
* If it contains HWLOC_DISTANCES_KIND_VALUE_BANDWIDTH or LATENCY, only distance
121-
* matrices whose kind matches these are returned.
127+
* If it contains some HWLOC_DISTANCES_KIND_VALUE_*, only distance matrices
128+
* whose kind matches one of these are returned.
122129
*
123130
* On input, \p nr points to the number of distance matrices that may be stored
124131
* in \p distances.

include/hwloc/rename.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ extern "C" {
474474
#define HWLOC_DISTANCES_KIND_FROM_USER HWLOC_NAME_CAPS(DISTANCES_KIND_FROM_USER)
475475
#define HWLOC_DISTANCES_KIND_VALUE_LATENCY HWLOC_NAME_CAPS(DISTANCES_KIND_VALUE_LATENCY)
476476
#define HWLOC_DISTANCES_KIND_VALUE_BANDWIDTH HWLOC_NAME_CAPS(DISTANCES_KIND_VALUE_BANDWIDTH)
477+
#define HWLOC_DISTANCES_KIND_VALUE_HOPS HWLOC_NAME_CAPS(DISTANCES_KIND_VALUE_HOPS)
477478
#define HWLOC_DISTANCES_KIND_HETEROGENEOUS_TYPES HWLOC_NAME_CAPS(DISTANCES_KIND_HETEROGENEOUS_TYPES)
478479

479480
#define hwloc_distances_get HWLOC_NAME(distances_get)

utils/lstopo/lstopo-text.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,16 @@ static void output_distances(struct lstopo_output *loutput)
233233
err = hwloc_distances_get(topology, &nr, dist, 0, 0);
234234
if (!err) {
235235
for(j=0; j<nr; j++) {
236-
const char *kindmeans = (dist[j]->kind & HWLOC_DISTANCES_KIND_VALUE_LATENCY) ? "latency" : (dist[j]->kind & HWLOC_DISTANCES_KIND_VALUE_BANDWIDTH) ? "bandwidth" : "distance";
236+
const char *kindmeans;
237237
const char *name = hwloc_distances_get_name(topology, dist[j]);
238+
if (dist[j]->kind & HWLOC_DISTANCES_KIND_VALUE_LATENCY)
239+
kindmeans = "latency";
240+
else if (dist[j]->kind & HWLOC_DISTANCES_KIND_VALUE_BANDWIDTH)
241+
kindmeans = "bandwidth";
242+
else if (dist[j]->kind & HWLOC_DISTANCES_KIND_VALUE_HOPS)
243+
kindmeans = "hops";
244+
else
245+
kindmeans = "distance";
238246
if (!name)
239247
name = "(null)";
240248
if (loutput->transform_distances != -1)

0 commit comments

Comments
 (0)