Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 104 additions & 90 deletions src/tools/info/sys_info.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2001-2015. ALL RIGHTS RESERVED.
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2001-2026. ALL RIGHTS RESERVED.
* Copyright (C) Shanghai Zhaoxin Semiconductor Co., Ltd. 2020. ALL RIGHTS RESERVED.
* Copyright (C) Tactical Computing Labs, LLC. 2022. ALL RIGHTS RESERVED.
* Copyright (C) Advanced Micro Devices, Inc. 2024. ALL RIGHTS RESERVED.
Expand All @@ -13,7 +13,7 @@

#include "ucx_info.h"

#include <ucs/sys/string.h>
#include <ucs/debug/table.h>
#include <ucs/sys/sys.h>
#include <ucs/sys/math.h>
#include <ucs/time/time.h>
Expand Down Expand Up @@ -61,131 +61,145 @@ static double measure_memcpy_bandwidth(size_t size)
return result;
}

static void print_repeat_char(int ch, int count)
/* Add an empty row used as vertical padding around content rows */
static void print_sys_topo_add_padding(ucs_table_t *table)
Comment thread
guy-ealey-morag marked this conversation as resolved.
{
int i;
ucs_table_row_h row = ucs_table_add_row(table);
unsigned i;

for (i = 0; i < count; ++i) {
putchar(ch);
for (i = 0; i < table->config.n_cols; ++i) {
ucs_table_row_add_cell_empty(table, row, 1);
}
}

static void print_row_separator(int column_width, int first_column_width,
int num_columns, int fill_char,
int separator_char)
/* Add a header row of the shape "<label> | dev0 | dev1 | ...", surrounded
* by empty padding rows and followed by a separator. */
static void print_sys_topo_add_devices_header(ucs_table_t *table,
const char *first_col_label,
unsigned num_devices)
{
int i;
ucs_table_row_h row;
ucs_sys_device_t sys_dev;

printf("# %c", separator_char);
print_repeat_char(fill_char, first_column_width);
for (i = 0; i < num_columns; ++i) {
putchar(separator_char);
print_repeat_char(fill_char, column_width);
}
printf("%c\n", separator_char);
}
print_sys_topo_add_padding(table);

static void print_table_header(const char *title, const char *distance_unit,
int column_width, int first_column_width,
int num_columns)
{
int column;

printf("#\n");
printf("# %s\n", title);
printf("#\n");
print_row_separator(column_width, first_column_width, num_columns, '-',
'+');
print_row_separator(column_width, first_column_width, num_columns, ' ',
'|');
printf("# |%*s ", first_column_width - 1, distance_unit);
for (column = 0; column < num_columns; ++column) {
printf("|%*s ", column_width - 1,
ucs_topo_sys_device_get_name((ucs_sys_device_t)column));
row = ucs_table_add_row(table);
ucs_table_row_add_cell_fmt(table, row, 1, UCS_TABLE_ALIGN_RIGHT, "%s",
first_col_label);
for (sys_dev = 0; sys_dev < num_devices; ++sys_dev) {
ucs_table_row_add_cell_fmt(table, row, 1, UCS_TABLE_ALIGN_RIGHT, "%s",
ucs_topo_sys_device_get_name(sys_dev));
}

printf("|\n");
print_row_separator(column_width, first_column_width, num_columns, ' ',
'|');
print_row_separator(column_width, first_column_width, num_columns, '-',
'+');
print_sys_topo_add_padding(table);
ucs_table_add_separator(table);
}

static void print_sys_topo()
static void print_sys_topo_distances(unsigned num_devices)
{
const unsigned num_devices = ucs_topo_num_devices();
static const int distance_width = 10;
static const char *system_topo_title = "System topology";
static const char *distance_unit = "MB/s";
static const char *memory_latency_title = "NUMA memory latency";
static const char *numa_distance_unit = "nsec";
ucs_table_config_t cfg = {
.n_cols = 1 + num_devices,
.row_prefix = "# ",
.equal_widths = 1,
};
ucs_sys_device_t sys_dev1, sys_dev2;
ucs_sys_dev_distance_t distance;
char distance_str[20];
ucs_status_t status;
int name_width;
ucs_table_row_h row;
ucs_table_t table;

/* Get maximal width of device name */
name_width = 2 + strlen(distance_unit);
for (sys_dev1 = 0; sys_dev1 < num_devices; ++sys_dev1) {
name_width = ucs_max(
name_width, 2 + strlen(ucs_topo_sys_device_get_name(sys_dev1)));
}
printf("#\n# System topology\n#\n");

ucs_table_init(&table, &cfg);

print_table_header(system_topo_title, distance_unit, distance_width,
name_width, num_devices);
print_sys_topo_add_devices_header(&table, "MB/s", num_devices);

/* Print table content */
for (sys_dev1 = 0; sys_dev1 < num_devices; ++sys_dev1) {
print_row_separator(distance_width, name_width, num_devices, ' ', '|');
if (sys_dev1 > 0) {
ucs_table_add_separator(&table);
}

print_sys_topo_add_padding(&table);

row = ucs_table_add_row(&table);
ucs_table_row_add_cell_fmt(&table, row, 1, UCS_TABLE_ALIGN_RIGHT, "%s",
ucs_topo_sys_device_get_name(sys_dev1));

printf("# |%*s ", name_width - 1,
ucs_topo_sys_device_get_name(sys_dev1));
for (sys_dev2 = 0; sys_dev2 < num_devices; ++sys_dev2) {
if (sys_dev1 == sys_dev2) {
/* Do not print distance of device to itself */
strncpy(distance_str, "-", sizeof(distance_str));
ucs_table_row_add_cell_fmt(&table, row, 1,
UCS_TABLE_ALIGN_CENTER, "%s", "-");
continue;
}

status = ucs_topo_get_distance(sys_dev1, sys_dev2, &distance);
if (status != UCS_OK) {
ucs_table_row_add_cell_fmt(&table, row, 1,
UCS_TABLE_ALIGN_RIGHT, "<%s>",
ucs_status_string(status));
} else if (distance.bandwidth > UCS_PBYTE) {
ucs_table_row_add_cell_fmt(&table, row, 1,
UCS_TABLE_ALIGN_RIGHT, "%s", "inf");
} else {
status = ucs_topo_get_distance(sys_dev1, sys_dev2, &distance);
if (status != UCS_OK) {
ucs_snprintf_safe(distance_str, sizeof(distance_str),
"<%s>", ucs_status_string(status));
} else if (distance.bandwidth > UCS_PBYTE) {
ucs_snprintf_safe(distance_str, sizeof(distance_str),
"inf");
} else {
ucs_snprintf_safe(distance_str, sizeof(distance_str),
"%.1f", distance.bandwidth / UCS_MBYTE);
}
ucs_table_row_add_cell_fmt(&table, row, 1,
UCS_TABLE_ALIGN_RIGHT, "%.1f",
distance.bandwidth / UCS_MBYTE);
}
printf("|%*s ", distance_width - 1, distance_str);
}
printf("|\n");

print_row_separator(distance_width, name_width, num_devices, ' ', '|');
print_row_separator(distance_width, name_width, num_devices, '-', '+');
print_sys_topo_add_padding(&table);
}

print_table_header(memory_latency_title, "device", distance_width,
name_width, num_devices);
print_row_separator(distance_width, name_width, num_devices, ' ', '|');
ucs_table_print(&table);
ucs_table_cleanup(&table);
}

printf("# |%*s ", name_width - 1, numa_distance_unit);
printf("|");
for (sys_dev1 = 0; sys_dev1 < num_devices; ++sys_dev1) {
ucs_topo_get_memory_distance(sys_dev1, &distance);
ucs_snprintf_safe(distance_str, sizeof(distance_str), "%.1f",
distance.latency * UCS_NSEC_PER_SEC);
printf("%*s |", distance_width - 1, distance_str);
static void print_sys_topo_memory_latency(unsigned num_devices)
{
ucs_table_config_t cfg = {
.n_cols = 1 + num_devices,
.row_prefix = "# ",
.equal_widths = 1,
};
ucs_sys_dev_distance_t distance;
ucs_sys_device_t sys_dev;
ucs_table_row_h row;
ucs_table_t table;

printf("#\n# NUMA memory latency\n#\n");

ucs_table_init(&table, &cfg);

print_sys_topo_add_devices_header(&table, "device", num_devices);

print_sys_topo_add_padding(&table);

row = ucs_table_add_row(&table);
ucs_table_row_add_cell_fmt(&table, row, 1, UCS_TABLE_ALIGN_RIGHT, "%s",
"nsec");
for (sys_dev = 0; sys_dev < num_devices; ++sys_dev) {
ucs_topo_get_memory_distance(sys_dev, &distance);
ucs_table_row_add_cell_fmt(&table, row, 1, UCS_TABLE_ALIGN_RIGHT,
"%.1f", distance.latency * UCS_NSEC_PER_SEC);
}

printf("\n");
print_row_separator(distance_width, name_width, num_devices, ' ', '|');
print_row_separator(distance_width, name_width, num_devices, '-', '+');
print_sys_topo_add_padding(&table);

ucs_table_print(&table);
ucs_table_cleanup(&table);

printf("# Memory latency is calculated according to the CPU affinity\n");
}
Comment thread
guy-ealey-morag marked this conversation as resolved.

static void print_sys_topo()
{
const unsigned num_devices = ucs_topo_num_devices();

print_sys_topo_distances(num_devices);
print_sys_topo_memory_latency(num_devices);
}

static double measure_timer_accuracy()
{
double elapsed, elapsed_accurate;
Expand Down
2 changes: 1 addition & 1 deletion src/ucp/proto/proto_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ void ucp_proto_request_select_error(ucp_request_t *req,
size_t msg_length)
{
UCS_STRING_BUFFER_ONSTACK(sel_param_strb, UCP_PROTO_SELECT_PARAM_STR_MAX);
UCS_STRING_BUFFER_ONSTACK(proto_select_strb, UCP_PROTO_CONFIG_STR_MAX);
UCS_STRING_BUFFER_ONSTACK(proto_select_strb, UCS_ALLOCA_MAX_SIZE);
Comment thread
guy-ealey-morag marked this conversation as resolved.
ucp_ep_h ep = req->send.ep;

ucp_proto_select_param_str(sel_param, ucp_operation_names, &sel_param_strb);
Expand Down
Loading
Loading