Skip to content

Commit 5bc215a

Browse files
authored
Merge pull request #10627 from jjhursey/patch-dep-send
MPI-4: Issue warning when MPI_Cancel called for non blocking send request, MPI_Isend
2 parents de26485 + 05e85f7 commit 5bc215a

File tree

10 files changed

+168
-3
lines changed

10 files changed

+168
-3
lines changed

ompi/mca/pml/base/pml_base_frame.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* reserved.
1616
* Copyright (c) 2015 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
18-
* Copyright (c) 2018 IBM Corporation. All rights reserved.
18+
* Copyright (c) 2018-2022 IBM Corporation. All rights reserved.
1919
* Copyright (c) 2020 Intel, Inc. All rights reserved.
2020
* $COPYRIGHT$
2121
*
@@ -42,6 +42,9 @@
4242
#include "ompi/mca/pml/pml.h"
4343
#include "ompi/mca/pml/base/base.h"
4444
#include "ompi/mca/pml/base/pml_base_request.h"
45+
#if MPI_VERSION >= 4
46+
#include "ompi/mca/pml/base/pml_base_sendreq.h"
47+
#endif
4548

4649
/*
4750
* The following file was created by configure. It contains extern
@@ -100,12 +103,28 @@ char *ompi_pml_base_bsend_allocator_name = NULL;
100103
static char *ompi_pml_base_wrapper = NULL;
101104
#endif
102105

106+
#if MPI_VERSION >= 4
107+
#define OMPI_PML_BASE_WARN_DEP_CANCEL_SEND_DEFAULT OMPI_PML_BASE_WARN_DEP_CANCEL_SEND_ONCE
108+
int ompi_pml_base_warn_dep_cancel_send_level = OMPI_PML_BASE_WARN_DEP_CANCEL_SEND_DEFAULT;
109+
mca_base_var_enum_value_t ompi_pml_base_warn_dep_cancel_send_values[] = {
110+
{.value = OMPI_PML_BASE_WARN_DEP_CANCEL_SEND_ALWAYS, .string = "always"},
111+
{.value = OMPI_PML_BASE_WARN_DEP_CANCEL_SEND_ONCE, .string = "once"},
112+
{.value = OMPI_PML_BASE_WARN_DEP_CANCEL_SEND_NEVER, .string = "never"},
113+
{0, NULL}
114+
};
115+
#endif
116+
103117
static int mca_pml_base_register(mca_base_register_flag_t flags)
104118
{
105119
#if !MCA_ompi_pml_DIRECT_CALL
106120
int var_id;
107121
#endif
108122

123+
#if MPI_VERSION >= 4
124+
mca_base_var_enum_t *ompi_pml_base_warn_dep_cancel_send_enum = NULL;
125+
int rc;
126+
#endif
127+
109128
ompi_pml_base_bsend_allocator_name = "basic";
110129
(void) mca_base_var_register("ompi", "pml", "base", "bsend_allocator", NULL,
111130
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
@@ -124,6 +143,21 @@ static int mca_pml_base_register(mca_base_register_flag_t flags)
124143
(void) mca_base_var_register_synonym(var_id, "ompi", "pml", NULL, "wrapper", 0);
125144
#endif
126145

146+
#if MPI_VERSION >= 4
147+
mca_base_var_enum_create("pml_base_deprecate_warnings", ompi_pml_base_warn_dep_cancel_send_values,
148+
&ompi_pml_base_warn_dep_cancel_send_enum);
149+
rc = mca_base_var_register("ompi", "pml", "base", "warn_dep_cancel_send",
150+
"How often to issue warnings for deprecated cancelation of send requests",
151+
MCA_BASE_VAR_TYPE_INT, ompi_pml_base_warn_dep_cancel_send_enum, 0, 0,
152+
OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY,
153+
&ompi_pml_base_warn_dep_cancel_send_level);
154+
OBJ_RELEASE(ompi_pml_base_warn_dep_cancel_send_enum);
155+
if (OPAL_ERR_VALUE_OUT_OF_BOUNDS == rc) {
156+
ompi_pml_base_warn_dep_cancel_send_level = OMPI_PML_BASE_WARN_DEP_CANCEL_SEND_DEFAULT;
157+
opal_output(0, "pml:base:register: Warning invalid deprecation warning value specified. Using default: %d",
158+
ompi_pml_base_warn_dep_cancel_send_level);
159+
}
160+
#endif
127161
return OMPI_SUCCESS;
128162
}
129163

ompi/mca/pml/base/pml_base_sendreq.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* University of Stuttgart. All rights reserved.
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
12+
* Copyright (c) 2022 IBM Corporation. All rights reserved.
1213
* $COPYRIGHT$
1314
*
1415
* Additional copyrights may follow
@@ -19,6 +20,9 @@
1920
#include <string.h>
2021
#include "ompi/mca/pml/pml.h"
2122
#include "ompi/mca/pml/base/pml_base_sendreq.h"
23+
#if MPI_VERSION >= 4
24+
#include "opal/sys/atomic.h"
25+
#endif
2226

2327
static void mca_pml_base_send_request_construct(mca_pml_base_send_request_t* req);
2428
static void mca_pml_base_send_request_destruct(mca_pml_base_send_request_t* req);
@@ -47,3 +51,17 @@ static void mca_pml_base_send_request_destruct(mca_pml_base_send_request_t* req)
4751
*/
4852
}
4953

54+
#if MPI_VERSION >= 4
55+
int mca_pml_cancel_send_callback(struct ompi_request_t *request, int flag)
56+
{
57+
static opal_atomic_int32_t send_deprecate_count = 0;
58+
int32_t val;
59+
60+
val = opal_atomic_add_fetch_32(&send_deprecate_count, 1);
61+
if ( (OMPI_PML_BASE_WARN_DEP_CANCEL_SEND_ONCE == ompi_pml_base_warn_dep_cancel_send_level && (1 == val)) ||
62+
(OMPI_PML_BASE_WARN_DEP_CANCEL_SEND_ALWAYS == ompi_pml_base_warn_dep_cancel_send_level) ) {
63+
opal_output(0, "WARNING: Calling MPI_Cancel for a request created by a non-blocking send is deprecated.");
64+
}
65+
return OMPI_SUCCESS;
66+
}
67+
#endif

ompi/mca/pml/base/pml_base_sendreq.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
1717
* reserved.
1818
* Copyright (c) 2017 Intel, Inc. All rights reserved.
19+
* Copyright (c) 2022 IBM Corporation. All rights reserved.
1920
* $COPYRIGHT$
2021
*
2122
* Additional copyrights may follow
@@ -67,6 +68,19 @@ OMPI_DECLSPEC OBJ_CLASS_DECLARATION( mca_pml_base_send_request_t );
6768
* is done in the send request start routine.
6869
*/
6970

71+
#if MPI_VERSION >= 4
72+
/*
73+
* Deprecation of MPI_Cancel for non blocking sends in MPI 4.0 and later
74+
* is handled by adding a callback for the cancel request.
75+
*/
76+
#define MCA_PML_BASE_SEND_CANCEL_CALLBACK(req) \
77+
if (NULL == (req)->req_base.req_ompi.req_cancel) { \
78+
(req)->req_base.req_ompi.req_cancel = mca_pml_cancel_send_callback; \
79+
}
80+
#else
81+
#define MCA_PML_BASE_SEND_CANCEL_CALLBACK(req)
82+
#endif
83+
7084
#define MCA_PML_BASE_SEND_REQUEST_INIT( request, \
7185
addr, \
7286
count, \
@@ -95,6 +109,7 @@ OMPI_DECLSPEC OBJ_CLASS_DECLARATION( mca_pml_base_send_request_t );
95109
(request)->req_base.req_pml_complete = false; \
96110
(request)->req_base.req_free_called = false; \
97111
(request)->req_base.req_ompi.req_status._cancelled = 0; \
112+
MCA_PML_BASE_SEND_CANCEL_CALLBACK(request) \
98113
(request)->req_bytes_packed = 0; \
99114
\
100115
/* initialize datatype convertor for this request */ \
@@ -153,6 +168,21 @@ OMPI_DECLSPEC OBJ_CLASS_DECLARATION( mca_pml_base_send_request_t );
153168
} while (0)
154169

155170

171+
#if MPI_VERSION >= 4
172+
enum {
173+
OMPI_PML_BASE_WARN_DEP_CANCEL_SEND_ALWAYS = 1,
174+
OMPI_PML_BASE_WARN_DEP_CANCEL_SEND_ONCE = 2,
175+
OMPI_PML_BASE_WARN_DEP_CANCEL_SEND_NEVER = 3,
176+
};
177+
OMPI_DECLSPEC extern int ompi_pml_base_warn_dep_cancel_send_level;
178+
179+
/**
180+
* Cancellation callback used to issue a deprecation warning on
181+
* nonblocking sends (per MPI 4.0).
182+
*/
183+
OMPI_DECLSPEC extern int mca_pml_cancel_send_callback(struct ompi_request_t *request, int flag);
184+
#endif
185+
156186
END_C_DECLS
157187

158188
#endif

ompi/mca/pml/ob1/pml_ob1_isend.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* Copyright (c) 2014-2021 Cisco Systems, Inc. All rights reserved
1616
* Copyright (c) 2015 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
18+
* Copyright (c) 2022 IBM Corporation. All rights reserved.
1819
* $COPYRIGHT$
1920
*
2021
* Additional copyrights may follow
@@ -29,6 +30,9 @@
2930
#include "pml_ob1_recvreq.h"
3031
#include "ompi/peruse/peruse-internal.h"
3132
#include "ompi/runtime/ompi_spc.h"
33+
#if MPI_VERSION >= 4
34+
#include "ompi/mca/pml/base/pml_base_sendreq.h"
35+
#endif
3236

3337
/**
3438
* Single usage request. As we allow recursive calls (as an
@@ -181,6 +185,12 @@ int mca_pml_ob1_isend(const void *buf,
181185
/* NTH: it is legal to return ompi_request_empty since the only valid
182186
* field in a send completion status is whether or not the send was
183187
* cancelled (which it can't be at this point anyway). */
188+
#if MPI_VERSION >= 4
189+
if (OPAL_UNLIKELY(OMPI_PML_BASE_WARN_DEP_CANCEL_SEND_NEVER != ompi_pml_base_warn_dep_cancel_send_level)) {
190+
*request = &ompi_request_empty_send;
191+
return OMPI_SUCCESS;
192+
}
193+
#endif
184194
*request = &ompi_request_empty;
185195
return OMPI_SUCCESS;
186196
}

ompi/mca/pml/ob1/pml_ob1_sendreq.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
2222
* Copyright (c) 2018-2019 Triad National Security, LLC. All rights
2323
* reserved.
24+
* Copyright (c) 2022 IBM Corporation. All rights reserved.
2425
* $COPYRIGHT$
2526
*
2627
* Additional copyrights may follow
@@ -127,6 +128,10 @@ static int mca_pml_ob1_send_request_free(struct ompi_request_t** request)
127128

128129
static int mca_pml_ob1_send_request_cancel(struct ompi_request_t* request, int complete)
129130
{
131+
#if MPI_VERSION >= 4
132+
mca_pml_cancel_send_callback(request, complete);
133+
#endif
134+
130135
#if OPAL_ENABLE_FT_MPI
131136
ompi_communicator_t* comm = request->req_mpi_object.comm;
132137
mca_pml_ob1_send_request_t* pml_req = (mca_pml_ob1_send_request_t*)request;

ompi/mca/pml/ucx/pml_ucx.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* reserved.
66
* Copyright (c) 2018-2019 Research Organization for Information Science
77
* and Technology (RIST). All rights reserved.
8-
* Copyright (c) 2018 IBM Corporation. All rights reserved.
8+
* Copyright (c) 2018-2022 IBM Corporation. All rights reserved.
99
* Copyright (c) 2019 Intel, Inc. All rights reserved.
1010
* Copyright (c) 2022 Amazon.com, Inc. or its affiliates.
1111
* All Rights reserved.
@@ -358,6 +358,9 @@ int mca_pml_ucx_init(int enable_mpi_threads)
358358
/* Create a completed request to be returned from isend */
359359
OBJ_CONSTRUCT(&ompi_pml_ucx.completed_send_req, ompi_request_t);
360360
mca_pml_ucx_completed_request_init(&ompi_pml_ucx.completed_send_req);
361+
#if MPI_VERSION >= 4
362+
ompi_pml_ucx.completed_send_req.req_cancel = mca_pml_cancel_send_callback;
363+
#endif
361364

362365
opal_progress_register(mca_pml_ucx_progress);
363366

@@ -924,6 +927,11 @@ int mca_pml_ucx_isend(const void *buf, size_t count, ompi_datatype_t *datatype,
924927
} else if (!UCS_PTR_IS_ERR(req)) {
925928
PML_UCX_VERBOSE(8, "got request %p", (void*)req);
926929
req->req_mpi_object.comm = comm;
930+
#if MPI_VERSION >= 4
931+
if (OPAL_LIKELY(mca_pml_ucx_request_cancel == req->req_cancel)) {
932+
req->req_cancel = mca_pml_ucx_request_cancel_send;
933+
}
934+
#endif
927935
*request = req;
928936
return OMPI_SUCCESS;
929937
} else {

ompi/mca/pml/ucx/pml_ucx_request.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (c) 2016 The University of Tennessee and The University
44
* of Tennessee Research Foundation. All rights
55
* reserved.
6+
* Copyright (c) 2022 IBM Corporation. All rights reserved.
67
* $COPYRIGHT$
78
*
89
* Additional copyrights may follow
@@ -14,6 +15,7 @@
1415
#include "ompi/mca/pml/base/pml_base_bsend.h"
1516
#include "ompi/message/message.h"
1617
#include "ompi/runtime/ompi_spc.h"
18+
#include "ompi/request/request.h"
1719
#include <inttypes.h>
1820

1921

@@ -29,12 +31,20 @@ static int mca_pml_ucx_request_free(ompi_request_t **rptr)
2931
return OMPI_SUCCESS;
3032
}
3133

32-
static int mca_pml_ucx_request_cancel(ompi_request_t *req, int flag)
34+
int mca_pml_ucx_request_cancel(ompi_request_t *req, int flag)
3335
{
3436
ucp_request_cancel(ompi_pml_ucx.ucp_worker, req);
3537
return OMPI_SUCCESS;
3638
}
3739

40+
#if MPI_VERSION >= 4
41+
int mca_pml_ucx_request_cancel_send(ompi_request_t *req, int flag)
42+
{
43+
mca_pml_cancel_send_callback(req, flag);
44+
return mca_pml_ucx_request_cancel(req, flag);
45+
}
46+
#endif
47+
3848
__opal_attribute_always_inline__ static inline void
3949
mca_pml_ucx_send_completion_internal(void *request, ucs_status_t status)
4050
{

ompi/mca/pml/ucx/pml_ucx_request.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (c) 2016-2021 The University of Tennessee and The University
44
* of Tennessee Research Foundation. All rights
55
* reserved.
6+
* Copyright (c) 2022 IBM Corporation. All rights reserved.
67
* $COPYRIGHT$
78
*
89
* Additional copyrights may follow
@@ -15,6 +16,9 @@
1516

1617
#include "pml_ucx.h"
1718
#include "pml_ucx_datatype.h"
19+
#if MPI_VERSION >= 4
20+
#include "ompi/mca/pml/base/pml_base_sendreq.h"
21+
#endif
1822

1923

2024
enum {
@@ -145,6 +149,11 @@ void mca_pml_ucx_request_init(void *request);
145149

146150
void mca_pml_ucx_request_cleanup(void *request);
147151

152+
int mca_pml_ucx_request_cancel(ompi_request_t *req, int flag);
153+
#if MPI_VERSION >= 4
154+
int mca_pml_ucx_request_cancel_send(ompi_request_t *req, int flag);
155+
#endif
156+
148157

149158
static inline void mca_pml_ucx_request_reset(ompi_request_t *req)
150159
{

ompi/request/request.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
2121
* Copyright (c) 2018 Triad National Security, LLC. All rights
2222
* reserved.
23+
* Copyright (c) 2022 IBM Corporation. All rights reserved.
2324
* $COPYRIGHT$
2425
*
2526
* Additional copyrights may follow
@@ -34,11 +35,17 @@
3435
#include "ompi/request/request.h"
3536
#include "ompi/request/request_default.h"
3637
#include "ompi/constants.h"
38+
#if MPI_VERSION >= 4
39+
#include "ompi/mca/pml/base/pml_base_sendreq.h"
40+
#endif
3741

3842
opal_pointer_array_t ompi_request_f_to_c_table = {{0}};
3943
ompi_predefined_request_t ompi_request_null = {{{{{0}}}}};
4044
ompi_predefined_request_t *ompi_request_null_addr = &ompi_request_null;
4145
ompi_request_t ompi_request_empty = {{{{0}}}};
46+
#if MPI_VERSION >= 4
47+
ompi_request_t ompi_request_empty_send = {{{{0}}}};
48+
#endif
4249
ompi_status_public_t ompi_status_empty = {0};
4350
ompi_request_fns_t ompi_request_functions = {
4451
ompi_request_default_test,
@@ -179,6 +186,36 @@ int ompi_request_init(void)
179186
return OMPI_ERR_REQUEST;
180187
}
181188

189+
#if MPI_VERSION >= 4
190+
/*
191+
* This is a copy of the ompi_request_empty object where the only difference
192+
* is that the req_cancel callback is set to a callback which issues a
193+
* message that calling MPI_Cancel on a non-blocking send request is
194+
* deprecated.
195+
*/
196+
OBJ_CONSTRUCT(&ompi_request_empty_send, ompi_request_t);
197+
ompi_request_empty_send.req_type = OMPI_REQUEST_NULL;
198+
ompi_request_empty_send.req_status.MPI_SOURCE = MPI_PROC_NULL;
199+
ompi_request_empty_send.req_status.MPI_TAG = MPI_ANY_TAG;
200+
ompi_request_empty_send.req_status.MPI_ERROR = MPI_SUCCESS;
201+
ompi_request_empty_send.req_status._ucount = 0;
202+
ompi_request_empty_send.req_status._cancelled = 0;
203+
204+
ompi_request_empty_send.req_complete = REQUEST_COMPLETED;
205+
ompi_request_empty_send.req_state = OMPI_REQUEST_ACTIVE;
206+
ompi_request_empty_send.req_persistent = false;
207+
ompi_request_empty_send.req_f_to_c_index =
208+
opal_pointer_array_add(&ompi_request_f_to_c_table, &ompi_request_empty_send);
209+
ompi_request_empty_send.req_start = NULL; /* should not be called */
210+
ompi_request_empty_send.req_free = ompi_request_empty_free;
211+
ompi_request_empty_send.req_cancel = mca_pml_cancel_send_callback;
212+
ompi_request_empty_send.req_mpi_object.comm = &ompi_mpi_comm_world.comm;
213+
214+
if (2 != ompi_request_empty_send.req_f_to_c_index) {
215+
return OMPI_ERR_REQUEST;
216+
}
217+
#endif
218+
182219
ompi_status_empty.MPI_SOURCE = MPI_ANY_SOURCE;
183220
ompi_status_empty.MPI_TAG = MPI_ANY_TAG;
184221
ompi_status_empty.MPI_ERROR = MPI_SUCCESS;

ompi/request/request.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
1919
* Copyright (c) 2018 Triad National Security, LLC. All rights
2020
* reserved.
21+
* Copyright (c) 2022 IBM Corporation. All rights reserved.
2122
* $COPYRIGHT$
2223
*
2324
* Additional copyrights may follow
@@ -383,6 +384,9 @@ OMPI_DECLSPEC extern ompi_predefined_request_t *ompi_request_null_addr;
383384
OMPI_DECLSPEC extern ompi_request_t ompi_request_empty;
384385
OMPI_DECLSPEC extern ompi_status_public_t ompi_status_empty;
385386
OMPI_DECLSPEC extern ompi_request_fns_t ompi_request_functions;
387+
#if MPI_VERSION >= 4
388+
OMPI_DECLSPEC extern ompi_request_t ompi_request_empty_send;
389+
#endif
386390

387391
/**
388392
* Initialize the MPI_Request subsystem; invoked during MPI_INIT.

0 commit comments

Comments
 (0)