Skip to content

Commit 21c9c66

Browse files
authored
Merge pull request #8039 from bosilca/fix/adapt
Fix some corner cases with ADAPT
2 parents eca00a7 + 77eaa5c commit 21c9c66

12 files changed

+632
-612
lines changed

ompi/mca/coll/adapt/Makefile.am

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ sources = \
2424
coll_adapt_inbuf.c \
2525
coll_adapt_inbuf.h \
2626
coll_adapt_item.c \
27-
coll_adapt_item.h
27+
coll_adapt_item.h \
28+
coll_adapt_topocache.c \
29+
coll_adapt_topocache.h
2830

2931
# Make the output library in this directory, and name it either
3032
# mca_<type>_<name>.la (for DSO builds) or libmca_<type>_<name>.la

ompi/mca/coll/adapt/coll_adapt.h

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* of Tennessee Research Foundation. All rights
44
* reserved.
55
* $COPYRIGHT$
6-
*
6+
*
77
* Additional copyrights may follow
8-
*
8+
*
99
* $HEADER$
1010
*/
1111

@@ -25,6 +25,17 @@ BEGIN_C_DECLS
2525

2626
typedef struct mca_coll_adapt_module_t mca_coll_adapt_module_t;
2727

28+
typedef enum {
29+
OMPI_COLL_ADAPT_ALGORITHM_TUNED = 0,
30+
OMPI_COLL_ADAPT_ALGORITHM_BINOMIAL,
31+
OMPI_COLL_ADAPT_ALGORITHM_IN_ORDER_BINOMIAL,
32+
OMPI_COLL_ADAPT_ALGORITHM_BINARY,
33+
OMPI_COLL_ADAPT_ALGORITHM_PIPELINE,
34+
OMPI_COLL_ADAPT_ALGORITHM_CHAIN,
35+
OMPI_COLL_ADAPT_ALGORITHM_LINEAR,
36+
OMPI_COLL_ADAPT_ALGORITHM_COUNT /* number of algorithms, keep last! */
37+
} ompi_coll_adapt_algorithm_t;
38+
2839
/*
2940
* Structure to hold the adapt coll component. First it holds the
3041
* base coll component, and then holds a bunch of
@@ -56,6 +67,7 @@ typedef struct mca_coll_adapt_component_t {
5667
size_t adapt_ibcast_segment_size;
5768
int adapt_ibcast_max_send_requests;
5869
int adapt_ibcast_max_recv_requests;
70+
bool adapt_ibcast_synchronous_send;
5971
/* Bcast free list */
6072
opal_free_list_t *adapt_ibcast_context_free_list;
6173

@@ -67,17 +79,54 @@ typedef struct mca_coll_adapt_component_t {
6779
int adapt_inbuf_free_list_min;
6880
int adapt_inbuf_free_list_max;
6981
int adapt_inbuf_free_list_inc;
82+
bool adapt_ireduce_synchronous_send;
7083

7184
/* Reduce free list */
7285
opal_free_list_t *adapt_ireduce_context_free_list;
7386

7487
} mca_coll_adapt_component_t;
7588

89+
/*
90+
* Structure used to store what is necessary for the collective operations
91+
* routines in case of fallback.
92+
*/
93+
typedef struct mca_coll_adapt_collective_fallback_s {
94+
union {
95+
mca_coll_base_module_reduce_fn_t reduce;
96+
mca_coll_base_module_ireduce_fn_t ireduce;
97+
} previous_routine;
98+
mca_coll_base_module_t *previous_module;
99+
} mca_coll_adapt_collective_fallback_t;
100+
101+
102+
typedef enum mca_coll_adapt_colltype {
103+
ADAPT_REDUCE = 0,
104+
ADAPT_IREDUCE = 1,
105+
ADAPT_COLLCOUNT
106+
} mca_coll_adapt_colltype_t;
107+
108+
/*
109+
* Some defines to stick to the naming used in the other components in terms of
110+
* fallback routines
111+
*/
112+
#define previous_reduce previous_routines[ADAPT_REDUCE].previous_routine.reduce
113+
#define previous_ireduce previous_routines[ADAPT_IREDUCE].previous_routine.ireduce
114+
115+
#define previous_reduce_module previous_routines[ADAPT_REDUCE].previous_module
116+
#define previous_ireduce_module previous_routines[ADAPT_IREDUCE].previous_module
117+
118+
76119
/* Coll adapt module per communicator*/
77120
struct mca_coll_adapt_module_t {
78121
/* Base module */
79122
mca_coll_base_module_t super;
80123

124+
/* To be able to fallback when the cases are not supported */
125+
struct mca_coll_adapt_collective_fallback_s previous_routines[ADAPT_COLLCOUNT];
126+
127+
/* cached topologies */
128+
opal_list_t *topo_cache;
129+
81130
/* Whether this module has been lazily initialized or not yet */
82131
bool adapt_enabled;
83132
};

ompi/mca/coll/adapt/coll_adapt_context.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,31 @@
33
* of Tennessee Research Foundation. All rights
44
* reserved.
55
* $COPYRIGHT$
6-
*
6+
*
77
* Additional copyrights may follow
8-
*
8+
*
99
* $HEADER$
1010
*/
1111

1212
#include "ompi/mca/coll/coll.h"
1313
#include "coll_adapt_context.h"
1414

1515

16+
static void adapt_constant_reduce_context_construct(ompi_coll_adapt_constant_reduce_context_t *context)
17+
{
18+
OBJ_CONSTRUCT(&context->recv_list, opal_list_t);
19+
OBJ_CONSTRUCT(&context->mutex_recv_list, opal_mutex_t);
20+
OBJ_CONSTRUCT(&context->inbuf_list, opal_free_list_t);
21+
}
22+
23+
static void adapt_constant_reduce_context_destruct(ompi_coll_adapt_constant_reduce_context_t *context)
24+
{
25+
OBJ_DESTRUCT(&context->mutex_recv_list);
26+
OBJ_DESTRUCT(&context->recv_list);
27+
OBJ_DESTRUCT(&context->inbuf_list);
28+
}
29+
30+
1631
OBJ_CLASS_INSTANCE(ompi_coll_adapt_bcast_context_t, opal_free_list_item_t,
1732
NULL, NULL);
1833

@@ -23,4 +38,5 @@ OBJ_CLASS_INSTANCE(ompi_coll_adapt_reduce_context_t, opal_free_list_item_t,
2338
NULL, NULL);
2439

2540
OBJ_CLASS_INSTANCE(ompi_coll_adapt_constant_reduce_context_t, opal_object_t,
26-
NULL, NULL);
41+
&adapt_constant_reduce_context_construct,
42+
&adapt_constant_reduce_context_destruct);

ompi/mca/coll/adapt/coll_adapt_context.h

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* of Tennessee Research Foundation. All rights
44
* reserved.
55
* $COPYRIGHT$
6-
*
6+
*
77
* Additional copyrights may follow
8-
*
8+
*
99
* $HEADER$
1010
*/
1111

@@ -74,41 +74,35 @@ struct ompi_coll_adapt_constant_reduce_context_s {
7474
/* Increment of each segment */
7575
int segment_increment;
7676
int num_segs;
77-
ompi_request_t *request;
7877
int rank;
78+
int root;
79+
/* The distance between the address of inbuf->buff and the address of inbuf */
80+
int distance;
81+
int ireduce_tag;
82+
/* How many sends are posted but not finished */
83+
int32_t ongoing_send;
7984
/* Length of the fragment array, which is the number of recevied segments */
8085
int32_t num_recv_segs;
8186
/* Number of sent segments */
8287
int32_t num_sent_segs;
8388
/* Next seg need to be received for every children */
84-
opal_atomic_int32_t *next_recv_segs;
85-
/* Mutex to protect recv_list */
86-
opal_mutex_t *mutex_recv_list;
87-
/* Mutex to protect num_recv_segs */
88-
opal_mutex_t *mutex_num_recv_segs;
89-
/* Mutex to protect num_sent */
90-
opal_mutex_t *mutex_num_sent;
89+
int32_t *next_recv_segs;
9190
/* Mutex to protect each segment when do the reduce op */
9291
opal_mutex_t *mutex_op_list;
9392
/* Reduce operation */
9493
ompi_op_t *op;
9594
ompi_coll_tree_t *tree;
9695
/* Accumulate buff */
9796
char **accumbuf;
98-
/* inbuf list address of accumbuf */
99-
ompi_coll_adapt_inbuf_t ** accumbuf_to_inbuf;
100-
opal_free_list_t *inbuf_list;
101-
/* A list to store the segments which are received and not yet be sent */
102-
opal_list_t *recv_list;
10397
ptrdiff_t lower_bound;
104-
/* How many sends are posted but not finished */
105-
opal_atomic_int32_t ongoing_send;
10698
char *sbuf;
10799
char *rbuf;
108-
int root;
109-
/* The distance between the address of inbuf->buff and the address of inbuf */
110-
int distance;
111-
int ireduce_tag;
100+
opal_free_list_t inbuf_list;
101+
/* Mutex to protect recv_list */
102+
opal_mutex_t mutex_recv_list;
103+
/* A list to store the segments which are received and not yet be sent */
104+
opal_list_t recv_list;
105+
ompi_request_t *request;
112106
};
113107

114108
typedef struct ompi_coll_adapt_constant_reduce_context_s ompi_coll_adapt_constant_reduce_context_t;
@@ -123,7 +117,7 @@ typedef int (*ompi_coll_adapt_reduce_cuda_callback_fn_t) (ompi_coll_adapt_reduce
123117
struct ompi_coll_adapt_reduce_context_s {
124118
opal_free_list_item_t super;
125119
char *buff;
126-
int frag_id;
120+
int seg_index;
127121
int child_id;
128122
int peer;
129123
ompi_coll_adapt_constant_reduce_context_t *con;

0 commit comments

Comments
 (0)