Skip to content

Commit 340e7ad

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 b0e9261 commit 340e7ad

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
@@ -1152,7 +1152,23 @@ class TypeCommCopyAttrFunctionStandard(Type):
11521152
# pass
11531153

11541154
def type_text(self, enable_count=False):
1155-
return 'MPI_Comm_copy_attr_function *'
1155+
type_name = self.mangle_name('MPI_Comm_copy_attr_function')
1156+
return f'{type_name} *'
1157+
1158+
@property
1159+
def argument(self):
1160+
return f'(MPI_Comm_copy_attr_function *) {self.name}'
1161+
1162+
# @property
1163+
# def init_code(self):
1164+
# code = []
1165+
# code = ['ompi_abi_wrapper_helper_t *helper = NULL;']
1166+
# code.append('helper = ( ompi_abi_wrapper_helper_t *)malloc(sizeof(ompi_abi_wrapper_helper_t));')
1167+
# code.append('if (NULL == helper) return MPI_ERR_NO_MEM;')
1168+
# code.append('helper->user_extra_state = extra_state;')
1169+
# code.append('helper->user_copy_fn = comm_copy_attr_fn;')
1170+
# code.append('helper->user_delete_fn = comm_delete_attr_fn;')
1171+
# return code
11561172

11571173
@Type.add_type('COMM_DELETE_ATTR_FUNCTION', abi_type=['ompi'])
11581174
class TypeCommDeleteAttrFunction(Type):
@@ -1167,7 +1183,12 @@ class TypeCommDeleteAttrFunctionStandard(Type):
11671183
# pass
11681184

11691185
def type_text(self, enable_count=False):
1170-
return 'MPI_Comm_delete_attr_function *'
1186+
type_name = self.mangle_name('MPI_Comm_delete_attr_function')
1187+
return f'{type_name} *'
1188+
1189+
@property
1190+
def argument(self):
1191+
return f'(MPI_Comm_delete_attr_function *) {self.name}'
11711192

11721193
@Type.add_type('GREQUEST_QUERY_FUNCTION', abi_type=['ompi'])
11731194
class TypeGrequestQueryFunction(Type):
@@ -1279,7 +1300,12 @@ class TypeTypeCopyAttrFunctionStandard(Type):
12791300
# pass
12801301

12811302
def type_text(self, enable_count=False):
1282-
return 'MPI_Type_copy_attr_function *'
1303+
type_name = self.mangle_name('MPI_Type_copy_attr_function')
1304+
return f'{type_name} *'
1305+
1306+
@property
1307+
def argument(self):
1308+
return f'(MPI_Type_copy_attr_function *) {self.name}'
12831309

12841310
@Type.add_type('TYPE_DELETE_ATTR_FUNCTION', abi_type=['ompi'])
12851311
class TypeTypeDeleteAttrFunction(Type):
@@ -1294,9 +1320,15 @@ class TypeTypeDeleteAttrFunctionStandard(Type):
12941320
# pass
12951321

12961322
def type_text(self, enable_count=False):
1297-
return 'MPI_Type_delete_attr_function *'
1323+
type_name = self.mangle_name('MPI_Type_delete_attr_function')
1324+
return f'{type_name} *'
1325+
1326+
@property
1327+
def argument(self):
1328+
return f'(MPI_Type_delete_attr_function *) {self.name}'
12981329

12991330
@Type.add_type('WIN_ERRHANDLER_FUNCTION', abi_type=['ompi'])
1331+
13001332
class TypeWinErrhandlerFunction(Type):
13011333

13021334
def type_text(self, enable_count=False):
@@ -1324,7 +1356,12 @@ class TypeWinCopyAttrFunctionStandard(Type):
13241356
# pass
13251357

13261358
def type_text(self, enable_count=False):
1327-
return 'MPI_Win_copy_attr_function *'
1359+
type_name = self.mangle_name('MPI_Win_copy_attr_function')
1360+
return f'{type_name} *'
1361+
1362+
@property
1363+
def argument(self):
1364+
return f'(MPI_Win_copy_attr_function *) {self.name}'
13281365

13291366
@Type.add_type('WIN_DELETE_ATTR_FUNCTION', abi_type=['ompi'])
13301367
class TypeWinDeleteAttrFunction(Type):
@@ -1339,7 +1376,12 @@ class TypeWinDeleteAttrFunctionStandard(Type):
13391376
# pass
13401377

13411378
def type_text(self, enable_count=False):
1342-
return 'MPI_Win_delete_attr_function *'
1379+
type_name = self.mangle_name('MPI_Win_delete_attr_function')
1380+
return f'{type_name} *'
1381+
1382+
@property
1383+
def argument(self):
1384+
return f'(MPI_Win_delete_attr_function *) {self.name}'
13431385

13441386
@Type.add_type('ERRHANDLER', abi_type=['ompi'])
13451387
class TypeErrhandler(Type):
@@ -1448,23 +1490,23 @@ def type_text(self, enable_count=False):
14481490

14491491

14501492
@Type.add_type('SESSION_INOUT', abi_type=['standard'])
1451-
class TypeSessionOutStandard(StandardABIType):
1493+
class TypeSessionInOutStandard(StandardABIType):
14521494

1453-
# @property
1454-
# def init_code(self):
1455-
# return [f'MPI_Session {self.tmpname} = {ConvertFuncs.SESSION}(*{self.name});']
1495+
@property
1496+
def init_code(self):
1497+
return [f'MPI_Session {self.tmpname} = {ConvertFuncs.SESSION}(*{self.name});']
14561498

14571499
@property
14581500
def final_code(self):
1459-
return [f'*{self.name} = {ConvertOMPIToStandard.SESSION}((MPI_Session) *{self.name});']
1501+
return [f'*{self.name} = {ConvertOMPIToStandard.SESSION}({self.tmpname});']
14601502

14611503
def type_text(self, enable_count=False):
14621504
type_name = self.mangle_name('MPI_Session')
14631505
return f'{type_name} *'
14641506

14651507
@property
14661508
def argument(self):
1467-
return f'(MPI_Session *) {self.name}'
1509+
return f'&{self.tmpname}'
14681510

14691511

14701512
@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
@@ -147,7 +147,6 @@ def abi_internal_name(extname):
147147
'DATAREP_CONVERSION_FUNCTION',
148148
]
149149

150-
151150
def prototype_has_bigcount(prototype):
152151
"""Should this prototype have a bigcount version?"""
153152
return any(param.type_name in BIGCOUNT_TYPE_NAMES for param in prototype.params)
@@ -165,3 +164,17 @@ def prototype_has_buffers(prototype):
165164
return True
166165
else:
167166
return False
167+
168+
USER_CALLBACK_NAMES = [
169+
'COMM_COPY_ATTR_FUNCTION',
170+
'COMM_DELETE_ATTR_FUNCTION',
171+
'TYPE_COPY_ATTR_FUNCTION',
172+
'TYPE_DELETE_ATTR_FUNCTION',
173+
'WIN_COPY_ATTR_FUNCTION',
174+
'WIN_DELETE_ATTR_FUNCTION',
175+
]
176+
177+
def prototype_needs_callback_wrappers(prototype):
178+
"""Should this prototype need a callback wrappers"""
179+
return any(param.type_name in USER_CALLBACK_NAMES for param in prototype.params)
180+

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)