Skip to content

Commit

Permalink
Add qvi_hwloc_bitmap_dup() and use it. (#93)
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel K. Gutierrez <samuel@lanl.gov>
  • Loading branch information
samuelkgutierrez authored Mar 18, 2024
1 parent e261550 commit c924ef2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
26 changes: 20 additions & 6 deletions src/qvi-hwloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -705,17 +705,32 @@ qvi_hwloc_bitmap_copy(
hwloc_const_cpuset_t src,
hwloc_cpuset_t dest
) {
if (!src || !dest) {
assert(false);
return QV_ERR_INTERNAL;
}
assert(src && dest);

if (hwloc_bitmap_copy(dest, src) != 0) {
return QV_ERR_HWLOC;
}
return QV_SUCCESS;
}

int
qvi_hwloc_bitmap_dup(
hwloc_const_cpuset_t src,
hwloc_cpuset_t *dest
) {
hwloc_cpuset_t idest = nullptr;
int rc = qvi_hwloc_bitmap_calloc(&idest);
if (rc != QV_SUCCESS) goto out;

rc = qvi_hwloc_bitmap_copy(src, idest);
out:
if (rc != QV_SUCCESS) {
qvi_hwloc_bitmap_free(&idest);
}
*dest = idest;
return rc;
}

int
qvi_hwloc_bitmap_nbits(
hwloc_const_cpuset_t cpuset,
Expand Down Expand Up @@ -1545,8 +1560,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;
qvi_hwloc_bitmap_calloc(&icpuset);
rc = qvi_hwloc_bitmap_copy(dev->cpuset, icpuset);
rc = qvi_hwloc_bitmap_dup(dev->cpuset, &icpuset);
if (rc != QV_SUCCESS) goto out;
}
if (!icpuset) rc = QV_ERR_NOT_FOUND;
Expand Down
9 changes: 9 additions & 0 deletions src/qvi-hwloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ qvi_hwloc_bitmap_copy(
hwloc_cpuset_t dest
);

/**
*
*/
int
qvi_hwloc_bitmap_dup(
hwloc_const_cpuset_t src,
hwloc_cpuset_t *dest
);

/**
* Returns the number of bits required to represent a given cpuset.
*/
Expand Down
16 changes: 5 additions & 11 deletions src/qvi-hwpool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,8 @@ qvi_hwpool_new_line_from_hwpool(
qvi_line_hwpool_t *iline = nullptr;
rc = qvi_line_hwpool_new(&iline);
if (rc != QV_SUCCESS) goto out;
// Initialize and copy the cpuset.
rc = qvi_hwloc_bitmap_calloc(&iline->cpuset);
if (rc != QV_SUCCESS) goto out;
rc = qvi_hwloc_bitmap_copy(rpool->cpus.cpuset, iline->cpuset);
// Duplicate the cpuset.
rc = qvi_hwloc_bitmap_dup(rpool->cpus.cpuset, &iline->cpuset);
if (rc != QV_SUCCESS) goto out;
// Initialize and fill in the device information.
iline->ndevinfos = ndevinfos;
Expand All @@ -192,14 +190,10 @@ qvi_hwpool_new_line_from_hwpool(
for (const auto &dinfo : rpool->devinfos) {
iline->devinfos[idx].type = dinfo.second->type;
iline->devinfos[idx].id = dinfo.second->id;
// Initialize and copy cpuset
rc = qvi_hwloc_bitmap_calloc(
&iline->devinfos[idx].affinity
);
if (rc != QV_SUCCESS) break;
rc = qvi_hwloc_bitmap_copy(
// Duplicate the cpuset
rc = qvi_hwloc_bitmap_dup(
dinfo.second->affinity,
iline->devinfos[idx].affinity
&iline->devinfos[idx].affinity
);
if (rc != QV_SUCCESS) break;
nw = asprintf(
Expand Down

0 comments on commit c924ef2

Please sign in to comment.