Skip to content

Commit 668c122

Browse files
pthread gather/scatter/split support MkI (#273)
Signed-off-by: Guillaume Mercier <[email protected]>
1 parent 4e96f3a commit 668c122

25 files changed

+351
-70
lines changed

include/quo-vadis-pthread.h

+25
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@
2727
extern "C" {
2828
#endif
2929

30+
/**
31+
* Mapping policies types.
32+
*/
33+
typedef enum qv_policy_s {
34+
QV_POLICY_PACKED = 1,
35+
QV_POLICY_COMPACT = 1,
36+
QV_POLICY_CLOSE = 1,
37+
QV_POLICY_SPREAD = 2,
38+
QV_POLICY_DISTRIBUTE = 3,
39+
QV_POLICY_ALTERNATE = 3,
40+
QV_POLICY_CORESFIRST = 3,
41+
QV_POLICY_SCATTER = 4,
42+
QV_POLICY_CHOOSE = 5,
43+
} qv_policy_t;
44+
3045
/**
3146
* Similar to pthread_create(3).
3247
*/
@@ -66,6 +81,16 @@ qv_pthread_scopes_free(
6681
qv_scope_t **scopes
6782
);
6883

84+
/**
85+
* Fills color array used in qv_pthread_scope_split*.
86+
*/
87+
int
88+
qv_pthread_colors_fill(
89+
int *color_array,
90+
int array_size,
91+
qv_policy_t policy
92+
);
93+
6994
#ifdef __cplusplus
7095
}
7196
#endif

src/quo-vadis-pthread.cc

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* -*- Mode: C++; c-basic-offset:4; indent-tabs-mode:nil -*- */
2-
/*
2+
/*qv_policy_t
33
* Copyright (c) 2022-2024 Triad National Security, LLC
44
* All rights reserved.
55
*
@@ -116,7 +116,7 @@ qv_pthread_create(
116116
return ENOMEM;
117117
}
118118
return pthread_create(
119-
thread, attr, qvi_pthread_group_s::call_first_from_pthread_create, cargs
119+
thread, attr, qvi_pthread_group::call_first_from_pthread_create, cargs
120120
);
121121
}
122122

@@ -135,6 +135,16 @@ qv_pthread_scopes_free(
135135
qvi_catch_and_return();
136136
}
137137

138+
int
139+
qv_pthread_colors_fill(
140+
int *,//color_array,
141+
int, // array_size,
142+
qv_policy_t //policy
143+
){
144+
//TODO(GM) implement
145+
return QV_ERR_NOT_SUPPORTED;
146+
}
147+
138148
/*
139149
* vim: ft=cpp ts=4 sts=4 sw=4 expandtab
140150
*/

src/quo-vadis.cc

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ qv_scope_split(
179179
// We use the sentinel value QV_HW_OBJ_LAST to differentiate between
180180
// calls from split() and split_at(). Since this call doesn't have a
181181
// hardware type argument, we use QV_HW_OBJ_LAST as the hardware type.
182+
// return
182183
return scope->split(npieces, color, QV_HW_OBJ_LAST, subscope);
183184
}
184185
qvi_catch_and_return();

src/qvi-bbuff.cc

+8
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ qvi_bbuff_dup(
112112
return qvi_dup(src, buff);
113113
}
114114

115+
int
116+
qvi_bbuff_copy(
117+
const qvi_bbuff &src,
118+
qvi_bbuff *buff
119+
) {
120+
return qvi_copy(src, buff);
121+
}
122+
115123
void
116124
qvi_bbuff_delete(
117125
qvi_bbuff **buff

src/qvi-bbuff.h

+14
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,25 @@ qvi_bbuff_dup(
7373
qvi_bbuff **buff
7474
);
7575

76+
int
77+
qvi_bbuff_copy(
78+
const qvi_bbuff &src,
79+
qvi_bbuff *buff
80+
);
81+
7682
void
7783
qvi_bbuff_delete(
7884
qvi_bbuff **buff
7985
);
8086

87+
enum qvi_alloc_s {
88+
ALLOC_SHARED = 0,
89+
ALLOC_SHARED_GLOBAL,
90+
ALLOC_PRIVATE,
91+
};
92+
93+
typedef enum qvi_alloc_s qvi_alloc_type_t;
94+
8195
#endif
8296

8397
/*

src/qvi-common.h

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <chrono>
4949
#include <map>
5050
#include <mutex>
51+
#include <condition_variable>
5152
#include <new>
5253
#include <numeric>
5354
#include <set>

src/qvi-group-mpi.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "qvi-common.h"
2121
#include "qvi-group.h"
2222
#include "qvi-mpi.h"
23+
#include "qvi-bbuff.h"
2324

2425
struct qvi_group_mpi : public qvi_group {
2526
protected:
@@ -84,7 +85,7 @@ struct qvi_group_mpi : public qvi_group {
8485
gather(
8586
qvi_bbuff *txbuff,
8687
int root,
87-
bool *shared,
88+
qvi_alloc_type_t *shared,
8889
qvi_bbuff ***rxbuffs
8990
) {
9091
return qvi_mpi_group_gather_bbuffs(

src/qvi-group-omp.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "qvi-common.h"
2424
#include "qvi-group.h"
2525
#include "qvi-omp.h"
26+
#include "qvi-bbuff.h"
2627

2728
struct qvi_group_omp : public qvi_group {
2829
private:
@@ -90,7 +91,7 @@ struct qvi_group_omp : public qvi_group {
9091
gather(
9192
qvi_bbuff *txbuff,
9293
int root,
93-
bool *shared,
94+
qvi_alloc_type_t *shared,
9495
qvi_bbuff ***rxbuffs
9596
) {
9697
return m_ompgroup->gather(txbuff, root, shared, rxbuffs);

src/qvi-group-process.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "qvi-common.h"
1818
#include "qvi-group.h"
1919
#include "qvi-process.h"
20+
#include "qvi-bbuff.h"
2021

2122
struct qvi_group_process : public qvi_group {
2223
protected:
@@ -85,7 +86,7 @@ struct qvi_group_process : public qvi_group {
8586
gather(
8687
qvi_bbuff *txbuff,
8788
int root,
88-
bool *shared,
89+
qvi_alloc_type_t *shared,
8990
qvi_bbuff ***rxbuffs
9091
) {
9192
return qvi_process_group_gather_bbuffs(

src/qvi-group-pthread.cc

+15-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
qvi_group_pthread::qvi_group_pthread(
1818
int group_size
1919
) {
20-
const int rc = qvi_new(&thgroup, group_size);
20+
const int rc = qvi_new(&thgroup, group_size, 0);
2121
if (qvi_unlikely(rc != QV_SUCCESS)) throw qvi_runtime_error();
2222
}
2323

@@ -36,12 +36,21 @@ qvi_group_pthread::self(
3636

3737
int
3838
qvi_group_pthread::split(
39-
int,
40-
int,
41-
qvi_group **
39+
int color ,
40+
int key,
41+
qvi_group ** child
4242
) {
43-
// TODO(skg)
44-
return QV_ERR_NOT_SUPPORTED;
43+
qvi_group_pthread *ichild = nullptr;
44+
int rc = qvi_new(&ichild);
45+
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
46+
47+
rc = thgroup->split(color, key, &ichild->thgroup);
48+
out:
49+
if (qvi_unlikely(rc != QV_SUCCESS)) {
50+
qvi_delete(&ichild);
51+
}
52+
*child = ichild;
53+
return rc;
4554
}
4655

4756
/*

src/qvi-group-pthread.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
#include "qvi-common.h"
1818
#include "qvi-group.h"
1919
#include "qvi-pthread.h"
20+
#include "qvi-bbuff.h"
2021

2122
struct qvi_group_pthread : public qvi_group {
2223
/** Underlying group instance. */
2324
qvi_pthread_group_t *thgroup = nullptr;
2425
/** Constructor. */
25-
qvi_group_pthread(void) = delete;
26+
qvi_group_pthread(void) = default;
2627
/** Constructor. */
2728
qvi_group_pthread(
2829
int group_size
@@ -87,7 +88,7 @@ struct qvi_group_pthread : public qvi_group {
8788
gather(
8889
qvi_bbuff *txbuff,
8990
int root,
90-
bool *shared,
91+
qvi_alloc_type_t *shared,
9192
qvi_bbuff ***rxbuffs
9293
) {
9394
return thgroup->gather(

src/qvi-group.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "qvi-common.h"
2121
#include "qvi-utils.h"
22+
#include "qvi-bbuff.h"
2223

2324
/** Group ID type. */
2425
using qvi_group_id_t = uint64_t;
@@ -82,7 +83,7 @@ struct qvi_group : qvi_refc {
8283
gather(
8384
qvi_bbuff *txbuff,
8485
int root,
85-
bool *shared,
86+
qvi_alloc_type_t *shared,
8687
qvi_bbuff ***rxbuffs
8788
) = 0;
8889
/** Scatters bbuffs from specified root. */

src/qvi-hwsplit.cc

+10-6
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,9 @@ qvi_hwsplit_coll::scatter_values(
641641
}
642642

643643
rc = group->scatter(txbuffs.data(), rootid, &rxbuff);
644-
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
644+
if (qvi_unlikely(rc != QV_SUCCESS)) {
645+
goto out;
646+
}
645647

646648
*value = *(TYPE *)rxbuff->data();
647649
out:
@@ -692,7 +694,7 @@ qvi_hwsplit_coll::gather_values(
692694
return rc;
693695
}
694696
// Gather the values to the root.
695-
bool shared = false;
697+
qvi_alloc_type_t shared = ALLOC_PRIVATE;
696698
qvi_bbuff **bbuffs = nullptr;
697699
rc = group->gather(txbuff, rootid, &shared, &bbuffs);
698700
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
@@ -705,14 +707,15 @@ qvi_hwsplit_coll::gather_values(
705707
}
706708
}
707709
out:
708-
if (!shared || (shared && (group->rank() == rootid))) {
710+
if ((ALLOC_PRIVATE == shared) || ((ALLOC_SHARED == shared) && (group->rank() == rootid))) {
709711
if (bbuffs) {
710-
for (uint_t i = 0; i < group_size; ++i) {
712+
for (uint_t i = 0; i < group_size; ++i) {
711713
qvi_bbuff_delete(&bbuffs[i]);
712714
}
713715
delete[] bbuffs;
714716
}
715717
}
718+
716719
qvi_bbuff_delete(&txbuff);
717720
if (qvi_unlikely(rc != QV_SUCCESS)) {
718721
// If something went wrong, just zero-initialize the values.
@@ -733,7 +736,7 @@ qvi_hwsplit_coll::gather_hwpools(
733736
int rc = txpool->packinto(&txbuff);
734737
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
735738
// Gather the values to the root.
736-
bool shared = false;
739+
qvi_alloc_type_t shared = ALLOC_PRIVATE;
737740
qvi_bbuff **bbuffs = nullptr;
738741
rc = group->gather(&txbuff, rootid, &shared, &bbuffs);
739742
if (rc != QV_SUCCESS) goto out;
@@ -749,14 +752,15 @@ qvi_hwsplit_coll::gather_hwpools(
749752
}
750753
}
751754
out:
752-
if (!shared || (shared && (group->rank() == rootid))) {
755+
if ((ALLOC_PRIVATE == shared) || ((ALLOC_SHARED == shared) && (group->rank() == rootid))) {
753756
if (bbuffs) {
754757
for (uint_t i = 0; i < group_size; ++i) {
755758
qvi_bbuff_delete(&bbuffs[i]);
756759
}
757760
delete[] bbuffs;
758761
}
759762
}
763+
760764
if (rc != QV_SUCCESS) {
761765
// If something went wrong, just zero-initialize the pools.
762766
rxpools = {};

src/qvi-mpi.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ qvi_mpi_group_gather_bbuffs(
365365
qvi_mpi_group_t *group,
366366
qvi_bbuff *txbuff,
367367
int root,
368-
bool *shared_alloc,
368+
qvi_alloc_type_t *shared_alloc,
369369
qvi_bbuff ***rxbuffs
370370
) {
371371
const int send_count = (int)txbuff->size();
@@ -434,7 +434,7 @@ qvi_mpi_group_gather_bbuffs(
434434
bbuffs = nullptr;
435435
}
436436
*rxbuffs = bbuffs;
437-
*shared_alloc = false;
437+
*shared_alloc = ALLOC_PRIVATE;
438438
return rc;
439439
}
440440

src/qvi-mpi.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "qvi-common.h"
2121
#include "qvi-group.h"
2222
#include "quo-vadis-mpi.h" // IWYU pragma: keep
23+
#include "qvi-bbuff.h"
2324

2425
// Forward declarations.
2526
struct qvi_mpi_s;
@@ -151,7 +152,7 @@ qvi_mpi_group_gather_bbuffs(
151152
qvi_mpi_group_t *group,
152153
qvi_bbuff *txbuff,
153154
int root,
154-
bool *shared_alloc,
155+
qvi_alloc_type_t *shared_alloc,
155156
qvi_bbuff ***rxbuffs
156157
);
157158

0 commit comments

Comments
 (0)