Skip to content

Commit

Permalink
Add and test qvi_scope_ksplit_at(), update internal APIs.
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel K. Gutierrez <samuel@lanl.gov>
  • Loading branch information
samuelkgutierrez committed Apr 30, 2024
1 parent c10a8e4 commit 9b02cf4
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 20 deletions.
50 changes: 38 additions & 12 deletions src/qvi-scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,17 @@ qvi_scope_free(

void
qvi_scope_kfree(
std::vector<qv_scope_t *> &scopes
qv_scope_t ***kscopes,
uint_t k
) {
for (auto scope : scopes) {
qvi_scope_free(&scope);
if (!kscopes) return;

qv_scope_t **ikscopes = *kscopes;
for (uint_t i = 0; i < k; ++i) {
qvi_scope_free(&ikscopes[i]);
}
scopes.clear();
delete[] ikscopes;
*kscopes = nullptr;
}

static int
Expand Down Expand Up @@ -1147,15 +1152,18 @@ int
qvi_scope_ksplit(
qv_scope_t *parent,
uint_t npieces,
const std::vector<int> &kcolors,
std::vector<qv_scope_t *> &kchildren
int *kcolors,
uint_t k,
qv_hw_obj_type_t maybe_obj_type,
qv_scope_t ***kchildren
) {
if (kcolors.size() == 0) return QV_ERR_INVLD_ARG;
if (k == 0 || !kchildren) return QV_ERR_INVLD_ARG;
*kchildren = nullptr;

const uint_t group_size = kcolors.size();
const uint_t group_size = k;
qvi_scope_split_agg_s splitagg{};
int rc = splitagg.init(
parent->rmi, parent->hwpool, group_size, npieces, QV_HW_OBJ_LAST
parent->rmi, parent->hwpool, group_size, npieces, maybe_obj_type
);
if (rc != QV_SUCCESS) return rc;
// Since this is called by a single task, get its ID and associated hardware
Expand Down Expand Up @@ -1191,8 +1199,10 @@ qvi_scope_ksplit(
// Split the hardware resources based on the provided split parameters.
rc = agg_split(splitagg);
if (rc != QV_SUCCESS) return rc;

// Now populate the children.
kchildren.resize(group_size);
qv_scope_t **ikchildren = qvi_new qv_scope_t*[group_size];
if (!ikchildren) return QV_ERR_OOR;

for (uint_t i = 0; i < group_size; ++i) {
// Split off from our parent group. This call is usually called from a
Expand Down Expand Up @@ -1223,11 +1233,12 @@ qvi_scope_ksplit(
qvi_scope_free(&child);
break;
}
kchildren[i] = child;
ikchildren[i] = child;
}
if (rc != QV_SUCCESS) {
kchildren.clear();
qvi_scope_kfree(&ikchildren, k);
}
*kchildren = ikchildren;
return rc;
}

Expand All @@ -1253,6 +1264,21 @@ qvi_scope_split_at(
return rc;
}

int
qvi_scope_ksplit_at(
qv_scope_t *parent,
qv_hw_obj_type_t type,
int *kgroup_ids,
uint_t k,
qv_scope_t ***kchildren
) {
int nobj = 0;
int rc = qvi_scope_nobjs(parent, type, &nobj);
if (rc != QV_SUCCESS) return rc;

return qvi_scope_ksplit(parent, nobj, kgroup_ids, k, type, kchildren);
}

int
qvi_scope_create(
qv_scope_t *parent,
Expand Down
23 changes: 19 additions & 4 deletions src/qvi-scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ qvi_scope_free(
);

/**
* Frees scope resources and clears the input vector.
* Frees scope resources and container.
*/
void
qvi_scope_kfree(
std::vector<qv_scope_t *> &scopes
qv_scope_t ***kscopes,
uint_t k
);

/**
Expand Down Expand Up @@ -117,8 +118,10 @@ int
qvi_scope_ksplit(
qv_scope_t *parent,
uint_t npieces,
const std::vector<int> &kcolors,
std::vector<qv_scope_t *> &kchildren
int *kcolors,
uint_t k,
qv_hw_obj_type_t maybe_obj_type,
qv_scope_t ***kchildren
);

/**
Expand All @@ -132,6 +135,18 @@ qvi_scope_split_at(
qv_scope_t **child
);

/**
*
*/
int
qvi_scope_ksplit_at(
qv_scope_t *parent,
qv_hw_obj_type_t type,
int *kgroup_ids,
uint_t k,
qv_scope_t ***kchildren
);

/**
*
*/
Expand Down
36 changes: 32 additions & 4 deletions tests/test-mpi-scope-ksplit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,21 @@ main(void)
QV_SCOPE_SPLIT_AFFINITY_PRESERVING
);
//std::iota(colors.begin(), colors.end(), 0);
const uint_t k = colors.size();

std::vector<qv_scope_t *> subscopes;
qvi_log_info("Testing ksplit()");

qv_scope_t **subscopes = nullptr;
rc = qvi_scope_ksplit(
base_scope, npieces, colors, subscopes
base_scope, npieces, colors.data(),
k, QV_HW_OBJ_LAST, &subscopes
);
if (rc != QV_SUCCESS) {
ers = "qvi_scope_ksplit() failed";
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
}

for (uint_t i = 0; i < subscopes.size(); ++i) {
for (uint_t i = 0; i < k; ++i) {
qvi_test_scope_report(
ctx, subscopes[i], std::to_string(i).c_str()
);
Expand All @@ -99,8 +103,32 @@ main(void)
ctx, subscopes[i]
);
}
// Done with all the subscopes, so clean-up everything.
qvi_scope_kfree(&subscopes, k);

qvi_log_info("Testing ksplit_at()");
// Test qvi_scope_ksplit_at().
rc = qvi_scope_ksplit_at(
base_scope, QV_HW_OBJ_PU, colors.data(), k, &subscopes
);
if (rc != QV_SUCCESS) {
ers = "qvi_scope_ksplit_at() failed";
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
}

qvi_scope_kfree(subscopes);
for (uint_t i = 0; i < k; ++i) {
qvi_test_scope_report(
ctx, subscopes[i], std::to_string(i).c_str()
);
qvi_test_bind_push(
ctx, subscopes[i]
);
qvi_test_bind_pop(
ctx, subscopes[i]
);
}
// Done with all the subscopes, so clean-up everything.
qvi_scope_kfree(&subscopes, k);

rc = qv_scope_free(ctx, base_scope);
if (rc != QV_SUCCESS) {
Expand Down

0 comments on commit 9b02cf4

Please sign in to comment.