Skip to content

Commit

Permalink
Merge pull request #3217 from SteVwonder/hwloc-info-gpu
Browse files Browse the repository at this point in the history
hwloc: add printing of num GPUs to `flux hwloc info`
  • Loading branch information
mergify[bot] committed Sep 19, 2020
2 parents fde68d3 + fc1e089 commit afc3396
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/cmd/builtin/hwloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define XML_BASEDIR "resource.hwloc.xml"

extern char **environ;
static int hwloc_gpu_count (hwloc_topology_t topology);

/* idset helpers:
*/
Expand Down Expand Up @@ -323,7 +324,7 @@ static int cmd_info (optparse_t *p, int ac, char *av[])
char **xmlv = NULL;
char *xml = NULL;
uint32_t size = 0, i = 0;
int ncores = 0, npu = 0, nnodes = 0;
int ncores = 0, npu = 0, nnodes = 0, ngpus = 0;
hwloc_topology_t topo;

flux_hwloc_xml (p, &xmlv, &size);
Expand All @@ -336,11 +337,17 @@ static int cmd_info (optparse_t *p, int ac, char *av[])
ncores += hwloc_get_nbobjs_by_type (topo, HWLOC_OBJ_CORE);
npu += hwloc_get_nbobjs_by_type (topo, HWLOC_OBJ_PU);
nnodes += hwloc_get_nbobjs_by_type (topo, HWLOC_OBJ_MACHINE);
ngpus += hwloc_gpu_count (topo);
hwloc_topology_destroy (topo);
}

printf ("%d Machine%s, %d Cores, %d PUs\n",
printf ("%d Machine%s, %d Cores, %d PUs",
nnodes, nnodes > 1 ? "s" : "", ncores, npu);
if (ngpus > 0) {
printf (", %d GPU%s\n", ngpus, ngpus > 1 ? "s" : "");
} else {
printf ("\n");
}

string_array_destroy (xmlv, size);
return (0);
Expand Down
11 changes: 11 additions & 0 deletions t/t2005-hwloc-basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ test_expect_success HAVE_JQ 'hwloc: reload xml with GPU resources' '
$jq -e ".\"[0-1]\".cpuset == \"0-175\"" < sierra.out
'

# Keep this test after 'reload sierra' above so we're processing
# known topology xml with GPUs from reload.
#
test_expect_success 'hwloc: flux-hwloc info reports expected GPU resources' '
cat <<-EOF > hwloc-info.expected3 &&
2 Machines, 88 Cores, 352 PUs, 8 GPUs
EOF
flux hwloc info > hwloc-info.out3 &&
test_cmp hwloc-info.expected3 hwloc-info.out3
'

test_expect_success 'hwloc: return an error code on an invalid DIR' '
test_expect_code 1 flux hwloc reload nonexistence
'
Expand Down

0 comments on commit afc3396

Please sign in to comment.