Skip to content

Commit 74fc0ac

Browse files
committed
some fixes and start of a wrapper method
for comm/type/win attributes. Not clear if this is the way to handle attr copy/del call backs compiled againt the mpi.h ABI header file. Signed-off-by: Howard Pritchard <howardp@lanl.gov>
1 parent 049755d commit 74fc0ac

File tree

8 files changed

+144
-26
lines changed

8 files changed

+144
-26
lines changed

ompi/attribute/attribute.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#define OMPI_KEYVAL_PREDEFINED 0x0001
5151
#define OMPI_KEYVAL_F77 0x0002
5252
#define OMPI_KEYVAL_F77_INT 0x0004
53+
#define OMPI_KEYVAL_ABI 0x0008
5354

5455

5556
BEGIN_C_DECLS
@@ -136,7 +137,7 @@ struct ompi_attribute_keyval_t {
136137
copy/delete attribute functions
137138
properly and error checking */
138139
int attr_flag; /**< flag field: contains "OMPI_KEYVAL_PREDEFINED",
139-
"OMPI_KEYVAL_F77" */
140+
"OMPI_KEYVAL_F77", "OMPI_KEYVAL_ABI", etc. */
140141
ompi_attribute_fn_ptr_union_t copy_attr_fn; /**< Copy function for the
141142
attribute */
142143
ompi_attribute_fn_ptr_union_t delete_attr_fn; /**< Delete function for the

ompi/mpi/bindings/ompi_bindings/c.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,35 @@ def dump_header(self):
322322
# user functions
323323
self.dump('typedef int (MPI_Copy_function)(MPI_Comm_ABI_INTERNAL, int, void *, void *, void *, int *);')
324324
self.dump('typedef int (MPI_Delete_function)(MPI_Comm_ABI_INTERNAL, int, void *, void *);')
325+
#
326+
# generate prototypes for user call back functions
327+
#
328+
for handle in consts.C_ATTRIBUTE_OBJS:
329+
prefix, suffix = handle.split('_')
330+
copy_callback_func_name = f'{handle}_copy_attr_function'
331+
copy_callback_func_name = f'{self.mangle_name(copy_callback_func_name)}'
332+
delete_callback_func_name = f'{handle}_delete_attr_function'
333+
delete_callback_func_name = f'{self.mangle_name(delete_callback_func_name)}'
334+
#
335+
# stupid MPI standard naming consistency
336+
#
337+
if handle == 'MPI_Type':
338+
obj_arg_type = f'{self.mangle_name("MPI_Datatype")}'
339+
else:
340+
obj_arg_type = f'{self.mangle_name(handle)}'
341+
obj_arg_name = f'old{suffix}'.lower()
342+
obj_arg = f'{obj_arg_type} {obj_arg_name}'
343+
keyval_arg = f'int {suffix}_keyval'.lower()
344+
self.dump(f'typedef int ({copy_callback_func_name})({obj_arg}, {keyval_arg}, void *, void *, void *,int *);')
345+
self.dump(f'typedef int ({delete_callback_func_name})({obj_arg}, {keyval_arg}, void *, void *);')
346+
325347
# Function signatures
326348
for sig in self.signatures:
327349
self.dump(f'{sig};')
328-
# print("Working on signature " + str(sig))
329350
self.dump('int MPI_Abi_details(int *buflen, char *details, MPI_Info *info);')
330351
self.dump('int MPI_Abi_supported(int *flag);')
331352
self.dump('int MPI_Abi_version(int *abi_major, int *abi_minor);')
353+
332354
if not self.external:
333355
# Now generate the conversion code
334356
self.generate_error_convert_fn()
@@ -383,18 +405,28 @@ def print_cdefs_for_bigcount(out, enable_count=False):
383405
out.dump('#undef OMPI_BIGCOUNT_SRC')
384406
out.dump('#define OMPI_BIGCOUNT_SRC 0')
385407

408+
def print_cdefs_for_abi(out, abi_type='ompi'):
409+
if abi_type == 'ompi':
410+
out.dump('#undef OMPI_ABI_SRC')
411+
out.dump('#define OMPI_ABI_SRC 0')
412+
else:
413+
out.dump('#undef OMPI_ABI_SRC')
414+
out.dump('#define OMPI_ABI_SRC 1')
415+
386416
def ompi_abi(base_name, template, out):
387417
"""Generate the OMPI ABI functions."""
388418
template.print_header(out)
389419
print_profiling_header(base_name, out)
390420
print_cdefs_for_bigcount(out)
421+
print_cdefs_for_abi(out)
391422
out.dump(template.prototype.signature(base_name, abi_type='ompi'))
392423
template.print_body(func_name=base_name, out=out)
393424
# Check if we need to generate the bigcount interface
394425
if util.prototype_has_bigcount(template.prototype):
395426
base_name_c = f'{base_name}_c'
396427
print_profiling_header(base_name_c, out)
397428
print_cdefs_for_bigcount(out, enable_count=True)
429+
print_cdefs_for_abi(out)
398430
out.dump(template.prototype.signature(base_name_c, abi_type='ompi', enable_count=True))
399431
template.print_body(func_name=base_name_c, out=out)
400432

@@ -406,17 +438,26 @@ def standard_abi(base_name, template, out):
406438
"""Generate the standard ABI functions."""
407439
template.print_header(out)
408440
out.dump(f'#include "{ABI_INTERNAL_HEADER}"')
441+
print_cdefs_for_abi(out,abi_type='standard')
442+
443+
# If any parameters are pointers to user callback functions, generate code
444+
# for callback wrappers
445+
# if util.prototype_needs_callback_wrappers(template.prototype):
446+
# for param in prototype.params:
447+
# if param.callback_wrapper_code:
409448

410449
# Static internal function (add a random component to avoid conflicts)
411450
internal_name = f'ompi_abi_{template.prototype.name}'
412451
print_cdefs_for_bigcount(out)
452+
print_cdefs_for_abi(out, abi_type='standard')
413453
internal_sig = template.prototype.signature(internal_name, abi_type='ompi',
414454
enable_count=False)
415455
out.dump(consts.INLINE_ATTRS, internal_sig)
416456
template.print_body(func_name=base_name, out=out)
417457
if util.prototype_has_bigcount(template.prototype):
418458
internal_name = f'ompi_abi_{template.prototype.name}_c'
419459
print_cdefs_for_bigcount(out, enable_count=True)
460+
print_cdefs_for_abi(out, abi_type='standard')
420461
internal_sig = template.prototype.signature(internal_name, abi_type='ompi',
421462
enable_count=True)
422463
out.dump(consts.INLINE_ATTRS, internal_sig)

ompi/mpi/bindings/ompi_bindings/c_type.py

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,23 @@ class TypeCommCopyAttrFunctionStandard(Type):
11761176
# pass
11771177

11781178
def type_text(self, enable_count=False):
1179-
return 'MPI_Comm_copy_attr_function *'
1179+
type_name = self.mangle_name('MPI_Comm_copy_attr_function')
1180+
return f'{type_name} *'
1181+
1182+
@property
1183+
def argument(self):
1184+
return f'(MPI_Comm_copy_attr_function *) {self.name}'
1185+
1186+
# @property
1187+
# def init_code(self):
1188+
# code = []
1189+
# code = ['ompi_abi_wrapper_helper_t *helper = NULL;']
1190+
# code.append('helper = ( ompi_abi_wrapper_helper_t *)malloc(sizeof(ompi_abi_wrapper_helper_t));')
1191+
# code.append('if (NULL == helper) return MPI_ERR_NO_MEM;')
1192+
# code.append('helper->user_extra_state = extra_state;')
1193+
# code.append('helper->user_copy_fn = comm_copy_attr_fn;')
1194+
# code.append('helper->user_delete_fn = comm_delete_attr_fn;')
1195+
# return code
11801196

11811197
@Type.add_type('COMM_DELETE_ATTR_FUNCTION', abi_type=['ompi'])
11821198
class TypeCommDeleteAttrFunction(Type):
@@ -1191,7 +1207,12 @@ class TypeCommDeleteAttrFunctionStandard(Type):
11911207
# pass
11921208

11931209
def type_text(self, enable_count=False):
1194-
return 'MPI_Comm_delete_attr_function *'
1210+
type_name = self.mangle_name('MPI_Comm_delete_attr_function')
1211+
return f'{type_name} *'
1212+
1213+
@property
1214+
def argument(self):
1215+
return f'(MPI_Comm_delete_attr_function *) {self.name}'
11951216

11961217
@Type.add_type('GREQUEST_QUERY_FUNCTION', abi_type=['ompi'])
11971218
class TypeGrequestQueryFunction(Type):
@@ -1303,7 +1324,12 @@ class TypeTypeCopyAttrFunctionStandard(Type):
13031324
# pass
13041325

13051326
def type_text(self, enable_count=False):
1306-
return 'MPI_Type_copy_attr_function *'
1327+
type_name = self.mangle_name('MPI_Type_copy_attr_function')
1328+
return f'{type_name} *'
1329+
1330+
@property
1331+
def argument(self):
1332+
return f'(MPI_Type_copy_attr_function *) {self.name}'
13071333

13081334
@Type.add_type('TYPE_DELETE_ATTR_FUNCTION', abi_type=['ompi'])
13091335
class TypeTypeDeleteAttrFunction(Type):
@@ -1318,9 +1344,15 @@ class TypeTypeDeleteAttrFunctionStandard(Type):
13181344
# pass
13191345

13201346
def type_text(self, enable_count=False):
1321-
return 'MPI_Type_delete_attr_function *'
1347+
type_name = self.mangle_name('MPI_Type_delete_attr_function')
1348+
return f'{type_name} *'
1349+
1350+
@property
1351+
def argument(self):
1352+
return f'(MPI_Type_delete_attr_function *) {self.name}'
13221353

13231354
@Type.add_type('WIN_ERRHANDLER_FUNCTION', abi_type=['ompi'])
1355+
13241356
class TypeWinErrhandlerFunction(Type):
13251357

13261358
def type_text(self, enable_count=False):
@@ -1348,7 +1380,12 @@ class TypeWinCopyAttrFunctionStandard(Type):
13481380
# pass
13491381

13501382
def type_text(self, enable_count=False):
1351-
return 'MPI_Win_copy_attr_function *'
1383+
type_name = self.mangle_name('MPI_Win_copy_attr_function')
1384+
return f'{type_name} *'
1385+
1386+
@property
1387+
def argument(self):
1388+
return f'(MPI_Win_copy_attr_function *) {self.name}'
13521389

13531390
@Type.add_type('WIN_DELETE_ATTR_FUNCTION', abi_type=['ompi'])
13541391
class TypeWinDeleteAttrFunction(Type):
@@ -1363,7 +1400,12 @@ class TypeWinDeleteAttrFunctionStandard(Type):
13631400
# pass
13641401

13651402
def type_text(self, enable_count=False):
1366-
return 'MPI_Win_delete_attr_function *'
1403+
type_name = self.mangle_name('MPI_Win_delete_attr_function')
1404+
return f'{type_name} *'
1405+
1406+
@property
1407+
def argument(self):
1408+
return f'(MPI_Win_delete_attr_function *) {self.name}'
13671409

13681410
@Type.add_type('ERRHANDLER', abi_type=['ompi'])
13691411
class TypeErrhandler(Type):
@@ -1472,23 +1514,23 @@ def type_text(self, enable_count=False):
14721514

14731515

14741516
@Type.add_type('SESSION_INOUT', abi_type=['standard'])
1475-
class TypeSessionOutStandard(StandardABIType):
1517+
class TypeSessionInOutStandard(StandardABIType):
14761518

1477-
# @property
1478-
# def init_code(self):
1479-
# return [f'MPI_Session {self.tmpname} = {ConvertFuncs.SESSION}(*{self.name});']
1519+
@property
1520+
def init_code(self):
1521+
return [f'MPI_Session {self.tmpname} = {ConvertFuncs.SESSION}(*{self.name});']
14801522

14811523
@property
14821524
def final_code(self):
1483-
return [f'*{self.name} = {ConvertOMPIToStandard.SESSION}((MPI_Session) *{self.name});']
1525+
return [f'*{self.name} = {ConvertOMPIToStandard.SESSION}({self.tmpname});']
14841526

14851527
def type_text(self, enable_count=False):
14861528
type_name = self.mangle_name('MPI_Session')
14871529
return f'{type_name} *'
14881530

14891531
@property
14901532
def argument(self):
1491-
return f'(MPI_Session *) {self.name}'
1533+
return f'&{self.tmpname}'
14921534

14931535

14941536
@Type.add_type('SESSION_OUT', abi_type=['standard'])

ompi/mpi/bindings/ompi_bindings/consts.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,15 @@
250250
'MPI_Win',
251251
]
252252

253+
#
254+
# C objects that can have attributes cached on them
255+
#
256+
C_ATTRIBUTE_OBJS = [
257+
'MPI_Comm',
258+
'MPI_Type',
259+
'MPI_Win',
260+
]
261+
253262
class ConvertFuncs:
254263
"""Names of conversion functions (between standard ABI and OMPI ABI)."""
255264

@@ -262,7 +271,7 @@ class ConvertFuncs:
262271
STATUS = 'ompi_convert_abi_status_intern_status'
263272
MESSAGE = 'ompi_convert_abi_message_intern_message'
264273
OP = 'ompi_convert_abi_op_intern_op'
265-
SESSION = 'ompi_convert_abi_session_intern_win'
274+
SESSION = 'ompi_convert_abi_session_intern_session'
266275
WIN = 'ompi_convert_abi_win_intern_win'
267276
INFO = 'ompi_convert_abi_info_intern_info'
268277
FILE = 'ompi_convert_abi_file_intern_file'

ompi/mpi/bindings/ompi_bindings/util.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ def abi_internal_name(extname):
159159
'DATAREP_CONVERSION_FUNCTION',
160160
]
161161

162-
163162
def prototype_has_bigcount(prototype):
164163
"""Should this prototype have a bigcount version?"""
165164
return any(param.type_name in BIGCOUNT_TYPE_NAMES for param in prototype.params)
@@ -177,3 +176,17 @@ def prototype_has_buffers(prototype):
177176
return True
178177
else:
179178
return False
179+
180+
USER_CALLBACK_NAMES = [
181+
'COMM_COPY_ATTR_FUNCTION',
182+
'COMM_DELETE_ATTR_FUNCTION',
183+
'TYPE_COPY_ATTR_FUNCTION',
184+
'TYPE_DELETE_ATTR_FUNCTION',
185+
'WIN_COPY_ATTR_FUNCTION',
186+
'WIN_DELETE_ATTR_FUNCTION',
187+
]
188+
189+
def prototype_needs_callback_wrappers(prototype):
190+
"""Should this prototype need a callback wrappers"""
191+
return any(param.type_name in USER_CALLBACK_NAMES for param in prototype.params)
192+

ompi/mpi/c/comm_create_keyval.c.in

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ PROTOTYPE ERROR_CLASS comm_create_keyval(COMM_COPY_ATTR_FUNCTION comm_copy_attr_
3636
INT_OUT comm_keyval, BUFFER_OUT extra_state)
3737
{
3838
int ret;
39+
int flags = 0;
3940
ompi_attribute_fn_ptr_union_t copy_fn;
4041
ompi_attribute_fn_ptr_union_t del_fn;
4142

@@ -48,11 +49,14 @@ PROTOTYPE ERROR_CLASS comm_create_keyval(COMM_COPY_ATTR_FUNCTION comm_copy_attr_
4849
}
4950
}
5051

51-
copy_fn.attr_communicator_copy_fn = comm_copy_attr_fn;
52-
del_fn.attr_communicator_delete_fn = comm_delete_attr_fn;
52+
copy_fn.attr_communicator_copy_fn = (MPI_Comm_copy_attr_function *)comm_copy_attr_fn;
53+
del_fn.attr_communicator_delete_fn = (MPI_Comm_delete_attr_function *)comm_delete_attr_fn;
5354

54-
ret = ompi_attr_create_keyval(COMM_ATTR, copy_fn,
55-
del_fn, comm_keyval, extra_state, 0, NULL);
55+
#if OMPI_ABI_SRC
56+
flags |= OMPI_KEYVAL_ABI;
57+
#endif
58+
ret = ompi_attr_create_keyval(COMM_ATTR, copy_fn, del_fn,
59+
comm_keyval, extra_state, flags, NULL);
5660

5761
OMPI_ERRHANDLER_NOHANDLE_RETURN(ret, MPI_ERR_OTHER, FUNC_NAME);
5862
}

ompi/mpi/c/type_create_keyval.c.in

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ PROTOTYPE ERROR_CLASS type_create_keyval(TYPE_COPY_ATTR_FUNCTION type_copy_attr_
3636
INT_OUT type_keyval,
3737
BUFFER_OUT extra_state)
3838
{
39-
int ret;
39+
int ret, flags = 0;
4040
ompi_attribute_fn_ptr_union_t copy_fn;
4141
ompi_attribute_fn_ptr_union_t del_fn;
4242

@@ -53,8 +53,12 @@ PROTOTYPE ERROR_CLASS type_create_keyval(TYPE_COPY_ATTR_FUNCTION type_copy_attr_
5353
copy_fn.attr_datatype_copy_fn = type_copy_attr_fn;
5454
del_fn.attr_datatype_delete_fn = type_delete_attr_fn;
5555

56+
#if OMPI_ABI_SRC
57+
flags |= OMPI_KEYVAL_ABI;
58+
#endif
59+
5660
ret = ompi_attr_create_keyval(TYPE_ATTR, copy_fn, del_fn,
57-
type_keyval, extra_state, 0, NULL);
61+
type_keyval, extra_state, flags, NULL);
5862
OMPI_ERRHANDLER_NOHANDLE_RETURN(ret, ret, FUNC_NAME);
5963
}
6064

ompi/mpi/c/win_create_keyval.c.in

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ PROTOTYPE ERROR_CLASS win_create_keyval(WIN_COPY_ATTR_FUNCTION win_copy_attr_fn,
3535
WIN_DELETE_ATTR_FUNCTION win_delete_attr_fn,
3636
INT_OUT win_keyval, BUFFER_OUT extra_state)
3737
{
38-
int ret;
38+
int ret, flags = 0;
3939
ompi_attribute_fn_ptr_union_t copy_fn;
4040
ompi_attribute_fn_ptr_union_t del_fn;
4141

@@ -48,10 +48,14 @@ PROTOTYPE ERROR_CLASS win_create_keyval(WIN_COPY_ATTR_FUNCTION win_copy_attr_fn,
4848
}
4949
}
5050

51-
copy_fn.attr_win_copy_fn = win_copy_attr_fn;
52-
del_fn.attr_win_delete_fn = win_delete_attr_fn;
51+
copy_fn.attr_win_copy_fn = (MPI_Win_copy_attr_function *)win_copy_attr_fn;
52+
del_fn.attr_win_delete_fn = (MPI_Win_delete_attr_function *)win_delete_attr_fn;
53+
54+
#if OMPI_ABI_SRC
55+
flags |= OMPI_KEYVAL_ABI;
56+
#endif
5357

5458
ret = ompi_attr_create_keyval(WIN_ATTR, copy_fn, del_fn,
55-
win_keyval, extra_state, 0, NULL);
59+
win_keyval, extra_state, flags, NULL);
5660
OMPI_ERRHANDLER_NOHANDLE_RETURN(ret, MPI_ERR_OTHER, FUNC_NAME);
5761
}

0 commit comments

Comments
 (0)