Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cffi: typedef shmem_{ctx|team}_t as an opaque struct type #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dalcinl
Copy link
Member

@dalcinl dalcinl commented Aug 1, 2023

This allows for OpenSHMEM implementations declaring ctx/team types as either a pointer types or an integral types.

Declaring shmem_{ctx|team}_t as an opaque struct type has an annoying side-effect: now ctx/team handles can no longer be compared for equality. Therefore, add a couple auxiliary functions eq_{ctx|team} to compare handles for equality. Additionally, in case we need them in the future, add functions to convert to/from integer values.

This allows for OpenSHMEM implementations declaring ctx/team types as
either a pointer types or an integral types.

Declaring `shmem_{ctx|team}_t` as an opaque struct type has an annoying
side-effect: now ctx/team handles can no longer be compared for equality.
Therefore, add a couple auxiliary functions `eq_{ctx|team}` to compare
handles for equality. Additionally, in case we need them in the future,
add functions to convert to/from integer values.
@dalcinl dalcinl added the enhancement New feature or request label Aug 1, 2023
@dalcinl dalcinl self-assigned this Aug 1, 2023
@dalcinl
Copy link
Member Author

dalcinl commented Aug 1, 2023

@jeffhammond I managed to find a way to address our Cray issue, albeit at the expense of slightly uglier implementation code in the Python side.

@jeffhammond
Copy link
Collaborator

This is what worked on LUMI:

diff --git a/src/apicodegen.py b/src/apicodegen.py
index e6acec0..d0ece31 100644
--- a/src/apicodegen.py
+++ b/src/apicodegen.py
@@ -23,8 +23,8 @@ typename_to_type = {
     'float':      'float',
     'double':     'double',
     'longdouble': 'long double',
-    'complexf':   'float _Complex',
-    'complexd':   'double _Complex',
+    #'complexf':   'float _Complex',
+    #'complexd':   'double _Complex',
 }

 typesizes_rma = (
@@ -122,8 +122,8 @@ typenames_reduce = {
     'float':      "           max min sum prod".split(),
     'double':     "           max min sum prod".split(),
     'longdouble': "           max min sum prod".split(),
-    'complexd':   "                   sum prod".split(),
-    'complexf':   "                   sum prod".split(),
+    #'complexd':   "                   sum prod".split(),
+    #'complexf':   "                   sum prod".split(),
 }


@@ -213,7 +213,7 @@ int shmem_alltoallsmem(shmem_team_t team, void *dest, const void *source, ptrdif

 reduce_ops = ('and', 'or', 'xor', 'max', 'min', 'sum', 'prod')
 reduce_team = """
-int shmem_{TYPENAME}_{OP}_reduce(shmem_team_t team, {TYPE} *dest, const {TYPE} *source, size_t nreduce);
+void shmem_{TYPENAME}_{OP}_reduce(shmem_team_t team, {TYPE} *dest, const {TYPE} *source, size_t nreduce);
 """  # noqa

 wait = """
diff --git a/src/libshmem/config/cray.h b/src/libshmem/config/cray.h
index db66c31..01ed740 100644
--- a/src/libshmem/config/cray.h
+++ b/src/libshmem/config/cray.h
@@ -1,4 +1,27 @@
 #ifndef PySHMEM_CONFIG_CRAY_H
 #define PySHMEM_CONFIG_CRAY_H

+#if CRAY_SHMEM_MAJOR_VERSION >= 11
+#define PySHMEM_HAVE_shmem_malloc_with_hints 1
+#define PySHMEM_HAVE_shmem_team_t 1
+#define PySHMEM_HAVE_SHMEM_CTX_INVALID 1
+#define PySHMEM_HAVE_shmem_amo_nbi 1
+#define PySHMEM_HAVE_shmem_put_signal 1
+#define PySHMEM_HAVE_shmem_signal_fetch 1
+#define PySHMEM_HAVE_shmem_signal_wait_until 1
+#define PySHMEM_HAVE_shmem_broadcast 1
+#define PySHMEM_HAVE_shmem_collect 1
+#define PySHMEM_HAVE_shmem_fcollect 1
+#define PySHMEM_HAVE_shmem_alltoall 1
+#define PySHMEM_HAVE_shmem_alltoalls 1
+#define PySHMEM_HAVE_shmem_broadcastmem 1
+#define PySHMEM_HAVE_shmem_collectmem 1
+#define PySHMEM_HAVE_shmem_fcollectmem 1
+#define PySHMEM_HAVE_shmem_alltoallmem 1
+#define PySHMEM_HAVE_shmem_alltoallsmem 1
+#define PySHMEM_HAVE_shmem_reduce 1
+#define PySHMEM_HAVE_shmem_wait_test_many 1
+//#define PySHMEM_HAVE_shmem_pcontrol 1
+#endif
+
 #endif
diff --git a/src/libshmem/fallback.h b/src/libshmem/fallback.h
index 808fd74..f291abd 100644
--- a/src/libshmem/fallback.h
+++ b/src/libshmem/fallback.h
@@ -658,8 +658,8 @@ PySHMEM_REDUCE_2(longlong,   long long)
 PySHMEM_REDUCE_2(float,      float)
 PySHMEM_REDUCE_2(double,     double)
 PySHMEM_REDUCE_2(longdouble, long double)
-PySHMEM_REDUCE_1(complexf,   float _Complex)
-PySHMEM_REDUCE_1(complexd,   double _Complex)
+//PySHMEM_REDUCE_1(complexf,   float _Complex)
+//PySHMEM_REDUCE_1(complexd,   double _Complex)

 #define PySHMEM_REDUCE_UINT_OP(TYPENAME, TYPE, OP)                      \
 static                                                                  \
diff --git a/src/shmem4py/shmem.py b/src/shmem4py/shmem.py
index 67087c9..756d058 100644
--- a/src/shmem4py/shmem.py
+++ b/src/shmem4py/shmem.py
@@ -2263,7 +2263,7 @@ def reduce(
     team_ = team.ob_team if team is not None else lib.SHMEM_TEAM_WORLD
     ctype, target, source, size = _parse_reduce(target, source, size)
     shmem_reduce = _shmem(None, ctype, f'{op}_reduce')
-    ierr = shmem_reduce(team_, target, source, size)
+    ierr = shmem_reduce(team_, target, source, size) or 0
     _chkerr(ierr, f"shmem_{ctype}_{op}_reduce")

@jeffhammond
Copy link
Collaborator

the complex stuff is a hack. i haven't tried to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants