Skip to content

Commit dbcc458

Browse files
committed
Redo the non contiguous datatype part in SOLO module.
Known problems: 1. bcast: has bug if a datatype is from MPI_Bottom 2. reduce \ allreduce : fix or remove the non contiguous support.
1 parent 0892890 commit dbcc458

5 files changed

Lines changed: 53 additions & 556 deletions

File tree

ompi/mca/coll/solo/coll_solo.h

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@ typedef struct mca_coll_solo_module_t {
5959
/* Whether this module has been lazily initialized or not yet */
6060
bool enabled;
6161

62-
/**
63-
* osc alrogithms attach memory blocks to this bynamic window and use it to perform one-sided
64-
* communications.
65-
*/
66-
MPI_Win dynamic_win;
67-
6862
/**
6963
* This window is created by ompi_win_allocate_shared such that each process contains a shared
7064
* memory data buffer, and this data buffer is divided into two parts - ctrl_bufs and data_bufs.
@@ -101,18 +95,6 @@ mca_coll_base_module_t *mca_coll_solo_comm_query(struct ompi_communicator_t *com
10195
/* Lazily enable a module (since it involves expensive memory allocation, etc.) */
10296
int mca_coll_solo_lazy_enable(mca_coll_base_module_t * module, struct ompi_communicator_t *comm);
10397

104-
/* Attach a memory block to the dynamic_win of a communicator */
105-
char **mca_coll_solo_attach_buf(mca_coll_solo_module_t * solo_module,
106-
struct ompi_communicator_t *comm,
107-
char *local_buf,
108-
size_t local_buf_size);
109-
110-
/* Detach a memory block from the dynamic_win of a communicator */
111-
void mca_coll_solo_detach_buf(mca_coll_solo_module_t * solo_module,
112-
struct ompi_communicator_t *comm,
113-
char *local_buf,
114-
char ***attached_bufs);
115-
11698
/* Setup and initialize the static_win of a communicator */
11799
void mca_coll_solo_setup_static_win(mca_coll_solo_module_t *solo_module,
118100
struct ompi_communicator_t *comm,
@@ -135,26 +117,13 @@ int mca_coll_solo_bcast_linear_intra_memcpy(void *buff, int count,
135117
struct ompi_communicator_t *comm,
136118
mca_coll_base_module_t * module);
137119

138-
int mca_coll_solo_bcast_linear_intra_osc(void *buff, int count,
139-
struct ompi_datatype_t *dtype,
140-
int root,
141-
struct ompi_communicator_t *comm,
142-
mca_coll_base_module_t * module);
143-
144120
int mca_coll_solo_bcast_pipeline_intra_memcpy(void *buff, int count,
145121
struct ompi_datatype_t *dtype,
146122
int root,
147123
struct ompi_communicator_t *comm,
148124
mca_coll_base_module_t * module,
149125
size_t seg_size);
150126

151-
int mca_coll_solo_bcast_pipeline_intra_osc(void *buff, int count,
152-
struct ompi_datatype_t *dtype,
153-
int root,
154-
struct ompi_communicator_t *comm,
155-
mca_coll_base_module_t * module,
156-
size_t seg_size);
157-
158127
/* MPI_Reduce algorithms */
159128
int mca_coll_solo_reduce_intra(const void *sbuf, void *rbuf, int count,
160129
struct ompi_datatype_t *dtype,
@@ -163,24 +132,13 @@ int mca_coll_solo_reduce_intra(const void *sbuf, void *rbuf, int count,
163132
struct ompi_communicator_t *comm,
164133
mca_coll_base_module_t * module);
165134

166-
int mca_coll_solo_reduce_ring_intra(const void *sbuf, void *rbuf, int count,
167-
struct ompi_datatype_t *dtype,
168-
struct ompi_op_t *op, int root,
169-
struct ompi_communicator_t *comm,
170-
mca_coll_base_module_t * module);
171-
172135
int mca_coll_solo_reduce_ring_intra_memcpy(const void *sbuf, void *rbuf, int count,
173136
struct ompi_datatype_t *dtype,
174137
struct ompi_op_t *op,
175138
int root,
176139
struct ompi_communicator_t
177140
*comm, mca_coll_base_module_t * module);
178141

179-
int mca_coll_solo_reduce_ring_intra_osc(const void *sbuf, void *rbuf, int count,
180-
struct ompi_datatype_t *dtype,
181-
struct ompi_op_t *op, int root,
182-
struct ompi_communicator_t *comm,
183-
mca_coll_base_module_t * module);
184142

185143
/* MPI_Allreduce algorithms */
186144
int mca_coll_solo_allreduce_intra(const void *sbuf, void *rbuf, int count,
@@ -195,10 +153,39 @@ int mca_coll_solo_allreduce_ring_intra_memcpy(const void *sbuf, void *rbuf, int
195153
struct ompi_communicator_t *comm,
196154
mca_coll_base_module_t * module);
197155

198-
int mca_coll_solo_allreduce_ring_intra_osc(const void *sbuf, void *rbuf, int count,
199-
struct ompi_datatype_t *dtype,
200-
struct ompi_op_t *op,
201-
struct ompi_communicator_t *comm,
202-
mca_coll_base_module_t * module);
156+
157+
/* Solo pack to shared memory */
158+
static inline void mca_coll_solo_pack_to_shared(void *local_buf, void *shared_buf, struct ompi_datatype_t *dtype, int count, ptrdiff_t extent) {
159+
if (ompi_datatype_is_predefined(dtype)) {
160+
memcpy((char *) shared_buf, (char *) local_buf, count * extent);
161+
}
162+
else {
163+
MPI_Aint pos = 0;
164+
ompi_datatype_pack_external("external32", local_buf, count, dtype, shared_buf, count * extent, &pos);
165+
}
166+
}
167+
168+
/* Solo unpack from shared memory */
169+
static inline void mca_coll_solo_unpack_from_shared(void *local_buf, void *shared_buf, struct ompi_datatype_t *dtype, int count, ptrdiff_t extent) {
170+
if (ompi_datatype_is_predefined(dtype)) {
171+
memcpy((char *) local_buf, (char *) shared_buf, count * extent);
172+
}
173+
else {
174+
MPI_Aint pos = 0;
175+
ompi_datatype_unpack_external("external32", shared_buf, count * extent, &pos, local_buf, count, dtype);
176+
}
177+
}
178+
179+
/* Solo copy from source to target */
180+
static inline void mca_coll_solo_copy(void *source, void *target, struct ompi_datatype_t *dtype, int count, ptrdiff_t extent) {
181+
if (ompi_datatype_is_predefined(dtype)) {
182+
memcpy(target, source, count * extent);
183+
}
184+
else {
185+
ompi_datatype_copy_content_same_ddt(dtype, count, target, source);
186+
}
187+
return;
188+
}
189+
203190
END_C_DECLS
204191
#endif /* MCA_COLL_SOLO_EXPORT_H */

ompi/mca/coll/solo/coll_solo_allreduce.c

Lines changed: 5 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,7 @@ int mca_coll_solo_allreduce_intra(const void *sbuf, void *rbuf,
1818
struct ompi_communicator_t *comm,
1919
mca_coll_base_module_t * module)
2020
{
21-
if (ompi_datatype_is_contiguous_memory_layout(dtype, count)) {
22-
mca_coll_solo_allreduce_ring_intra_memcpy(sbuf, rbuf, count, dtype, op, comm, module);
23-
}
24-
else {
25-
mca_coll_solo_allreduce_ring_intra_osc(sbuf, rbuf, count, dtype, op, comm, module);
26-
}
27-
return OMPI_SUCCESS;
28-
21+
return mca_coll_solo_allreduce_ring_intra_memcpy(sbuf, rbuf, count, dtype, op, comm, module);
2922
}
3023

3124

@@ -91,10 +84,7 @@ int mca_coll_solo_allreduce_ring_intra_memcpy(const void *sbuf, void *rbuf, int
9184
}
9285
} else {
9386
/* For the messages which are greater than mpool_large_block_size*np, invoke this reduce multiple times */
94-
int seg_count = count;
95-
size_t typelng;
96-
ompi_datatype_type_size(dtype, &typelng);
97-
COLL_BASE_COMPUTED_SEGCOUNT(mca_coll_solo_component.mpool_large_block_size, typelng, seg_count);
87+
int seg_count = mca_coll_solo_component.mpool_large_block_size / extent;
9888
int num_segments = (count + seg_count - 1) / seg_count;
9989
int last_count = count - seg_count * (num_segments - 1);
10090
for (int i = 0; i < num_segments; i++) {
@@ -122,7 +112,7 @@ int mca_coll_solo_allreduce_ring_intra_memcpy(const void *sbuf, void *rbuf, int
122112
}
123113
/* At first iteration, copy local data to the solo data buffer */
124114
if (cur == rank) {
125-
memcpy(data_bufs[cur], (char *) sbuf + cur * l_seg_count * extent, seg_count * extent);
115+
mca_coll_solo_copy((void *) ((char *) sbuf + cur * l_seg_count * extent), (void *) data_bufs[cur], dtype, seg_count, extent);
126116
mac_coll_solo_barrier_intra(comm, module);
127117

128118
}
@@ -147,7 +137,7 @@ int mca_coll_solo_allreduce_ring_intra_memcpy(const void *sbuf, void *rbuf, int
147137
} else {
148138
seg_count = count - i * l_seg_count;
149139
}
150-
memcpy((char *) c, data_bufs[i], seg_count * extent);
140+
mca_coll_solo_copy((void *) data_bufs[i], (void *) c, dtype, seg_count, extent);
151141
c = c + seg_count * extent;
152142
}
153143
mac_coll_solo_barrier_intra(comm, module);
@@ -167,127 +157,4 @@ int mca_coll_solo_allreduce_ring_intra_memcpy(const void *sbuf, void *rbuf, int
167157

168158
}
169159
return OMPI_SUCCESS;
170-
}
171-
172-
int mca_coll_solo_allreduce_ring_intra_osc(const void *sbuf, void *rbuf, int count,
173-
struct ompi_datatype_t *dtype,
174-
struct ompi_op_t *op,
175-
struct ompi_communicator_t *comm,
176-
mca_coll_base_module_t * module)
177-
{
178-
mca_coll_solo_module_t *solo_module = (mca_coll_solo_module_t *) module;
179-
int size = ompi_comm_size(comm);
180-
int rank = ompi_comm_rank(comm);
181-
int i;
182-
ptrdiff_t extent, lower_bound;
183-
ompi_datatype_get_extent(dtype, &lower_bound, &extent);
184-
185-
/* Enable solo module if necessary */
186-
if (!solo_module->enabled) {
187-
mca_coll_solo_lazy_enable(module, comm);
188-
}
189-
190-
/* Set up segment count */
191-
int seg_count, l_seg_count;
192-
seg_count = count / size;
193-
l_seg_count = seg_count;
194-
if (rank == size - 1) {
195-
seg_count = count - rank * l_seg_count;
196-
}
197-
198-
char **data_bufs = NULL;
199-
int id;
200-
MPI_Win cur_win;
201-
char *local_buf = NULL;
202-
if ((size_t) l_seg_count * extent <= mca_coll_solo_component.static_block_size) {
203-
data_bufs = (char **) malloc(sizeof(char *) * size);
204-
for (i = 0; i < size; i++) {
205-
data_bufs[i] = (char *) 0 + 4 * opal_cache_line_size;
206-
}
207-
cur_win = solo_module->static_win;
208-
} else if ((size_t) l_seg_count * extent <= mca_coll_solo_component.mpool_large_block_size) {
209-
id = mca_coll_solo_mpool_request(mca_coll_solo_component.solo_mpool, l_seg_count * extent);
210-
local_buf =
211-
mca_coll_solo_mpool_calculate(mca_coll_solo_component.solo_mpool, id,
212-
l_seg_count * extent);
213-
data_bufs = mca_coll_solo_attach_buf(solo_module, comm, local_buf, l_seg_count * extent);
214-
cur_win = solo_module->dynamic_win;
215-
} else {
216-
/* For the messages which are greater than mpool_large_block_size*np, invoke this reduce multiple times */
217-
int seg_count = count;
218-
size_t typelng;
219-
ompi_datatype_type_size(dtype, &typelng);
220-
COLL_BASE_COMPUTED_SEGCOUNT(mca_coll_solo_component.mpool_large_block_size, typelng, seg_count);
221-
int num_segments = (count + seg_count - 1) / seg_count;
222-
int last_count = count - seg_count * (num_segments - 1);
223-
for (int i = 0; i < num_segments; i++) {
224-
char *temp_sbuf = (char *)sbuf + seg_count * extent * i;
225-
char *temp_rbuf = (char *)rbuf + seg_count * extent * i;
226-
int temp_count = seg_count;
227-
if (i == num_segments - 1) {
228-
temp_count = last_count;
229-
}
230-
mca_coll_solo_allreduce_ring_intra_osc(temp_sbuf, temp_rbuf, temp_count, dtype, op,
231-
comm, module);
232-
}
233-
return MPI_SUCCESS;
234-
}
235-
236-
*(int *) (solo_module->ctrl_bufs[rank]) = rank;
237-
mac_coll_solo_barrier_intra(comm, module);
238-
239-
int cur = rank;
240-
for (i = 0; i < size; i++) {
241-
if (cur != size - 1) {
242-
seg_count = l_seg_count;
243-
} else {
244-
seg_count = count - cur * l_seg_count;
245-
}
246-
/* At first iteration, copy local data to the solo data buffer */
247-
if (cur == rank) {
248-
cur_win->w_osc_module->osc_fence(0, cur_win);
249-
cur_win->w_osc_module->osc_put((char *) sbuf +
250-
cur * l_seg_count * extent,
251-
seg_count, dtype, cur,
252-
(ptrdiff_t) data_bufs[cur], seg_count, dtype, cur_win);
253-
cur_win->w_osc_module->osc_fence(0, cur_win);
254-
}
255-
/* For other iterations, do operations on the solo data buffer */
256-
else {
257-
cur_win->w_osc_module->osc_accumulate((char *) sbuf +
258-
cur * l_seg_count *
259-
extent, seg_count, dtype, cur, (ptrdiff_t)
260-
data_bufs[cur], seg_count, dtype, op, cur_win);
261-
cur_win->w_osc_module->osc_fence(0, cur_win);
262-
}
263-
cur = (cur - 1 + size) % size;
264-
*(int *) (solo_module->ctrl_bufs[rank]) =
265-
(*(int *) (solo_module->ctrl_bufs[rank]) + 1) % size;
266-
mac_coll_solo_barrier_intra(comm, module);
267-
268-
}
269-
/* At last, all the processes copies data from the solo data buffer */
270-
char *c;
271-
c = rbuf;
272-
for (i = 0; i < size; i++) {
273-
if (i != size - 1) {
274-
seg_count = l_seg_count;
275-
} else {
276-
seg_count = count - i * l_seg_count;
277-
}
278-
cur_win->w_osc_module->osc_get(c, seg_count, dtype, i,
279-
(ptrdiff_t) data_bufs[i], seg_count, dtype, cur_win);
280-
c = c + seg_count * extent;
281-
}
282-
cur_win->w_osc_module->osc_fence(0, cur_win);
283-
if ((size_t) l_seg_count * extent <= mca_coll_solo_component.static_block_size) {
284-
if (data_bufs != NULL) {
285-
free(data_bufs);
286-
data_bufs = NULL;
287-
}
288-
} else if ((size_t) l_seg_count * extent <= mca_coll_solo_component.mpool_large_block_size) {
289-
mca_coll_solo_detach_buf(solo_module, comm, local_buf, &data_bufs);
290-
mca_coll_solo_mpool_return(mca_coll_solo_component.solo_mpool, id, l_seg_count * extent);
291-
}
292-
return OMPI_SUCCESS;
293-
}
160+
}

0 commit comments

Comments
 (0)