diff --git a/src/qvi-hwloc.cc b/src/qvi-hwloc.cc index 070be3db..5a56c0da 100644 --- a/src/qvi-hwloc.cc +++ b/src/qvi-hwloc.cc @@ -56,7 +56,7 @@ static const int QVI_HWLOC_DEVICE_INVISIBLE_ID = -1; typedef struct qvi_hwloc_device_s { int qvim_rc = QV_ERR_INTERNAL; /** Device cpuset */ - hwloc_cpuset_t cpuset = nullptr; + qvi_hwloc_bitmap_t cpuset; /** Internal object type information */ qvi_hwloc_objx_t objx = {}; /** Vendor ID */ @@ -74,13 +74,10 @@ typedef struct qvi_hwloc_device_s { /** Constructor */ qvi_hwloc_device_s(void) { - qvim_rc = qvi_hwloc_bitmap_calloc(&cpuset); + qvim_rc = qvi_construct_rc(cpuset); } /** Destructor */ - ~qvi_hwloc_device_s(void) - { - qvi_hwloc_bitmap_free(&cpuset); - } + ~qvi_hwloc_device_s(void) = default; } qvi_hwloc_device_t; typedef struct qvi_hwloc_s { @@ -415,7 +412,7 @@ set_gpu_device_info( return qvi_hwloc_rsmi_get_device_cpuset_by_device_id( hwl, device->smi, - device->cpuset + device->cpuset.data ); } // @@ -431,7 +428,7 @@ set_gpu_device_info( return qvi_hwloc_nvml_get_device_cpuset_by_pci_bus_id( hwl, device->pci_bus_id, - device->cpuset + device->cpuset.data ); } return QV_SUCCESS; @@ -1144,7 +1141,7 @@ get_nosdevs_in_cpuset( ) { int ndevs = 0; for (auto &dev : devs) { - if (hwloc_bitmap_isincluded(dev->cpuset, cpuset)) ndevs++; + if (hwloc_bitmap_isincluded(dev->cpuset.data, cpuset)) ndevs++; } *nobjs = ndevs; @@ -1249,7 +1246,7 @@ qvi_hwloc_device_copy( qvi_hwloc_device_t *src, qvi_hwloc_device_t *dest ) { - int rc = qvi_hwloc_bitmap_copy(src->cpuset, dest->cpuset); + int rc = qvi_hwloc_bitmap_copy(src->cpuset.data, dest->cpuset.data); if (rc != QV_SUCCESS) return rc; dest->objx = src->objx; @@ -1279,7 +1276,7 @@ qvi_hwloc_devices_emit( } for (auto &dev : *devlist) { char *cpusets = nullptr; - int rc = qvi_hwloc_bitmap_asprintf(&cpusets, dev->cpuset); + int rc = qvi_hwloc_bitmap_asprintf(&cpusets, dev->cpuset.data); if (rc != QV_SUCCESS) return rc; qvi_log_info(" Device Name: {}", dev->name); @@ -1302,7 +1299,7 @@ get_devices_in_cpuset_from_dev_list( qvi_hwloc_dev_list_t &devs ) { for (auto &dev : devlist) { - if (!hwloc_bitmap_isincluded(dev->cpuset, cpuset)) continue; + if (!hwloc_bitmap_isincluded(dev->cpuset.data, cpuset)) continue; auto devin = std::make_shared(); int rc = qvi_construct_rc(devin); @@ -1560,7 +1557,7 @@ qvi_hwloc_get_device_affinity( // lists tend to be small, so just perform a linear search for the given ID. for (const auto &dev : *devlist) { if (dev->visdev_id != device_id) continue; - rc = qvi_hwloc_bitmap_dup(dev->cpuset, &icpuset); + rc = qvi_hwloc_bitmap_dup(dev->cpuset.data, &icpuset); if (rc != QV_SUCCESS) goto out; } if (!icpuset) rc = QV_ERR_NOT_FOUND; diff --git a/src/qvi-hwloc.h b/src/qvi-hwloc.h index 7caa7563..ca8b613a 100644 --- a/src/qvi-hwloc.h +++ b/src/qvi-hwloc.h @@ -33,6 +33,9 @@ extern "C" { struct qvi_hwloc_s; typedef struct qvi_hwloc_s qvi_hwloc_t; +struct qvi_hwloc_bitmap_s; +typedef struct qvi_hwloc_bitmap_s qvi_hwloc_bitmap_t; + struct qvi_hwloc_device_s; typedef struct qvi_hwloc_device_s qvi_hwloc_device_t; @@ -417,6 +420,36 @@ qvi_hwloc_get_device_affinity( } #endif +#ifdef __cplusplus + +/** + * C++ style hwloc bitmap. + */ +struct qvi_hwloc_bitmap_s { + int qvim_rc = QV_ERR_INTERNAL; + /** Internal bitmap */ + hwloc_bitmap_t data = nullptr; + /** Constructor */ + qvi_hwloc_bitmap_s(void) + { + qvim_rc = qvi_hwloc_bitmap_calloc(&data); + } + /** Destructor */ + ~qvi_hwloc_bitmap_s(void) + { + qvi_hwloc_bitmap_free(&data); + } + /** Assignment operator. */ + void + operator=(const qvi_hwloc_bitmap_s &src) + { + qvim_rc = qvi_hwloc_bitmap_copy(src.data, data); + assert(qvim_rc == QV_SUCCESS); + } +}; + +#endif + #endif /* diff --git a/src/qvi-hwpool.cc b/src/qvi-hwpool.cc index e139548c..484f2e26 100644 --- a/src/qvi-hwpool.cc +++ b/src/qvi-hwpool.cc @@ -67,6 +67,10 @@ struct qvi_hwpool_resource_info_s { * location in the cpuset. */ std::vector resid_ref_count; + /** + * Maps resource IDs to hint flags that they might have associated with + * them. + */ qvi_hwpool_resource_id_hint_map_t resid_hint_map; }; @@ -88,18 +92,15 @@ struct qvi_hwpool_resource_s { struct qvi_hwpool_cpus_s : qvi_hwpool_resource_s { int qvim_rc = QV_ERR_INTERNAL; /** The cpuset of the maintained CPUs. */ - hwloc_bitmap_t cpuset = nullptr; + qvi_hwloc_bitmap_t cpuset; qvi_hwpool_cpus_s(void) { - qvim_rc = qvi_hwloc_bitmap_calloc(&cpuset); + qvim_rc = qvi_construct_rc(cpuset); } virtual - ~qvi_hwpool_cpus_s(void) - { - qvi_hwloc_bitmap_free(&cpuset); - } + ~qvi_hwpool_cpus_s(void) = default; }; struct qvi_hwpool_s { @@ -142,7 +143,7 @@ qvi_hwpool_new_from_line( int rc = qvi_hwpool_new(&irpool); if (rc != QV_SUCCESS) goto out; - rc = qvi_hwloc_bitmap_copy(line->cpuset, irpool->cpus.cpuset); + rc = qvi_hwpool_init(irpool, line->cpuset); if (rc != QV_SUCCESS) goto out; for (int i = 0; i < line->ndevinfos; ++i) { @@ -176,7 +177,7 @@ qvi_hwpool_new_line_from_hwpool( rc = qvi_line_hwpool_new(&iline); if (rc != QV_SUCCESS) goto out; // Duplicate the cpuset. - rc = qvi_hwloc_bitmap_dup(rpool->cpus.cpuset, &iline->cpuset); + rc = qvi_hwloc_bitmap_dup(rpool->cpus.cpuset.data, &iline->cpuset); if (rc != QV_SUCCESS) goto out; // Initialize and fill in the device information. iline->ndevinfos = ndevinfos; @@ -235,7 +236,7 @@ qvi_hwpool_init( qvi_hwpool_t *rpool, hwloc_const_bitmap_t cpuset ) { - return qvi_hwloc_bitmap_copy(cpuset, rpool->cpus.cpuset); + return qvi_hwloc_bitmap_copy(cpuset, rpool->cpus.cpuset.data); } int @@ -267,7 +268,7 @@ qvi_hwpool_cpuset_get( qvi_hwpool_t *rpool ) { assert(rpool); - return rpool->cpus.cpuset; + return rpool->cpus.cpuset.data; } const qvi_hwpool_devinfos_t * @@ -371,7 +372,7 @@ qvi_hwpool_add_devices_with_affinity( const qv_hw_obj_type_t type = devts[i]; int nobjs = 0; rc = qvi_hwloc_get_nobjs_in_cpuset( - hwloc, type, pool->cpus.cpuset, &nobjs + hwloc, type, pool->cpus.cpuset.data, &nobjs ); if (rc != QV_SUCCESS) break; // Iterate over the number of devices in each type. @@ -379,7 +380,7 @@ qvi_hwpool_add_devices_with_affinity( char *devids = nullptr, *pcibid = nullptr, *uuids = nullptr; // Device ID rc = qvi_hwloc_get_device_in_cpuset( - hwloc, type, devi, pool->cpus.cpuset, + hwloc, type, devi, pool->cpus.cpuset.data, QV_DEVICE_ID_ORDINAL, &devids ); if (rc != QV_SUCCESS) break; @@ -389,13 +390,13 @@ qvi_hwpool_add_devices_with_affinity( if (rc != QV_SUCCESS) break; // PCI Bus ID rc = qvi_hwloc_get_device_in_cpuset( - hwloc, type, devi, pool->cpus.cpuset, + hwloc, type, devi, pool->cpus.cpuset.data, QV_DEVICE_ID_PCI_BUS_ID, &pcibid ); if (rc != QV_SUCCESS) break; // UUID rc = qvi_hwloc_get_device_in_cpuset( - hwloc, type, devi, pool->cpus.cpuset, + hwloc, type, devi, pool->cpus.cpuset.data, QV_DEVICE_ID_UUID, &uuids ); if (rc != QV_SUCCESS) break; diff --git a/src/qvi-mpi.cc b/src/qvi-mpi.cc index 58ee6ed8..45102f9a 100644 --- a/src/qvi-mpi.cc +++ b/src/qvi-mpi.cc @@ -40,8 +40,8 @@ struct qvi_mpi_group_s { /** Destructor */ ~qvi_mpi_group_s(void) = default; /** Assignment operator. */ - void operator= - (const qvi_mpi_group_s &src) + void + operator=(const qvi_mpi_group_s &src) { qvim_rc = src.qvim_rc; tabid = src.tabid;