Skip to content

Commit 3adb1cd

Browse files
Cleanup some qvi-split code. (#258)
Signed-off-by: Samuel K. Gutierrez <[email protected]>
1 parent 4a47788 commit 3adb1cd

File tree

3 files changed

+79
-99
lines changed

3 files changed

+79
-99
lines changed

src/qvi-scope.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ qvi_scope_split(
258258
qvi_group_t *group = nullptr;
259259
qv_scope_t *ichild = nullptr;
260260
// Split the hardware resources based on the provided split parameters.
261-
qvi_scope_split_coll_s splitcoll(
261+
qvi_coll_hwsplit_s chwsplit(
262262
parent, npieces, color, maybe_obj_type
263263
);
264-
rc = splitcoll.split(&colorp, &hwpool);
264+
rc = chwsplit.split(&colorp, &hwpool);
265265
if (rc != QV_SUCCESS) goto out;
266266
// Split underlying group. Notice the use of colorp here.
267267
rc = parent->group->split(

src/qvi-split.cc

+59-77
Original file line numberDiff line numberDiff line change
@@ -429,26 +429,25 @@ qvi_hwsplit_s::split(void)
429429
return rc;
430430
}
431431

432-
qvi_scope_split_coll_s::qvi_scope_split_coll_s(
433-
qv_scope_t *parent_a,
434-
uint_t split_size_a,
435-
int mycolor_a,
436-
qv_hw_obj_type_t split_at_type_a
437-
) : parent(parent_a)
438-
, mycolor(mycolor_a)
432+
qvi_coll_hwsplit_s::qvi_coll_hwsplit_s(
433+
qv_scope_t *parent,
434+
uint_t npieces,
435+
int color,
436+
qv_hw_obj_type_t split_at_type
437+
) : m_parent(parent)
438+
, m_color(color)
439439
{
440-
const qvi_group_t *const pgroup = parent->group;
441-
if (pgroup->rank() == qvi_scope_split_coll_s::s_rootid) {
442-
hwsplit = qvi_hwsplit_s(
443-
parent, pgroup->size(), split_size_a, split_at_type_a
440+
const qvi_group_t *const pgroup = m_parent->group;
441+
if (pgroup->rank() == qvi_coll_hwsplit_s::s_rootid) {
442+
m_hwsplit = qvi_hwsplit_s(
443+
m_parent, pgroup->size(), npieces, split_at_type
444444
);
445445
}
446446
}
447447

448448
template <typename TYPE>
449449
int
450-
qvi_scope_split_coll_s::scatter_values(
451-
int root,
450+
qvi_coll_hwsplit_s::scatter_values(
452451
const std::vector<TYPE> &values,
453452
TYPE *value
454453
) {
@@ -457,9 +456,9 @@ qvi_scope_split_coll_s::scatter_values(
457456
int rc = QV_SUCCESS;
458457
qvi_bbuff_t *rxbuff = nullptr;
459458

460-
qvi_group_t *const group = parent->group;
459+
qvi_group_t *const group = m_parent->group;
461460
std::vector<qvi_bbuff_t *> txbuffs(0);
462-
if (root == group->rank()) {
461+
if (group->rank() == s_rootid) {
463462
const uint_t group_size = group->size();
464463
txbuffs.resize(group_size);
465464
// Pack the values.
@@ -473,7 +472,7 @@ qvi_scope_split_coll_s::scatter_values(
473472
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
474473
}
475474

476-
rc = group->scatter(txbuffs.data(), root, &rxbuff);
475+
rc = group->scatter(txbuffs.data(), s_rootid, &rxbuff);
477476
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
478477

479478
*value = *(TYPE *)rxbuff->data();
@@ -491,30 +490,28 @@ qvi_scope_split_coll_s::scatter_values(
491490

492491
template <typename TYPE>
493492
int
494-
qvi_scope_split_coll_s::bcast_value(
495-
int root,
493+
qvi_coll_hwsplit_s::bcast_value(
496494
TYPE *value
497495
) {
498496
static_assert(std::is_trivially_copyable<TYPE>::value, "");
499-
qvi_group_t *const group = parent->group;
497+
qvi_group_t *const group = m_parent->group;
500498

501499
std::vector<TYPE> values;
502-
if (root == group->rank()) {
500+
if (group->rank() == s_rootid) {
503501
values.resize(group->size());
504502
std::fill(values.begin(), values.end(), *value);
505503
}
506-
return scatter_values(root, values, value);
504+
return scatter_values(values, value);
507505
}
508506

509507
template <typename TYPE>
510508
int
511-
qvi_scope_split_coll_s::gather_values(
512-
int root,
509+
qvi_coll_hwsplit_s::gather_values(
513510
TYPE invalue,
514511
std::vector<TYPE> &outvals
515512
) {
516513
static_assert(std::is_trivially_copyable<TYPE>::value, "");
517-
qvi_group_t *const group = parent->group;
514+
qvi_group_t *const group = m_parent->group;
518515
const uint_t group_size = group->size();
519516

520517
qvi_bbuff_t *txbuff = nullptr;
@@ -529,18 +526,18 @@ qvi_scope_split_coll_s::gather_values(
529526
// Gather the values to the root.
530527
bool shared = false;
531528
qvi_bbuff_t **bbuffs = nullptr;
532-
rc = group->gather(txbuff, root, &shared, &bbuffs);
529+
rc = group->gather(txbuff, s_rootid, &shared, &bbuffs);
533530
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
534531
// The root fills in the output.
535-
if (group->rank() == root) {
532+
if (group->rank() == s_rootid) {
536533
outvals.resize(group_size);
537534
// Unpack the values.
538535
for (uint_t i = 0; i < group_size; ++i) {
539536
outvals[i] = *(TYPE *)bbuffs[i]->data();
540537
}
541538
}
542539
out:
543-
if (!shared || (shared && (group->rank() == root))) {
540+
if (!shared || (shared && (group->rank() == s_rootid))) {
544541
if (bbuffs) {
545542
for (uint_t i = 0; i < group_size; ++i) {
546543
qvi_bbuff_delete(&bbuffs[i]);
@@ -557,12 +554,11 @@ qvi_scope_split_coll_s::gather_values(
557554
}
558555

559556
int
560-
qvi_scope_split_coll_s::gather_hwpools(
561-
int root,
557+
qvi_coll_hwsplit_s::gather_hwpools(
562558
qvi_hwpool_s *txpool,
563559
std::vector<qvi_hwpool_s *> &rxpools
564560
) {
565-
qvi_group_t *const group = parent->group;
561+
qvi_group_t *const group = m_parent->group;
566562
const uint_t group_size = group->size();
567563
// Pack the hardware pool into a buffer.
568564
qvi_bbuff_t txbuff;
@@ -571,10 +567,10 @@ qvi_scope_split_coll_s::gather_hwpools(
571567
// Gather the values to the root.
572568
bool shared = false;
573569
qvi_bbuff_t **bbuffs = nullptr;
574-
rc = group->gather(&txbuff, root, &shared, &bbuffs);
570+
rc = group->gather(&txbuff, s_rootid, &shared, &bbuffs);
575571
if (rc != QV_SUCCESS) goto out;
576572

577-
if (group->rank() == root) {
573+
if (group->rank() == s_rootid) {
578574
rxpools.resize(group_size);
579575
// Unpack the hwpools.
580576
for (uint_t i = 0; i < group_size; ++i) {
@@ -585,7 +581,7 @@ qvi_scope_split_coll_s::gather_hwpools(
585581
}
586582
}
587583
out:
588-
if (!shared || (shared && (group->rank() == root))) {
584+
if (!shared || (shared && (group->rank() == s_rootid))) {
589585
if (bbuffs) {
590586
for (uint_t i = 0; i < group_size; ++i) {
591587
qvi_bbuff_delete(&bbuffs[i]);
@@ -601,33 +597,27 @@ qvi_scope_split_coll_s::gather_hwpools(
601597
}
602598

603599
int
604-
qvi_scope_split_coll_s::gather(void)
600+
qvi_coll_hwsplit_s::gather(void)
605601
{
606-
int rc = gather_values(
607-
s_rootid, qvi_task_t::mytid(), hwsplit.m_taskids
608-
);
602+
int rc = gather_values(qvi_task_t::mytid(), m_hwsplit.m_taskids);
609603
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
610604
// Note that the result hwpools are copies, so we can modify them freely.
611-
rc = gather_hwpools(
612-
s_rootid, parent->hwpool, hwsplit.m_hwpools
613-
);
605+
rc = gather_hwpools(m_parent->hwpool, m_hwsplit.m_hwpools);
614606
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
615607

616-
rc = gather_values(
617-
s_rootid, mycolor, hwsplit.m_colors
618-
);
608+
rc = gather_values(m_color, m_hwsplit.m_colors);
619609
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
620610

621-
const int myid = parent->group->rank();
622-
const uint_t group_size = parent->group->size();
623-
if (myid == qvi_scope_split_coll_s::s_rootid) {
624-
hwsplit.m_affinities.resize(group_size);
611+
const int myid = m_parent->group->rank();
612+
const uint_t group_size = m_parent->group->size();
613+
if (myid == qvi_coll_hwsplit_s::s_rootid) {
614+
m_hwsplit.m_affinities.resize(group_size);
625615
for (uint_t tid = 0; tid < group_size; ++tid) {
626616
hwloc_cpuset_t cpuset = nullptr;
627-
rc = parent->group->task()->bind_top(&cpuset);
617+
rc = m_parent->group->task()->bind_top(&cpuset);
628618
if (qvi_unlikely(rc != QV_SUCCESS)) break;
629619
//
630-
rc = hwsplit.m_affinities[tid].set(cpuset);
620+
rc = m_hwsplit.m_affinities[tid].set(cpuset);
631621
// Clean up.
632622
qvi_hwloc_bitmap_delete(&cpuset);
633623
if (qvi_unlikely(rc != QV_SUCCESS)) break;
@@ -637,18 +627,17 @@ qvi_scope_split_coll_s::gather(void)
637627
}
638628

639629
int
640-
qvi_scope_split_coll_s::scatter_hwpools(
641-
int root,
630+
qvi_coll_hwsplit_s::scatter_hwpools(
642631
const std::vector<qvi_hwpool_s *> &pools,
643632
qvi_hwpool_s **pool
644633
) {
645634
int rc = QV_SUCCESS;
646635
std::vector<qvi_bbuff_t *> txbuffs(0);
647636
qvi_bbuff_t *rxbuff = nullptr;
648637

649-
qvi_group_t *const group = parent->group;
638+
qvi_group_t *const group = m_parent->group;
650639

651-
if (root == group->rank()) {
640+
if (group->rank() == s_rootid) {
652641
const uint_t group_size = group->size();
653642
txbuffs.resize(group_size);
654643
// Pack the hwpools.
@@ -662,7 +651,7 @@ qvi_scope_split_coll_s::scatter_hwpools(
662651
if (rc != QV_SUCCESS) goto out;
663652
}
664653

665-
rc = group->scatter(txbuffs.data(), root, &rxbuff);
654+
rc = group->scatter(txbuffs.data(), s_rootid, &rxbuff);
666655
if (rc != QV_SUCCESS) goto out;
667656

668657
rc = qvi_bbuff_rmi_unpack(rxbuff->data(), pool);
@@ -678,28 +667,26 @@ qvi_scope_split_coll_s::scatter_hwpools(
678667
}
679668

680669
int
681-
qvi_scope_split_coll_s::scatter(
670+
qvi_coll_hwsplit_s::scatter(
682671
int *colorp,
683672
qvi_hwpool_s **result
684673
) {
685-
const int rc = scatter_values(s_rootid, hwsplit.m_colors, colorp);
674+
const int rc = scatter_values(m_hwsplit.m_colors, colorp);
686675
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
687-
return scatter_hwpools(s_rootid, hwsplit.m_hwpools, result);
676+
return scatter_hwpools(m_hwsplit.m_hwpools, result);
688677
}
689678

690679
int
691-
qvi_scope_split_coll_s::barrier(void)
680+
qvi_coll_hwsplit_s::barrier(void)
692681
{
693-
return parent->group->barrier();
682+
return m_parent->group->barrier();
694683
}
695684

696685
int
697-
qvi_scope_split_coll_s::split(
686+
qvi_coll_hwsplit_s::split(
698687
int *colorp,
699688
qvi_hwpool_s **result
700689
) {
701-
int rc2 = QV_SUCCESS;
702-
const int myid = parent->group->rank();
703690
// First consolidate the provided information, as this is coming from a
704691
// SPMD-like context (e.g., splitting a resource shared by MPI processes).
705692
// In most cases it is easiest to have a single task calculate the split
@@ -708,28 +695,23 @@ qvi_scope_split_coll_s::split(
708695
// whose id is equal to qvi_global_split_t::rootid after gather has
709696
// completed.
710697
int rc = gather();
711-
if (rc != QV_SUCCESS) goto out;
698+
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
712699
// The root does this calculation.
713-
if (myid == s_rootid) {
714-
rc2 = hwsplit.split();
700+
int rc2 = QV_SUCCESS;
701+
if (m_parent->group->rank() == s_rootid) {
702+
rc2 = m_hwsplit.split();
715703
}
716704
// Wait for the split information. Explicitly barrier here in case the
717705
// underlying broadcast implementation polls heavily for completion.
718706
rc = barrier();
719-
if (rc != QV_SUCCESS) goto out;
707+
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
720708
// To avoid hangs in split error paths, share the split rc with everyone.
721-
rc = bcast_value(s_rootid, &rc2);
722-
if (rc != QV_SUCCESS) goto out;
723-
// If the split failed, return the error to all callers.
724-
if (rc2 != QV_SUCCESS) {
725-
rc = rc2;
726-
goto out;
727-
}
709+
rc = bcast_value(&rc2);
710+
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
711+
// If the split failed, return the error to all participants.
712+
if (qvi_unlikely(rc2 != QV_SUCCESS)) return rc2;
728713
// Scatter the results.
729-
rc = scatter(colorp, result);
730-
if (rc != QV_SUCCESS) goto out;
731-
out:
732-
return rc;
714+
return scatter(colorp, result);
733715
}
734716

735717
/*

0 commit comments

Comments
 (0)