Skip to content

Commit

Permalink
Conduct some housekeeping. (#244)
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel K. Gutierrez <[email protected]>
  • Loading branch information
samuelkgutierrez authored Jul 25, 2024
1 parent 2d1fef4 commit 7072541
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 143 deletions.
2 changes: 1 addition & 1 deletion src/quo-vadis-mpi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ qvi_mpi_scope_comm_dup(
MPI_Comm *comm
) {
qvi_group_mpi_t *const mpi_group = dynamic_cast<qvi_group_mpi_t *>(
qvi_scope_group_get(scope)
qvi_scope_group(scope)
);
return mpi_group->comm_dup(comm);
}
Expand Down
2 changes: 1 addition & 1 deletion src/quo-vadis-pthread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ qv_pthread_create(
// pthread_create(), return a reasonable errno.
if (qvi_unlikely(rc != QV_SUCCESS)) return ENOMEM;

auto group = dynamic_cast<qvi_group_pthread_t *>(qvi_scope_group_get(scope));
auto group = dynamic_cast<qvi_group_pthread_t *>(qvi_scope_group(scope));
qvi_pthread_group_pthread_create_args_s *cargs = nullptr;
rc = qvi_new(&cargs, group->thgroup, qvi_pthread_routine, arg_ptr);
if (qvi_unlikely(rc != QV_SUCCESS)) {
Expand Down
2 changes: 1 addition & 1 deletion src/quo-vadis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ qv_scope_get_device_id(
return QV_ERR_INVLD_ARG;
}
try {
return qvi_scope_get_device_id(
return qvi_scope_device_id(
scope, dev_obj, dev_index, id_type, dev_id
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/qvi-bbuff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ qvi_bbuff_size(
int
qvi_bbuff_append(
qvi_bbuff_t *buff,
const void *data,
const void *const data,
size_t size
) {
const size_t req_capacity = size + buff->size;
Expand Down
10 changes: 1 addition & 9 deletions src/qvi-bbuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@

#include "qvi-common.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
*
*/
Expand Down Expand Up @@ -69,14 +65,10 @@ qvi_bbuff_size(
int
qvi_bbuff_append(
qvi_bbuff_t *buff,
const void *data,
const void *const data,
size_t size
);

#ifdef __cplusplus
}
#endif

#endif

/*
Expand Down
4 changes: 4 additions & 0 deletions src/qvi-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ typedef uint8_t byte_t;
typedef char const* cstr_t;
typedef unsigned int uint_t;

/** Opaque hwloc instance. */
struct qvi_hwloc_s;
typedef struct qvi_hwloc_s qvi_hwloc_t;

/** Opaque RMI client. */
struct qvi_rmi_client_s;
typedef struct qvi_rmi_client_s qvi_rmi_client_t;
Expand Down
7 changes: 7 additions & 0 deletions src/qvi-group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@

#include "qvi-group.h"
#include "qvi-group-pthread.h"
#include "qvi-task.h" // IWYU pragma: keep
#include "qvi-utils.h"

qvi_hwloc_t *
qvi_group_s::hwloc(void)
{
return task()->hwloc();
}

int
qvi_group_s::thsplit(
int nthreads,
Expand Down
3 changes: 3 additions & 0 deletions src/qvi-group.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ struct qvi_group_s : qvi_refc_s {
/** Returns pointer to the caller's task information. */
virtual qvi_task_t *
task(void) = 0;
/** Returns pointer to the task's hwloc information. */
qvi_hwloc_t *
hwloc(void);
/** Returns the number of members in this group. */
virtual int
size(void) = 0;
Expand Down
17 changes: 17 additions & 0 deletions src/qvi-hwloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,23 @@ qvi_hwloc_obj_type_is_host_resource(
}
}

int
qvi_hwloc_bitmap_string(
hwloc_const_bitmap_t bitmap,
qv_bind_string_format_t format,
char **result
) {
switch (format) {
case QV_BIND_STRING_AS_BITMAP:
return qvi_hwloc_bitmap_asprintf(result, bitmap);
case QV_BIND_STRING_AS_LIST:
return qvi_hwloc_bitmap_list_asprintf(result, bitmap);
default:
*result = nullptr;
return QV_ERR_INVLD_ARG;
}
}

int
qvi_hwloc_obj_type_depth(
qvi_hwloc_t *hwloc,
Expand Down
10 changes: 7 additions & 3 deletions src/qvi-hwloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ const int QVI_HWLOC_DEVICE_INVISIBLE_ID = -1;
/** ID used to indicate an invalid or unset ID. */
const int QVI_HWLOC_DEVICE_INVALID_ID = -1;

struct qvi_hwloc_s;
typedef struct qvi_hwloc_s qvi_hwloc_t;

struct qvi_hwloc_device_s;
typedef struct qvi_hwloc_device_s qvi_hwloc_device_t;

Expand Down Expand Up @@ -531,6 +528,13 @@ qvi_hwloc_get_devices_in_bitmap(
qvi_hwloc_dev_list_t &devs
);

int
qvi_hwloc_bitmap_string(
hwloc_const_bitmap_t bitmap,
qv_bind_string_format_t format,
char **result
);

#endif

#endif
Expand Down
3 changes: 1 addition & 2 deletions src/qvi-hwpool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ pool_release_cpus_by_cpuset(
}
#endif

// TODO(skg) Acquire devices.
int
qvi_hwpool_s::add_devices_with_affinity(
qvi_hwloc_t *hwloc
Expand Down Expand Up @@ -288,8 +287,8 @@ qvi_hwpool_s::unpack(
}
out:
if (qvi_unlikely(rc != QV_SUCCESS)) {
total_bw = 0;
qvi_delete(&ihwp);
total_bw = 0;
}
*bytes_written = total_bw;
*hwp = ihwp;
Expand Down
2 changes: 1 addition & 1 deletion src/qvi-hwpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#ifndef QVI_HWPOOL_H
#define QVI_HWPOOL_H

#include "qvi-common.h" // IWYU pragma: keep
#include "qvi-common.h"
#include "qvi-hwloc.h"

/**
Expand Down
1 change: 0 additions & 1 deletion src/qvi-rmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define QVI_RMI_H

#include "qvi-common.h"
#include "qvi-hwloc.h"
#include "qvi-hwpool.h"

#ifdef __cplusplus
Expand Down
112 changes: 49 additions & 63 deletions src/qvi-scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
// TODO(skg) Add RMI to acquire/release resources.

#include "qvi-scope.h"
#include "qvi-bbuff.h"
#include "qvi-task.h"
#include "qvi-bbuff.h"
#include "qvi-rmi.h"
#include "qvi-bbuff-rmi.h"
#include "qvi-hwpool.h"
Expand All @@ -29,7 +29,6 @@
/** Maintains a mapping between IDs to device information. */
using id_devinfo_multimap_t = std::multimap<int, const qvi_hwpool_dev_s *>;

/** Scope type definition. */
struct qv_scope_s {
/** Task group associated with this scope instance. */
qvi_group_t *group = nullptr;
Expand Down Expand Up @@ -60,6 +59,33 @@ qvi_scope_new(
return qvi_new(scope, group, hwpool);
}

int
qvi_scope_get(
qvi_group_t *group,
qv_scope_intrinsic_t iscope,
qv_scope_t **scope
) {
qvi_hwpool_s *hwpool = nullptr;
// Get the requested intrinsic group.
int rc = group->make_intrinsic(iscope);
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
// Get the requested intrinsic hardware pool.
rc = qvi_rmi_scope_get_intrinsic_hwpool(
group->task()->rmi(),
qvi_task_s::mytid(),
iscope, &hwpool
);
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
// Create and initialize the scope.
rc = qvi_scope_new(group, hwpool, scope);
out:
if (qvi_unlikely(rc != QV_SUCCESS)) {
qvi_delete(&hwpool);
qvi_scope_free(scope);
}
return rc;
}

void
qvi_scope_free(
qv_scope_t **scope
Expand All @@ -82,23 +108,23 @@ qvi_scope_thfree(
}

qvi_group_t *
qvi_scope_group_get(
qvi_scope_group(
qv_scope_t *scope
) {
assert(scope);
return scope->group;
}

const qvi_hwpool_s *
qvi_scope_hwpool_get(
qvi_scope_hwpool(
qv_scope_t *scope
) {
assert(scope);
return scope->hwpool;
}

const qvi_hwloc_bitmap_s &
qvi_scope_cpuset_get(
qvi_scope_cpuset(
qv_scope_t *scope
) {
assert(scope);
Expand Down Expand Up @@ -140,33 +166,33 @@ qvi_scope_nobjs(
int *n
) {
return scope->hwpool->nobjects(
scope->group->task()->hwloc(), obj, n
scope->group->hwloc(), obj, n
);
}

int
qvi_scope_get_device_id(
qvi_scope_device_id(
qv_scope_t *scope,
qv_hw_obj_type_t dev_obj,
int i,
qv_hw_obj_type_t dev_type,
int dev_index,
qv_device_id_type_t id_type,
char **dev_id
) {
int rc = QV_SUCCESS, id = 0, nw = 0;

// Look for the requested device.
qvi_hwpool_dev_s *finfo = nullptr;
for (const auto &dinfo : scope->hwpool->devices()) {
if (dev_obj != dinfo.first) continue;
if (id++ == i) {
if (dev_type != dinfo.first) continue;
if (id++ == dev_index) {
finfo = dinfo.second.get();
break;
}
}
if (!finfo) {
if (qvi_unlikely(!finfo)) {
rc = QV_ERR_NOT_FOUND;
goto out;
}

// Format the device ID based on the caller's request.
switch (id_type) {
case (QV_DEVICE_ID_UUID):
nw = asprintf(dev_id, "%s", finfo->uuid.c_str());
Expand All @@ -181,9 +207,9 @@ qvi_scope_get_device_id(
rc = QV_ERR_INVLD_ARG;
goto out;
}
if (nw == -1) rc = QV_ERR_OOR;
if (qvi_unlikely(nw == -1)) rc = QV_ERR_OOR;
out:
if (rc != QV_SUCCESS) {
if (qvi_unlikely(rc != QV_SUCCESS)) {
*dev_id = nullptr;
}
return rc;
Expand All @@ -209,54 +235,14 @@ int
qvi_scope_bind_string(
qv_scope_t *scope,
qv_bind_string_format_t format,
char **str
char **result
) {
char *istr = nullptr;

hwloc_cpuset_t cpuset = nullptr;
int rc = scope->group->task()->bind_top(&cpuset);
if (rc != QV_SUCCESS) return rc;

switch (format) {
case QV_BIND_STRING_AS_BITMAP:
rc = qvi_hwloc_bitmap_asprintf(&istr, cpuset);
break;
case QV_BIND_STRING_AS_LIST:
rc = qvi_hwloc_bitmap_list_asprintf(&istr, cpuset);
break;
default:
rc = QV_ERR_INVLD_ARG;
break;
}
qvi_hwloc_bitmap_free(&cpuset);
*str = istr;
return rc;
}
hwloc_cpuset_t bitmap = nullptr;
int rc = scope->group->task()->bind_top(&bitmap);
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;

int
qvi_scope_get(
qvi_group_t *group,
qv_scope_intrinsic_t iscope,
qv_scope_t **scope
) {
qvi_hwpool_s *hwpool = nullptr;
// Get the requested intrinsic group.
int rc = group->make_intrinsic(iscope);
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
// Get the requested intrinsic hardware pool.
rc = qvi_rmi_scope_get_intrinsic_hwpool(
group->task()->rmi(),
qvi_task_s::mytid(),
iscope, &hwpool
);
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
// Create and initialize the scope.
rc = qvi_scope_new(group, hwpool, scope);
out:
if (qvi_unlikely(rc != QV_SUCCESS)) {
qvi_delete(&hwpool);
qvi_scope_free(scope);
}
rc = qvi_hwloc_bitmap_string(bitmap, format, result);
qvi_hwloc_bitmap_free(&bitmap);
return rc;
}

Expand Down Expand Up @@ -1337,7 +1323,7 @@ qvi_scope_create(
rc = qvi_new(&hwpool);
if (rc != QV_SUCCESS) goto out;

rc = hwpool->initialize(parent->group->task()->hwloc(), cpuset);
rc = hwpool->initialize(parent->group->hwloc(), cpuset);
if (rc != QV_SUCCESS) goto out;
// Create underlying group. Notice the use of self here.
rc = parent->group->self(&group);
Expand Down
Loading

0 comments on commit 7072541

Please sign in to comment.