Skip to content

Commit 2f5c521

Browse files
src: Implement Dave's feedback
1 parent 0b52547 commit 2f5c521

File tree

3 files changed

+50
-42
lines changed

3 files changed

+50
-42
lines changed

src/init.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ unsigned int shmem_internal_rand_seed;
100100

101101
#ifdef USE_HWLOC
102102
#include <hwloc.h>
103-
hwloc_topology_t shmem_topology;
103+
hwloc_topology_t shmem_internal_topology;
104104
#endif
105105

106106
#ifdef ENABLE_THREADS
@@ -384,17 +384,17 @@ shmem_internal_heap_postinit(void)
384384

385385
#ifdef HAVE_SCHED_GETAFFINITY
386386
#ifdef USE_HWLOC
387-
ret = hwloc_topology_init(&shmem_topology);
387+
ret = hwloc_topology_init(&shmem_internal_topology);
388388
if (ret < 0) {
389389
RETURN_ERROR_MSG("hwloc_topology_init failed (%s)\n", strerror(errno));
390390
}
391391

392-
ret = hwloc_topology_set_io_types_filter(shmem_topology, HWLOC_TYPE_FILTER_KEEP_ALL);
392+
ret = hwloc_topology_set_io_types_filter(shmem_internal_topology, HWLOC_TYPE_FILTER_KEEP_ALL);
393393
if (ret < 0) {
394394
RETURN_ERROR_MSG("hwloc_topology_set_io_types_filter failed (%s)\n", strerror(errno));
395395
}
396396

397-
ret = hwloc_topology_load(shmem_topology);
397+
ret = hwloc_topology_load(shmem_internal_topology);
398398
if (ret < 0) {
399399
RETURN_ERROR_MSG("hwloc_topology_load failed (%s)\n", strerror(errno));
400400
}
@@ -403,20 +403,20 @@ shmem_internal_heap_postinit(void)
403403
hwloc_bitmap_t bindset_all = hwloc_bitmap_alloc();
404404
hwloc_bitmap_t bindset_socket = hwloc_bitmap_alloc();
405405

406-
ret = hwloc_get_proc_last_cpu_location(shmem_topology, getpid(), bindset, HWLOC_CPUBIND_PROCESS);
406+
ret = hwloc_get_proc_last_cpu_location(shmem_internal_topology, getpid(), bindset, HWLOC_CPUBIND_PROCESS);
407407
if (ret < 0) {
408408
RETURN_ERROR_MSG("hwloc_get_proc_last_cpu_location failed (%s)\n", strerror(errno));
409409
}
410410

411-
ret = hwloc_get_proc_cpubind(shmem_topology, getpid(), bindset_all, HWLOC_CPUBIND_PROCESS);
411+
ret = hwloc_get_proc_cpubind(shmem_internal_topology, getpid(), bindset_all, HWLOC_CPUBIND_PROCESS);
412412
if (ret < 0) {
413413
RETURN_ERROR_MSG("hwloc_get_proc_cpubind failed (%s)\n", strerror(errno));
414414
}
415415

416-
hwloc_obj_t socket = hwloc_get_next_obj_covering_cpuset_by_type(shmem_topology, bindset, HWLOC_OBJ_PACKAGE, NULL);
416+
hwloc_obj_t socket = hwloc_get_next_obj_covering_cpuset_by_type(shmem_internal_topology, bindset, HWLOC_OBJ_PACKAGE, NULL);
417417
if (!socket) RETURN_ERROR_MSG("hwloc_get_next_obj_covering_cpuset_by_type failed (could not detect object of type 'HWLOC_OBJ_PACKAGE' in provided cpuset)\n");
418418
hwloc_bitmap_and(bindset_socket, bindset_all, socket->cpuset);
419-
hwloc_set_proc_cpubind(shmem_topology, getpid(), bindset_socket, HWLOC_CPUBIND_PROCESS); //Include HWLOC_CPUBIND_STRICT in flags?
419+
hwloc_set_proc_cpubind(shmem_internal_topology, getpid(), bindset_socket, HWLOC_CPUBIND_PROCESS); //Include HWLOC_CPUBIND_STRICT in flags?
420420

421421
hwloc_bitmap_free(bindset);
422422
hwloc_bitmap_free(bindset_all);

src/shmem_internal.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extern unsigned int shmem_internal_rand_seed;
5353

5454
#ifdef USE_HWLOC
5555
#include <hwloc.h>
56-
extern hwloc_topology_t shmem_topology;
56+
extern hwloc_topology_t shmem_internal_topology;
5757
#endif
5858

5959
#define SHMEM_INTERNAL_HEAP_OVERHEAD (1024*1024)

src/transport_ofi.c

+41-33
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ struct fi_info *assign_nic_with_hwloc(struct fi_info *fabric, struct fi_info **p
13381338
int ret = 0;
13391339
hwloc_bitmap_t bindset = hwloc_bitmap_alloc();
13401340

1341-
ret = hwloc_get_proc_last_cpu_location(shmem_topology, getpid(), bindset, HWLOC_CPUBIND_PROCESS);
1341+
ret = hwloc_get_proc_last_cpu_location(shmem_internal_topology, getpid(), bindset, HWLOC_CPUBIND_PROCESS);
13421342
if (ret < 0) {
13431343
RAISE_ERROR_MSG("hwloc_get_proc_last_cpu_location failed (%s)\n", strerror(errno));
13441344
}
@@ -1352,10 +1352,16 @@ struct fi_info *assign_nic_with_hwloc(struct fi_info *fabric, struct fi_info **p
13521352
if (cur_prov->nic->bus_attr->bus_type != FI_BUS_PCI) continue;
13531353

13541354
struct fi_pci_attr pci = cur_prov->nic->bus_attr->attr.pci;
1355-
hwloc_obj_t io_device = hwloc_get_pcidev_by_busid(shmem_topology, pci.domain_id, pci.bus_id, pci.device_id, pci.function_id);
1356-
if (!io_device) RAISE_ERROR_MSG("hwloc_get_pcidev_by_busid failed\n");
1357-
hwloc_obj_t first_non_io = hwloc_get_non_io_ancestor_obj(shmem_topology, io_device);
1358-
if (!first_non_io) RAISE_ERROR_MSG("hwloc_get_non_io_ancestor_obj failed\n");
1355+
hwloc_obj_t io_device = hwloc_get_pcidev_by_busid(shmem_internal_topology, pci.domain_id, pci.bus_id, pci.device_id, pci.function_id);
1356+
if (!io_device) {
1357+
RAISE_WARN_MSG("hwloc_get_pcidev_by_busid failed\n");
1358+
return provs[shmem_internal_my_pe % num_nics];
1359+
};
1360+
hwloc_obj_t first_non_io = hwloc_get_non_io_ancestor_obj(shmem_internal_topology, io_device);
1361+
if (!first_non_io) {
1362+
RAISE_WARN_MSG("hwloc_get_non_io_ancestor_obj failed\n");
1363+
return provs[shmem_internal_my_pe % num_nics];
1364+
}
13591365

13601366
if (hwloc_bitmap_isincluded(bindset, first_non_io->cpuset) ||
13611367
hwloc_bitmap_isincluded(first_non_io->cpuset, bindset)) {
@@ -1372,7 +1378,6 @@ struct fi_info *assign_nic_with_hwloc(struct fi_info *fabric, struct fi_info **p
13721378
RAISE_WARN_MSG("Could not detect any NICs with affinity to the process\n");
13731379

13741380
/* If no 'close' NICs, select from list of all NICs using round-robin assignment */
1375-
//return provs[shmem_team_my_pe(SHMEMX_TEAM_NODE) % num_nics];
13761381
return provs[shmem_internal_my_pe % num_nics];
13771382
}
13781383

@@ -1386,7 +1391,6 @@ struct fi_info *assign_nic_with_hwloc(struct fi_info *fabric, struct fi_info **p
13861391

13871392
hwloc_bitmap_free(bindset);
13881393

1389-
//struct fi_info *provider = prov_list[shmem_team_my_pe(SHMEMX_TEAM_NODE) % num_close_nics];
13901394
struct fi_info *provider = prov_list[shmem_internal_my_pe % num_close_nics];
13911395
free(prov_list);
13921396

@@ -1512,7 +1516,8 @@ int query_for_fabric(struct fabric_info *info)
15121516
info->prov_name != NULL ? info->prov_name : "<auto>");
15131517

15141518
/* If the user supplied a fabric or domain name, use it to select the
1515-
* fabric. Otherwise, select the first fabric in the list. */
1519+
* fabrics that may be chosen. Otherwise, consider all available
1520+
* fabrics */
15161521
int num_nics = 0;
15171522
struct fi_info *fallback = NULL;
15181523
struct fi_info *filtered_fabrics_list_head = NULL;
@@ -1544,38 +1549,41 @@ int query_for_fabric(struct fabric_info *info)
15441549

15451550
info->p_info = NULL;
15461551

1547-
for (cur_fabric = filtered_fabrics_list_head; cur_fabric; cur_fabric = cur_fabric->next) {
1548-
if (!fallback) fallback = cur_fabric;
1549-
if (cur_fabric->nic && !nic_already_used(cur_fabric->nic, multirail_fabric_list_head, num_nics)) {
1550-
num_nics += 1;
1551-
if (!multirail_fabric_list_head) multirail_fabric_list_head = cur_fabric;
1552-
if (multirail_fabric_last_added) multirail_fabric_last_added->next = cur_fabric;
1553-
multirail_fabric_last_added = cur_fabric;
1554-
}
1555-
}
1556-
1557-
DEBUG_MSG("Total num. NICs detected: %d\n", num_nics);
1558-
if ((num_nics == 0) || (shmem_internal_params.DISABLE_MULTIRAIL)) {
1559-
info->p_info = fallback;
1552+
if (shmem_internal_params.DISABLE_MULTIRAIL) {
1553+
info->p_info = filtered_fabrics_list_head;
15601554
}
15611555
else {
1562-
int idx = 0;
1563-
struct fi_info **prov_list = (struct fi_info **) malloc(num_nics * sizeof(struct fi_info *));
1564-
for (cur_fabric = multirail_fabric_list_head; cur_fabric; cur_fabric = cur_fabric->next) {
1565-
prov_list[idx++] = cur_fabric;
1556+
/* Generate a linked list of all fabrics with a non-null nic value */
1557+
for (cur_fabric = filtered_fabrics_list_head; cur_fabric; cur_fabric = cur_fabric->next) {
1558+
if (!fallback) fallback = cur_fabric;
1559+
if (cur_fabric->nic && !nic_already_used(cur_fabric->nic, multirail_fabric_list_head, num_nics)) {
1560+
num_nics += 1;
1561+
if (!multirail_fabric_list_head) multirail_fabric_list_head = cur_fabric;
1562+
if (multirail_fabric_last_added) multirail_fabric_last_added->next = cur_fabric;
1563+
multirail_fabric_last_added = cur_fabric;
1564+
}
15661565
}
1567-
qsort(prov_list, num_nics, sizeof(struct fi_info *), compare_nic_names);
1568-
//DEBUG_MSG("[%d]: local_pe = %d\n", shmem_internal_my_pe, shmem_team_my_pe(SHMEMX_TEAM_NODE));
1566+
1567+
DEBUG_MSG("Total num. NICs detected: %d\n", num_nics);
1568+
if (num_nics == 0) {
1569+
info->p_info = fallback;
1570+
}
1571+
else {
1572+
int idx = 0;
1573+
struct fi_info **prov_list = (struct fi_info **) malloc(num_nics * sizeof(struct fi_info *));
1574+
for (cur_fabric = multirail_fabric_list_head; cur_fabric; cur_fabric = cur_fabric->next) {
1575+
prov_list[idx++] = cur_fabric;
1576+
}
1577+
qsort(prov_list, num_nics, sizeof(struct fi_info *), compare_nic_names);
15691578
#ifdef USE_HWLOC
1570-
info->p_info = assign_nic_with_hwloc(info->p_info, prov_list, num_nics);
1579+
info->p_info = assign_nic_with_hwloc(info->p_info, prov_list, num_nics);
15711580
#else
1572-
/* Round-robin assignment of NICs to PEs */
1573-
//info->p_info = prov_list[shmem_team_my_pe(SHMEMX_TEAM_NODE) % num_nics];
1574-
info->p_info = prov_list[shmem_internal_my_pe % num_nics];
1581+
/* Round-robin assignment of NICs to PEs */
1582+
info->p_info = prov_list[shmem_internal_my_pe % num_nics];
15751583
#endif
1576-
free(prov_list);
1584+
free(prov_list);
1585+
}
15771586
}
1578-
15791587
if (NULL == info->p_info) {
15801588
RAISE_WARN_MSG("OFI transport, no valid fabric (prov=%s, fabric=%s, domain=%s)\n",
15811589
info->prov_name != NULL ? info->prov_name : "<auto>",

0 commit comments

Comments
 (0)