Skip to content

Commit 991457e

Browse files
committed
Move ABI support into big count binding code
Implement lots of missing functionality in the original api.py script. The functionality is now part of the bindings generation framework used for Big Count. Number of todos still to do, in particular provide support for wrapping user supplied callback functions. Also, the sendrecv_replace, etc. code needs to be refactored to work with the bindings framework. Signed-off-by: Howard Pritchard <howardp@lanl.gov>
1 parent a4c1511 commit 991457e

16 files changed

+503
-136
lines changed

config/ompi_configure_options.m4

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ AM_CONDITIONAL(OMPI_OMPIO_SUPPORT, test "$ompi_want_ompio" = "1")
256256
AC_ARG_ENABLE([deprecate-mpif-h],
257257
[AS_HELP_STRING([--enable-deprecate-mpif-h],
258258
[Mark the mpif.h bindings as deprecated (default: enabled)])])
259+
# If the binding source files don't exist, then we need Python to generate them
260+
AM_PATH_PYTHON([3.6],,[:])
261+
binding_file="${srcdir}/ompi/mpi/c/ompi_send_generated.c"
262+
AS_IF([! test -e "$binding_file" && test "$PYTHON" = ":"],
263+
[AC_MSG_ERROR([Open MPI requires Python >=3.6 for generating the bindings. Aborting])])
264+
AM_CONDITIONAL(OMPI_GENERATE_BINDINGS,[test "$PYTHON" != ":"])
259265

260266
AC_MSG_CHECKING([if want to enable standard ABI library])
261267
AC_ARG_ENABLE([standard-abi],

ompi/Makefile.am

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ DIST_SUBDIRS = \
126126
$(MCA_ompi_FRAMEWORKS_SUBDIRS) \
127127
$(MCA_ompi_FRAMEWORK_COMPONENT_ALL_SUBDIRS)
128128

129-
noinst_LTLIBRARIES = libopen-mpi.la
129+
noinst_LTLIBRARIES = libopen_mpi.la
130130
lib_LTLIBRARIES = lib@OMPI_LIBMPI_NAME@.la
131131
if OMPI_STANDARD_ABI
132132
lib_LTLIBRARIES += libmpi_abi.la
@@ -142,14 +142,14 @@ endif
142142
# +----------------------+----------------------+
143143
# | libmpi_abi.la | libmpi.la |
144144
# +----------------------+----------------------+
145-
# | libopen-mpi.la |
145+
# | libopen_mpi.la |
146146
# +----------------------+----------------------+
147147
#
148-
# This includes a new library, libopen-mpi.la, that links in all backend code
148+
# This includes a new library, libopen_mpi.la, that links in all backend code
149149
# built in this directory or SUBDIRs of this directory. Previously everything
150150
# was just linked directly into libmpi.la (lib@OMPI_LIBMPI_NAME@.la).
151151
#
152-
# libmpi_abi.la and libmpi.la both now link in libopen-mpi.la, the only
152+
# libmpi_abi.la and libmpi.la both now link in libopen_mpi.la, the only
153153
# difference between them being that one includes the standard ABI functions
154154
# and the other the ompi-specific versions of those.
155155
#
@@ -167,7 +167,7 @@ libopen_mpi_la_DEPENDENCIES = $(libopen_mpi_la_LIBADD)
167167
# Build the main MPI library
168168
lib@OMPI_LIBMPI_NAME@_la_SOURCES =
169169
lib@OMPI_LIBMPI_NAME@_la_LIBADD = \
170-
libopen-mpi.la \
170+
libopen_mpi.la \
171171
mpi/c/libmpi_c.la \
172172
mpi/tool/libmpi_mpit.la \
173173
$(c_mpi_lib) \
@@ -182,16 +182,16 @@ lib@OMPI_LIBMPI_NAME@_la_LDFLAGS = \
182182
# The MPI Standard ABI library
183183
libmpi_abi_la_SOURCES =
184184
libmpi_abi_la_LIBADD = \
185-
libopen-mpi.la \
185+
libopen_mpi.la \
186186
mpi/c/libmpi_c_abi.la
187187

188188
# included subdirectory Makefile.am's and appended-to variables
189189
headers =
190-
noinst_LTLIBRARIES =
191190
include_HEADERS =
192191
EXTRA_DIST =
193192
lib@OMPI_LIBMPI_NAME@_la_SOURCES += $(headers)
194193
dist_ompidata_DATA =
194+
libopen_mpi_la_SOURCES += $(headers)
195195

196196
# Conditionally install the header files
197197

ompi/include/mpi.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,7 @@ OMPI_DECLSPEC extern struct ompi_predefined_datatype_t ompi_mpi_ub;
14331433
/*
14341434
* MPI API
14351435
*/
1436+
#ifndef OMPI_NO_MPI_PROTOTYPES
14361437
OMPI_DECLSPEC int MPI_Abi_supported(int *flag);
14371438
OMPI_DECLSPEC int MPI_Abi_version(int *abi_major, int *abi_minor);
14381439
OMPI_DECLSPEC int MPI_Abi_details(int *buflen, char *details, MPI_Info *info);
@@ -4093,6 +4094,7 @@ OMPI_DECLSPEC int PMPI_Type_ub(MPI_Datatype mtype, MPI_Aint *ub)
40934094

40944095
#endif /* OMPI_NO_MPI_PROTOTYPES */
40954096

4097+
40964098
#if defined(c_plusplus) || defined(__cplusplus)
40974099
}
40984100
#endif

ompi/mpi/bindings/ompi_bindings/c.py

Lines changed: 103 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,57 @@ def generate_comm_convert_fn_intern_to_abi(self):
137137
def generate_info_convert_fn(self):
138138
self.generic_convert(ConvertFuncs.INFO, 'info', 'MPI_Info', consts.RESERVED_INFOS)
139139

140+
def generate_info_convert_fn_intern_to_abi(self):
141+
self.generic_convert_reverse(ConvertOMPIToStandard.INFO, 'info', 'MPI_Info', consts.RESERVED_INFOS)
142+
143+
def generate_file_convert_fn(self):
144+
self.generic_convert(ConvertFuncs.FILE, 'file', 'MPI_File', consts.RESERVED_FILES)
145+
140146
def generate_file_convert_fn_intern_to_abi(self):
141-
self.generic_convert_reverse(ConvertFuncs.FILE, 'file', 'MPI_File', consts.RESERVED_FILES)
147+
self.generic_convert_reverse(ConvertOMPIToStandard.FILE, 'file', 'MPI_File', consts.RESERVED_FILES)
142148

143149
def generate_datatype_convert_fn(self):
144150
self.generic_convert(ConvertFuncs.DATATYPE, 'datatype', 'MPI_Datatype', consts.PREDEFINED_DATATYPES)
145151

152+
def generate_datatype_convert_fn_intern_to_abi(self):
153+
self.generic_convert_reverse(ConvertOMPIToStandard.DATATYPE, 'datatype', 'MPI_Datatype', consts.PREDEFINED_DATATYPES)
154+
155+
def generate_errhandler_convert_fn(self):
156+
self.generic_convert(ConvertFuncs.ERRHANDLER, 'errorhandler', 'MPI_Errhandler', consts.RESERVED_ERRHANDLERS)
157+
158+
def generate_errhandler_convert_fn_intern_to_abi(self):
159+
self.generic_convert_reverse(ConvertOMPIToStandard.ERRHANDLER, 'errorhandler', 'MPI_Errhandler', consts.RESERVED_ERRHANDLERS)
160+
161+
def generate_group_convert_fn(self):
162+
self.generic_convert(ConvertFuncs.GROUP, 'group', 'MPI_Group', consts.RESERVED_GROUPS)
163+
164+
def generate_group_convert_fn_intern_to_abi(self):
165+
self.generic_convert_reverse(ConvertOMPIToStandard.GROUP, 'group', 'MPI_Group', consts.RESERVED_GROUPS)
166+
167+
def generate_message_convert_fn(self):
168+
self.generic_convert(ConvertFuncs.MESSAGE, 'message', 'MPI_Message', consts.RESERVED_MESSAGES)
169+
170+
def generate_message_convert_fn_intern_to_abi(self):
171+
self.generic_convert_reverse(ConvertOMPIToStandard.MESSAGE, 'message', 'MPI_Message', consts.RESERVED_MESSAGES)
172+
146173
def generate_op_convert_fn(self):
147174
self.generic_convert(ConvertFuncs.OP, 'op', 'MPI_Op', consts.COLLECTIVE_OPERATIONS)
148175

176+
def generate_op_convert_fn_intern_to_abi(self):
177+
self.generic_convert_reverse(ConvertOMPIToStandard.OP, 'op', 'MPI_Op', consts.RESERVED_OPS)
178+
179+
def generate_session_convert_fn(self):
180+
self.generic_convert(ConvertFuncs.SESSION, 'session', 'MPI_Session', consts.RESERVED_SESSIONS)
181+
182+
def generate_session_convert_fn_intern_to_abi(self):
183+
self.generic_convert_reverse(ConvertOMPIToStandard.SESSION, 'session', 'MPI_Session', consts.RESERVED_SESSIONS)
184+
149185
def generate_win_convert_fn(self):
150186
self.generic_convert(ConvertFuncs.WIN, 'win', 'MPI_Win', consts.RESERVED_WINDOWS)
151187

188+
def generate_win_convert_fn_intern_to_abi(self):
189+
self.generic_convert_reverse(ConvertOMPIToStandard.WIN, 'win', 'MPI_Win', consts.RESERVED_WINDOWS)
190+
152191
def generate_pointer_convert_fn(self, type_, fn_name, constants):
153192
abi_type = self.mangle_name(type_)
154193
self.dump(f'{consts.INLINE_ATTRS} void {fn_name}({abi_type} *ptr)')
@@ -168,20 +207,34 @@ def generate_pointer_convert_fn(self, type_, fn_name, constants):
168207
def generate_request_convert_fn(self):
169208
self.generate_pointer_convert_fn('MPI_Request', ConvertFuncs.REQUEST, consts.RESERVED_REQUESTS)
170209

171-
def generate_file_convert_fn(self):
172-
self.generate_pointer_convert_fn('MPI_File', ConvertFuncs.FILE, consts.RESERVED_FILES)
210+
def generate_request_convert_fn_intern_to_abi(self):
211+
self.generic_convert_reverse(ConvertOMPIToStandard.REQUEST, 'request', 'MPI_Request', consts.RESERVED_REQUESTS)
212+
213+
# def generate_file_convert_fn(self):
214+
# self.generate_pointer_convert_fn('MPI_File', ConvertFuncs.FILE, consts.RESERVED_FILES)
173215

174216
def generate_status_convert_fn(self):
175217
type_ = 'MPI_Status'
176218
abi_type = self.mangle_name(type_)
177-
self.dump(f'{consts.INLINE_ATTRS} void {ConvertFuncs.STATUS}({abi_type} *out, {type_} *inp)')
219+
self.dump(f'{consts.INLINE_ATTRS} void {ConvertFuncs.STATUS}({type_} *out, {abi_type} *inp)')
178220
self.dump('{')
179221
self.dump(' out->MPI_SOURCE = inp->MPI_SOURCE;')
180222
self.dump(' out->MPI_TAG = inp->MPI_TAG;')
181223
self.dump(f' out->MPI_ERROR = {ConvertFuncs.ERROR_CLASS}(inp->MPI_ERROR);')
182224
# Ignoring the private fields for now
183225
self.dump('}')
184226

227+
def generate_status_convert_fn_intern_to_abi(self):
228+
type_ = 'MPI_Status'
229+
abi_type = self.mangle_name(type_)
230+
self.dump(f'{consts.INLINE_ATTRS} void {ConvertOMPIToStandard.STATUS}({abi_type} *out, {type_} *inp)')
231+
self.dump('{')
232+
self.dump(' out->MPI_SOURCE = inp->MPI_SOURCE;')
233+
self.dump(' out->MPI_TAG = inp->MPI_TAG;')
234+
# self.dump(f' out->MPI_ERROR = {ConvertOMPIToStandard.ERROR_CLASS}(inp->MPI_ERROR);')
235+
# Ignoring the private fields for now
236+
self.dump('}')
237+
185238
def define(self, type_, name, value):
186239
self.dump(f'#define {name} OMPI_CAST_CONSTANT({type_}, {value})')
187240

@@ -217,12 +270,17 @@ def dump_header(self):
217270
self.dump()
218271

219272
self.define_all('MPI_Datatype', consts.PREDEFINED_DATATYPES)
220-
self.define_all('MPI_Op', COLLECTIVE_OPERATIONS)
273+
self.define_all('MPI_Op', consts.COLLECTIVE_OPERATIONS)
274+
self.define_all('MPI_Op', consts.RESERVED_OPS)
221275
self.define_all('MPI_Comm', consts.RESERVED_COMMUNICATORS)
276+
self.define_all('MPI_Errhandler', consts.RESERVED_ERRHANDLERS)
277+
self.define_all('MPI_Group', consts.RESERVED_GROUPS)
222278
self.define_all('MPI_Request', consts.RESERVED_REQUESTS)
279+
self.define_all('MPI_Session', consts.RESERVED_SESSIONS)
223280
self.define_all('MPI_Win', consts.RESERVED_WINDOWS)
224281
self.define_all('MPI_Info', consts.RESERVED_INFOS)
225282
self.define_all('MPI_File', consts.RESERVED_FILES)
283+
self.define_all('MPI_Message', consts.RESERVED_MESSAGES)
226284

227285
for name, value in consts.VARIOUS_CONSTANTS.items():
228286
self.dump(f'#define {self.mangle_name(name)} {value}')
@@ -255,9 +313,13 @@ def dump_header(self):
255313
};""")
256314
self.dump(f'typedef struct MPI_Status_ABI {self.mangle_name("MPI_Status")};')
257315
self.dump()
316+
# user functions
317+
self.dump('typedef int (MPI_Copy_function)(MPI_Comm_ABI_INTERNAL, int, void *, void *, void *, int *);')
318+
self.dump('typedef int (MPI_Delete_function)(MPI_Comm_ABI_INTERNAL, int, void *, void *);')
258319
# Function signatures
259320
for sig in self.signatures:
260321
self.dump(f'{sig};')
322+
# print("Working on signature " + str(sig))
261323
self.dump('int MPI_Abi_details(int *buflen, char *details, MPI_Info *info);')
262324
self.dump('int MPI_Abi_supported(int *flag);')
263325
self.dump('int MPI_Abi_version(int *abi_major, int *abi_minor);')
@@ -267,12 +329,27 @@ def dump_header(self):
267329
self.generate_comm_convert_fn()
268330
self.generate_comm_convert_fn_intern_to_abi()
269331
self.generate_info_convert_fn()
332+
self.generate_info_convert_fn_intern_to_abi()
270333
self.generate_file_convert_fn()
334+
self.generate_file_convert_fn_intern_to_abi()
335+
self.generate_group_convert_fn()
336+
self.generate_group_convert_fn_intern_to_abi()
271337
self.generate_datatype_convert_fn()
338+
self.generate_datatype_convert_fn_intern_to_abi()
339+
self.generate_errhandler_convert_fn()
340+
self.generate_errhandler_convert_fn_intern_to_abi()
341+
self.generate_message_convert_fn()
342+
self.generate_message_convert_fn_intern_to_abi()
272343
self.generate_op_convert_fn()
344+
self.generate_op_convert_fn_intern_to_abi()
345+
self.generate_session_convert_fn()
346+
self.generate_session_convert_fn_intern_to_abi()
273347
self.generate_win_convert_fn()
348+
self.generate_win_convert_fn_intern_to_abi()
274349
self.generate_request_convert_fn()
350+
self.generate_request_convert_fn_intern_to_abi()
275351
self.generate_status_convert_fn()
352+
self.generate_status_convert_fn_intern_to_abi()
276353

277354
self.dump("""
278355
#if defined(c_plusplus) || defined(__cplusplus)
@@ -292,7 +369,7 @@ def print_profiling_header(fn_name, out):
292369
out.dump('#endif')
293370

294371

295-
def print_cdefs_for_bigcount(fn_name, out, enable_count=False):
372+
def print_cdefs_for_bigcount(out, enable_count=False):
296373
if enable_count:
297374
out.dump('#undef OMPI_BIGCOUNT_SRC')
298375
out.dump('#define OMPI_BIGCOUNT_SRC 1')
@@ -304,14 +381,14 @@ def ompi_abi(base_name, template, out):
304381
"""Generate the OMPI ABI functions."""
305382
template.print_header(out)
306383
print_profiling_header(base_name, out)
307-
print_cdefs_for_bigcount(base_name, out)
384+
print_cdefs_for_bigcount(out)
308385
out.dump(template.prototype.signature(base_name, abi_type='ompi'))
309386
template.print_body(func_name=base_name, out=out)
310387
# Check if we need to generate the bigcount interface
311388
if util.prototype_has_bigcount(template.prototype):
312389
base_name_c = f'{base_name}_c'
313390
print_profiling_header(base_name_c, out)
314-
print_cdefs_for_bigcount(base_name_c, out, enable_count=True)
391+
print_cdefs_for_bigcount(out, enable_count=True)
315392
out.dump(template.prototype.signature(base_name_c, abi_type='ompi', enable_count=True))
316393
template.print_body(func_name=base_name_c, out=out)
317394

@@ -326,15 +403,23 @@ def standard_abi(base_name, template, out):
326403

327404
# Static internal function (add a random component to avoid conflicts)
328405
internal_name = f'ompi_abi_{template.prototype.name}'
406+
print_cdefs_for_bigcount(out)
329407
internal_sig = template.prototype.signature(internal_name, abi_type='ompi',
330-
enable_count=True)
408+
enable_count=False)
331409
out.dump(consts.INLINE_ATTRS, internal_sig)
332410
template.print_body(func_name=base_name, out=out)
333-
334-
def generate_function(prototype, fn_name, internal_fn, enable_count=False):
411+
if util.prototype_has_bigcount(template.prototype):
412+
internal_name = f'ompi_abi_{template.prototype.name}_c'
413+
print_cdefs_for_bigcount(out, enable_count=True)
414+
internal_sig = template.prototype.signature(internal_name, abi_type='ompi',
415+
enable_count=True)
416+
out.dump(consts.INLINE_ATTRS, internal_sig)
417+
template.print_body(func_name=base_name, out=out)
418+
419+
def generate_function(prototype, fn_name, internal_fn, out, enable_count=False):
335420
"""Generate a function for the standard ABI."""
336-
print_profiling_header(fn_name)
337-
print_cdefs_for_bigcount(fn_name,enable_count)
421+
print_profiling_header(fn_name,out)
422+
# print_cdefs_for_bigcount(out, enable_count)
338423

339424
# Handle type conversions and arguments
340425
params = [param.construct(abi_type='standard') for param in prototype.params]
@@ -344,6 +429,7 @@ def generate_function(prototype, fn_name, internal_fn, enable_count=False):
344429
return_type = prototype.return_type.construct(abi_type='standard')
345430
lines.append(f'{return_type.tmp_type_text()} ret_value;')
346431
for param in params:
432+
# print("param = " + str(param) + " " + str(param.argument))
347433
if param.init_code:
348434
lines.extend(param.init_code)
349435
pass_args = ', '.join(param.argument for param in params)
@@ -359,10 +445,12 @@ def generate_function(prototype, fn_name, internal_fn, enable_count=False):
359445
out.dump(line)
360446
out.dump('}')
361447

362-
generate_function(template.prototype, base_name, internal_name)
448+
internal_name = f'ompi_abi_{template.prototype.name}'
449+
generate_function(template.prototype, base_name, internal_name, out)
363450
if util.prototype_has_bigcount(template.prototype):
364451
base_name_c = f'{base_name}_c'
365-
generate_function(template.prototype, base_name_c, internal_name,
452+
internal_name = f'ompi_abi_{template.prototype.name}_c'
453+
generate_function(template.prototype, base_name_c, internal_name, out,
366454
enable_count=True)
367455

368456

0 commit comments

Comments
 (0)