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

mmap shared memory transport #1086

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -707,3 +707,38 @@ jobs:
make check TESTS= -j
SHMEM_DEBUG=1 SHMEM_INFO=1 make VERBOSE=1 TEST_RUNNER="${SOS_PM} -np 2" check
${SOS_PM} -np 1 modules/tests-sos/test/unit/hello

mmap_only:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
include:
- config_name: transport_none
sos_config: [--enable-mmap --enable-shr-atomics --enable-error-checking --enable-pmi-simple]

steps:
- name: Checking OS version
run: |
echo "OS_NAME=$(lsb_release -si)-$(ls_release -sr)" >> $GITHUB_ENV
- uses: actions/checkout@v2
- name: Install dependencies
run: |
sudo apt-get install -y gfortran mpich libmpich-dev libev-dev libev-libevent-dev
sudo sysctl -w kernel.yama.ptrace_scope=0
sudo sysctl -w kernel.randomize_va_space=0

# SOS
- name: Build SOS (${{ matrix.name }})
run: |
./autogen.sh
mkdir build; cd build
../configure --prefix=${SOS_INSTALL_DIR} ${{ matrix.sos_config }}
make -j
make install
- name: Test SOS (${{ matrix.name }})
run: |
cd build
make check TESTS= -j
SHMEM_DEBUG=1 SHMEM_INFO=1 make VERBOSE=1 TEST_RUNNER="${SOS_PM} -np 2" check
cat modules/tests-sos/test/unit/hello.log
62 changes: 49 additions & 13 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ AC_ARG_ENABLE([memcpy],
[AC_HELP_STRING([--enable-memcpy],
[Use memcpy to perform local put/get operations (default:disabled)])])

AC_ARG_ENABLE([mmap],
[AC_HELP_STRING([--enable-mmap],
[Use mmap to share symmetric data and heap segments in shared memory (default:disabled)])])

AC_ARG_ENABLE([ofi-fence],
[AC_HELP_STRING([--enable-ofi-fence],
[Use FI_FENCE feature to optimize put-with-signal operations. (default: disabled)])])
Expand Down Expand Up @@ -476,7 +480,7 @@ else
transport_portals4="no"
transport_ofi="no"
transport_ucx="no"
AC_MSG_WARN([No transport requested])
AC_MSG_WARN([No network transport requested])
fi

AM_CONDITIONAL([USE_PORTALS4], [test "$transport_portals4" = "yes"])
Expand All @@ -491,38 +495,59 @@ CHECK_CMA(
[transport_cma="yes"],
[transport_cma="no"])

# If both XPMEM and CMA requested, user needs to choose one:
if test -n "$with_xpmem" -a "$with_xpmem" != "no" -a -n "$with_cma" -a "$with_cma" != "no" ; then
AC_MSG_ERROR([Cannot choose both XPMEM and CMA transports, see --help for details])
# Check which was requested, XPMEM or CMA:

num_shared_transports=0
if test -n "$with_xpmem" -a "$with_xpmem" != "no" ; then
((num_shared_transports+=1))
fi
if test -n "$with_cma" -a "$with_cma" != "no" ; then
((num_shared_transports+=1))
fi
if test -n "$enable_mmap" -a "$enable_mmap" != "no" ; then
((num_shared_transports+=1))
fi

# If more than one shared memory transport requested, user needs to choose one:
if [[ $num_shared_transports -gt 1 ]] ; then
echo "Selected" $num_shared_transports "shared memory transports, please choose one."
AC_MSG_ERROR([Only one shared memory transport is allowed (mmap, XPMEM, or CMA), see --help for details])
elif test -n "$enable_mmap" -a "$enable_mmap" != "no" ; then
transport_mmap="yes"
transport_cma="no"
transport_xpmem="no"
AC_DEFINE([USE_MMAP], [1], [Define if mmap transport is active])
AC_CHECK_LIB(rt, shm_open, [MMAP_LDFLAGS="-lrt"])
AC_SUBST([MMAP_LDFLAGS])
elif test -n "$with_xpmem" -a "$with_xpmem" != "no" ; then
transport_mmap="no"
transport_cma="no"
AC_DEFINE([USE_XPMEM], [1], [Define if XPMEM transport is active])
elif test -n "$with_cma" -a "$with_cma" != "no" ; then
transport_mmap="no"
transport_xpmem="no"
AC_DEFINE([USE_CMA], [1], [Define if Cross Memory Attach transport is active])
AC_DEFINE([_GNU_SOURCE], [1], [CMA transport header requires global definition of _GNU_SOURCE])
# If neither, disable XPMEM and CMA:
else
transport_mmap="no"
transport_xpmem="no"
transport_cma="no"
AC_MSG_RESULT([Neither XPMEM nor CMA transport requested])

AC_MSG_RESULT([Shared memory transport not requested])
fi

if test "$enable_memcpy" = "yes" -a "$transport_xpmem" = "no" -a "$transport_cma" = "no" ; then
if test "$enable_memcpy" = "yes" -a "$transport_xpmem" = "no" -a "$transport_cma" = "no" -a "$transport_mmap" = "no" ; then
transport_memcpy="yes"
AC_DEFINE([USE_MEMCPY], [1], [Define to use memcpy for local put/get communication])
elif test "$transport_xpmem" = "yes" -o "$transport_cma" = "yes" ; then
elif test "$transport_xpmem" = "yes" -o "$transport_cma" = "yes" -o "$transport_mmap" = "yes" ; then
transport_memcpy="yes"
else
transport_memcpy="no"
fi

AM_CONDITIONAL([USE_XPMEM], [test "$transport_xpmem" = "yes"])
AM_CONDITIONAL([USE_CMA], [test "$transport_cma" = "yes"])
AM_CONDITIONAL([USE_MMAP], [test "$transport_mmap" = "yes"])

AS_IF([test "$transport_xpmem" = "yes" -o "$transport_cma" = "yes"],
AS_IF([test "$transport_xpmem" = "yes" -o "$transport_cma" = "yes" -o "$transport_mmap" = "yes"],
[AC_DEFINE([USE_ON_NODE_COMMS], [1], [Define if any on-node comm transport is available])
AC_DEFINE([ENABLE_HARD_POLLING], [1], [Enable hard polling])
])
Expand All @@ -533,7 +558,7 @@ else
transport_shr_atomics="no"
fi

if test "$enable_shr_atomics" != "no" -a "$transport_xpmem" = "yes" -a "$transport" = "none"; then
if [[[ "$enable_shr_atomics" != "no" && ( "$transport_xpmem" = "yes" || "$transport_mmap" = "yes" ) && "$transport" = "none" ]]]; then
transport_shr_atomics="yes"
AC_DEFINE([USE_SHR_ATOMICS], [1], [If defined, the shared memory layer will perform processor atomics.])
fi
Expand Down Expand Up @@ -870,6 +895,9 @@ fi
if test -n "$with_xpmem" -a "$with_xpmem" != "no" -a "$with_xpmem" != "yes" ; then
DISTCHECK_CONFIGURE_FLAGS="$DISTCHECK_CONFIGURE_FLAGS --with-xpmem=${with_xpmem}"
fi
if test -n "$enable_mmap" -a "$enable_mmap" != "no" -a "$enable_mmap" != "yes" ; then
DISTCHECK_CONFIGURE_FLAGS="$DISTCHECK_CONFIGURE_FLAGS --enable-mmap=${enable_mmap}"
fi
if test -n "$with_pmi" -a "$with_pmi" != "no" -a "$with_pmi" != "yes" ; then
DISTCHECK_CONFIGURE_FLAGS="$DISTCHECK_CONFIGURE_FLAGS --with-pmi=${with_pmi}"
fi
Expand Down Expand Up @@ -932,6 +960,13 @@ fi
if test -n "opal_hwloc_LDFLAGS"; then
WRAPPER_COMPILER_EXTRA_LDFLAGS="$WRAPPER_COMPILER_EXTRA_LDFLAGS $opal_hwloc_LDFLAGS"
fi
if test "$transport_mmap" = "yes" ; then
CPPFLAGS="$CPPFLAGS $MMAP_CPPFLAGS"
LDFLAGS="$LDFLAGS $MMAP_LDFLAGS"
LIBS="$LIBS $MMAP_LIBS"
WRAPPER_COMPILER_EXTRA_LDFLAGS="$MMAP_LDFLAGS"
WRAPPER_COMPILER_EXTRA_LIBS="$MMAP_LIBS"
fi

CPPFLAGS="$CPPFLAGS $pmi_CPPFLAGS"
LDFLAGS="$LDFLAGS $pmi_LDFLAGS $aslr_LDFLAGS"
Expand Down Expand Up @@ -985,7 +1020,7 @@ AS_IF([test "$enable_pmi_mpi" != "yes" -a "$enable_pmi_simple" != "yes" -a "$opa
[AC_MSG_ERROR([No PMI client interface was configured, consider --enable-pmi-simple or --with-pmi])])

AS_IF([test -z "$num_transports"],
[AC_MSG_WARN([No transport found, resulting library will be unable to exchange messages])])
[AC_MSG_WARN([No network transport found, library will be unable to exchange remote messages])])

AS_IF([test "$shmem_cv_c11_works" != "yes"],
[AC_MSG_WARN([C compiler does not support _Generic, unable to verify and test C11 bindings])])
Expand Down Expand Up @@ -1025,6 +1060,7 @@ echo ""
echo "On Node Communication:"
echo " XPMEM: $transport_xpmem"
echo " CMA: $transport_cma"
echo " mmap: $transport_mmap"
echo " memcpy (self): $transport_memcpy"
echo " Shr. atomics: $transport_shr_atomics"
echo ""
Expand Down
6 changes: 6 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ libsma_la_SOURCES += \
transport_cma.c
endif

if USE_MMAP
libsma_la_SOURCES += \
transport_mmap.h \
transport_mmap.c
endif

if USE_PMI_SIMPLE
AM_CPPFLAGS += -I$(top_srcdir)/pmi-simple
libsma_la_SOURCES += \
Expand Down
2 changes: 2 additions & 0 deletions src/shmem_remote_pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ shmem_internal_ptr(const void *target, int pe)
if (-1 != (node_rank = shmem_internal_get_shr_rank(pe))) {
#if USE_XPMEM
return shmem_transport_xpmem_ptr(target, pe, node_rank);
#elif USE_MMAP
return shmem_transport_mmap_ptr(target, pe, node_rank);
#else
return NULL;
#endif
Expand Down
37 changes: 37 additions & 0 deletions src/shr_transport.h4
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ include(shmem_bind_c.m4)dnl
#include "transport_cma.h"
#endif

#ifdef USE_MMAP
#include "transport_mmap.h"
#endif

static inline int
shmem_shr_transport_init(void)
{
Expand All @@ -41,6 +45,11 @@ shmem_shr_transport_init(void)
ret = shmem_transport_cma_init();
if (0 != ret)
RETURN_ERROR_MSG("CMA init failed (%d)\n", ret);

#elif USE_MMAP
ret = shmem_transport_mmap_init();
if (0 != ret)
RETURN_ERROR_MSG("mmap init failed (%d)\n", ret);
#endif

return ret;
Expand All @@ -63,6 +72,12 @@ shmem_shr_transport_startup(void)
if (0 != ret) {
RETURN_ERROR_MSG("CMA startup failed (%d)\n", ret);
}

#elif USE_MMAP
ret = shmem_transport_mmap_startup();
if (0 != ret) {
RETURN_ERROR_MSG("mmap startup failed (%d)\n", ret);
}
#endif

return ret;
Expand All @@ -76,6 +91,8 @@ shmem_shr_transport_fini(void)
shmem_transport_xpmem_fini();
#elif USE_CMA
shmem_transport_cma_fini();
#elif USE_MMAP
shmem_transport_mmap_fini();
#endif
}

Expand All @@ -87,6 +104,8 @@ shmem_shr_transport_ptr(void *target, int noderank, void **local_ptr)
{
#if USE_XPMEM
XPMEM_GET_REMOTE_ACCESS(target, noderank, *local_ptr);
#elif USE_MMAP
MMAP_GET_REMOTE_ACCESS(target, noderank, *local_ptr);
#else
RAISE_ERROR_MSG("No path to peer (%d)\n", noderank);
#endif
Expand Down Expand Up @@ -147,6 +166,10 @@ shmem_shr_transport_put_scalar(shmem_ctx_t ctx, void *target,
#elif USE_CMA
shmem_transport_cma_put(target, source, len, pe,
shmem_internal_get_shr_rank(pe));

#elif USE_MMAP
shmem_transport_mmap_put(target, source, len, pe,
shmem_internal_get_shr_rank(pe));
#else
RAISE_ERROR_STR("No path to peer");
#endif
Expand All @@ -165,6 +188,10 @@ shmem_shr_transport_put(shmem_ctx_t ctx, void *target, const void *source,
#elif USE_CMA
shmem_transport_cma_put(target, source, len, pe,
shmem_internal_get_shr_rank(pe));

#elif USE_MMAP
shmem_transport_mmap_put(target, source, len, pe,
shmem_internal_get_shr_rank(pe));
#else
RAISE_ERROR_STR("No path to peer");
#endif
Expand All @@ -183,6 +210,10 @@ shmem_shr_transport_get(shmem_ctx_t ctx, void *target, const void *source,
#elif USE_CMA
shmem_transport_cma_get(target, source, len, pe,
shmem_internal_get_shr_rank(pe));

#elif USE_MMAP
shmem_transport_mmap_get(target, source, len, pe,
shmem_internal_get_shr_rank(pe));
#else
RAISE_ERROR_STR("No path to peer");
#endif
Expand Down Expand Up @@ -577,6 +608,12 @@ shmem_shr_transport_put_signal(shmem_ctx_t ctx, void *target,
shmem_internal_get_shr_rank(pe));
shmem_internal_membar_acq_rel(); /* Memory fence to ensure target PE observes
stores in the correct order */
#elif USE_MMAP
shmem_transport_mmap_put(target, source, len, pe,
shmem_internal_get_shr_rank(pe));
shmem_internal_membar_acq_rel(); /* Memory fence to ensure target PE observes
stores in the correct order */

#if USE_SHR_ATOMICS
if (sig_op == SHMEM_SIGNAL_ADD)
shmem_shr_transport_atomic(ctx, sig_addr, &signal, sizeof(uint64_t),
Expand Down
Loading
Loading