Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup more code. #95

Merged
merged 1 commit into from
Mar 19, 2024
Merged
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
23 changes: 10 additions & 13 deletions src/qvi-hwloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 {
Expand Down Expand Up @@ -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
);
}
//
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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<qvi_hwloc_device_t>();
int rc = qvi_construct_rc(devin);
Expand Down Expand Up @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions src/qvi-hwloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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

/*
Expand Down
29 changes: 15 additions & 14 deletions src/qvi-hwpool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ struct qvi_hwpool_resource_info_s {
* location in the cpuset.
*/
std::vector<uint32_t> 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;
};

Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 *
Expand Down Expand Up @@ -371,15 +372,15 @@ 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.
for (int devi = 0; devi < nobjs; ++devi) {
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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/qvi-mpi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading