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

use C++ for unit tests #646

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/distcheck.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:

- name: Install hwloc, utilities.
run: |
yum -y install hwloc-devel autoconf automake libtool gcc g++ git make
yum -y install hwloc-devel autoconf automake libtool gcc gcc-c++ git make

- name: Install CUDA
if: matrix.sdk == 'cuda'
Expand Down
20 changes: 18 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ NCCL_NET_OFI_DISTCHCK_CONFIGURE_FLAGS=
# Checks for programs
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CXX
m4_version_prereq([2.70], [], [AC_PROG_CC_STDC])
AC_C_INLINE

Expand All @@ -55,12 +56,18 @@ dnl between this and AC_PROG_CC.
AS_IF([test "${ax_enable_debug}" = "no"], [
dnl Enable O3 optimization
CFLAGS="${CFLAGS} -O3"
CXXFLAGS="${CXXFLAGS} -O3"

dnl use C++17, disable exceptions, and disable runtime type information
CXXFLAGS="-std=c++17 -fno-rtti -fno-exceptions"

dnl dead code elim
CFLAGS="${CFLAGS} -ffunction-sections -fdata-sections"
CXXFLAGS="${CXXFLAGS} -ffunction-sections -fdata-sections"

dnl https://maskray.me/blog/2021-05-09-fno-semantic-interposition
CFLAGS="${CFLAGS} -fno-semantic-interposition -fvisibility=hidden"
CXXFLAGS="${CXXFLAGS} -fno-semantic-interposition -fvisibility=hidden "
LDFLAGS="${LDFLAGS} -Bsymbolic"
])
CHECK_ENABLE_SANITIZER()
Expand Down Expand Up @@ -175,10 +182,15 @@ AS_IF([test "${enable_trace}" = "yes" ],
AC_DEFINE_UNQUOTED([OFI_NCCL_TRACE], [${trace}], [Defined to 1 unit test output should include TRACE level])

picky_cflags=""
picky_cxxflags=""
AC_DEFUN([ADD_PICKY_FLAGS],[
AC_LANG_PUSH([C])
AX_CHECK_COMPILE_FLAG([$1], [picky_cflags="${picky_cflags} $1"], [], [-Werror])
AC_LANG_POP()

AC_LANG_PUSH([C++])
AX_CHECK_COMPILE_FLAG([$1], [picky_cxxflags="${picky_cxxflags} $1"], [], [-Werror -x c++])
AC_LANG_POP()
])

dnl standard and normal
Expand Down Expand Up @@ -220,17 +232,21 @@ AC_ARG_ENABLE([picky-compiler],
AS_IF([test "${enable_picky_compiler}" != "no"],
[AC_MSG_NOTICE([Adding ${picky_cflags} to CFLAGS.])
CFLAGS="${CFLAGS} ${picky_cflags}"
CXXFLAGS="${CXXFLAGS} ${picky_cxxflags}"
AS_UNSET([picky_cxxflags])
AS_UNSET([picky_cflags])])

werror_flags="-Werror"
AC_ARG_ENABLE([werror],
[AS_HELP_STRING([--enable-werror], [(Developer) Enable setting -Werror. Off by default, unless building from Git tree.])])
AS_IF([test -d "${srcdir}/.git" -a -z "${enable_werror}"],
[AC_MSG_NOTICE([Found .git directory. Adding ${werror_flags} to CFLAGS.])
CFLAGS="${werror_flags} ${CFLAGS}"],
CXXFLAGS="${werror_flags} ${CXXFLAGS} "
CFLAGS="${werror_flags} ${CFLAGS} "],
[test "${enable_werror}" = "yes"],
[AC_MSG_NOTICE([Adding ${werror_flags} to CFLAGS.])
CFLAGS="${werror_flags} ${CFLAGS}"])
CXXFLAGS="${werror_flags} ${CXXFLAGS} "
CFLAGS="${werror_flags} ${CFLAGS} "])

AC_SUBST([NCCL_NET_OFI_DISTCHCK_CONFIGURE_FLAGS])

Expand Down
2 changes: 2 additions & 0 deletions include/nccl_ofi_config_bottom.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef NCCL_OFI_CONFIG_BOTTOM_H
#define NCCL_OFI_CONFIG_BOTTOM_H

#define NCCL_OFI_N_NVTX_DOMAIN_PER_COMM 8

/* configure aborts if __buildin_expect() isn't available */
#define OFI_LIKELY(x) __builtin_expect((x), 1)
#define OFI_UNLIKELY(x) __builtin_expect((x), 0)
Expand Down
39 changes: 17 additions & 22 deletions include/nccl_ofi_mr.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ enum nccl_ofi_mr_ckey_type {
typedef enum nccl_ofi_mr_ckey_type nccl_ofi_mr_ckey_type_t;

struct nccl_ofi_mr_ckey {
const union {
const struct iovec iovec;
union {
struct iovec iovec;
#if HAVE_DECL_FI_MR_DMABUF
const struct fi_mr_dmabuf fi_mr_dmabuf;
struct fi_mr_dmabuf fi_mr_dmabuf;
#endif
};
const enum nccl_ofi_mr_ckey_type type;
enum nccl_ofi_mr_ckey_type type;
};

typedef struct nccl_ofi_mr_ckey nccl_ofi_mr_ckey_t;
typedef struct nccl_ofi_mr_ckey const *const nccl_ofi_mr_ckey_ref;

Expand Down Expand Up @@ -118,30 +119,24 @@ static inline void nccl_ofi_mr_ckey_round(size_t *len, void **base_addr, const c
#if HAVE_DECL_FI_MR_DMABUF
static inline nccl_ofi_mr_ckey_t nccl_ofi_mr_ckey_mk_dmabuf(int fd, uint64_t offset, size_t len, void *base_addr)
{
return (nccl_ofi_mr_ckey_t){
.fi_mr_dmabuf =
{
.fd = fd,
.offset = offset,
.len = len,
.base_addr = base_addr,
},
.type = NCCL_OFI_MR_CKEY_DMABUF,
};
nccl_ofi_mr_ckey_t cache_key = {};
cache_key.fi_mr_dmabuf.fd = fd;
cache_key.fi_mr_dmabuf.offset = offset;
cache_key.fi_mr_dmabuf.len = len;
cache_key.fi_mr_dmabuf.base_addr = base_addr;
cache_key.type = NCCL_OFI_MR_CKEY_DMABUF;
return cache_key;
}
#endif

static inline nccl_ofi_mr_ckey_t nccl_ofi_mr_ckey_mk_vec(void *iov_base, size_t iov_len)
{
nccl_ofi_mr_ckey_round(&iov_len, &iov_base, "iovec");
return (nccl_ofi_mr_ckey_t){
.iovec =
{
.iov_base = iov_base,
.iov_len = iov_len,
},
.type = NCCL_OFI_MR_CKEY_IOVEC,
};
nccl_ofi_mr_ckey_t cache_key = {};
cache_key.iovec.iov_base = iov_base;
cache_key.iovec.iov_len = iov_len;
cache_key.type = NCCL_OFI_MR_CKEY_IOVEC;
return cache_key;
}

static inline void nccl_ofi_mr_ckey_fill_mr_attrs(nccl_ofi_mr_ckey_ref ckey, struct fi_mr_attr *attrs, uint64_t *flags)
Expand Down
16 changes: 10 additions & 6 deletions include/nccl_ofi_rdma.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
extern "C" {
#endif

#include "config.h"

#include <rdma/fabric.h>

#include "nccl_ofi.h"
#include "nccl_ofi_log.h"
#include "nccl_ofi_scheduler.h"
#include "nccl_ofi_msgbuff.h"
#include "nccl_ofi_topo.h"
#include "nccl_ofi_deque.h"
#include "nccl_ofi_ep_addr_list.h"
#include "nccl_ofi_freelist.h"
#include "nccl_ofi_idpool.h"
#include "nccl_ofi_tracepoint.h"
#include "nccl_ofi_ep_addr_list.h"
#include "nccl_ofi_log.h"
#include "nccl_ofi_msgbuff.h"
#include "nccl_ofi_scheduler.h"
#include "nccl_ofi_topo.h"
#if HAVE_NVTX_TRACING
#include <nvtx3/nvToolsExt.h>
#endif

/* Maximum number of rails supported. This defines the size of
* messages exchanged during connection establishment (linear
Expand Down
2 changes: 0 additions & 2 deletions include/tracing_impl/nvtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#if HAVE_NVTX_TRACING
#include <nvtx3/nvToolsExt.h>

#define NCCL_OFI_N_NVTX_DOMAIN_PER_COMM 8

static inline void nvtx_mark_domain(nvtxDomainHandle_t domain, const char* name, uint32_t color)
{
nvtxEventAttributes_t eventAttrib = {};
Expand Down
3 changes: 3 additions & 0 deletions m4/check_pkg_mpi.m4
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ AC_DEFUN([CHECK_PKG_MPI], [
LDFLAGS="${MPI_LDFLAGS} ${LDFLAGS}"])
MPICC=${mpi_bindir}mpicc
MPICXX=${mpi_bindir}mpicxx
AC_MSG_CHECKING([for working mpicc])
${MPICC} --help >& AS_MESSAGE_LOG_FD
AS_IF([test $? -eq 0],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])
MPICC="${CC}"
MPICXX="${CXX}"
AS_IF([test "${check_pkg_found}" = "yes"],
[AC_CHECK_HEADERS([mpi.h], [], [check_pkg_found=no])])
Expand All @@ -49,6 +51,7 @@ AC_DEFUN([CHECK_PKG_MPI], [
[$2])
AC_SUBST([MPICC])
AC_SUBST([MPICXX])
AC_SUBST([MPI_CPPFLAGS])
AC_SUBST([MPI_LDFLAGS])
AC_SUBST([MPI_LIBS])
Expand Down
9 changes: 5 additions & 4 deletions tests/functional/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ AM_CPPFLAGS += $(MPI_CPPFLAGS) $(CUDA_CPPFLAGS)
AM_LDFLAGS = $(MPI_LDFLAGS) $(CUDA_LDFLAGS)
LDADD = $(top_builddir)/src/libinternal_net_plugin.la $(MPI_LIBS) $(CUDA_LIBS)
CC = $(MPICC)
CXX = $(MPICXX)

if ENABLE_FUNC_TESTS
noinst_HEADERS = test-common.h
noinst_HEADERS = test-common.hpp

bin_PROGRAMS = nccl_connection nccl_message_transfer ring

nccl_connection_SOURCES = nccl_connection.c
nccl_message_transfer_SOURCES = nccl_message_transfer.c
ring_SOURCES = ring.c
nccl_connection_SOURCES = nccl_connection.cc
nccl_message_transfer_SOURCES = nccl_message_transfer.cc
ring_SOURCES = ring.cc
endif
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "config.h"

#include "test-common.h"
#include "test-common.hpp"

int main(int argc, char* argv[])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@

#include "config.h"

#include "test-common.h"
#include "test-common.hpp"

#define PROC_NAME_IDX(i) (i * MPI_MAX_PROCESSOR_NAME)

int main(int argc, char* argv[])
{
ncclResult_t res = ncclSuccess;
int rank, proc_name_len, num_ranks = 0, local_rank = 0, peer_rank = 0;
int rank, proc_name_len, num_ranks = 0, peer_rank = 0;
/* Unused when trace prints are not enabled. */
[[maybe_unused]] int local_rank = 0;
int buffer_type = NCCL_PTR_HOST;
test_nccl_properties_t props = {};

Expand Down Expand Up @@ -390,7 +392,7 @@ int main(int argc, char* argv[])
MPI_Finalize();
NCCL_OFI_INFO(NCCL_NET, "Test completed successfully for rank %d", rank);

exit:;
exit:

ncclResult_t close_res = ncclSuccess;

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/ring.c → tests/functional/ring.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "config.h"

#include "test-common.h"
#include "test-common.hpp"

#define PROC_NAME_IDX(i) (i * MPI_MAX_PROCESSOR_NAME)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include "nccl_ofi_math.h"
#include "nccl_ofi_param.h"


template <typename T>
constexpr T PROC_NAME_IDX(T i) { return i * MPI_MAX_PROCESSOR_NAME; };

#define STR2(v) #v
#define STR(v) STR2(v)

Expand Down
18 changes: 9 additions & 9 deletions tests/unit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/include
AM_CPPFLAGS += -isystem $(abs_top_srcdir)/3rd-party/nccl/$(DEVICE_INTERFACE)/include
AM_CPPFLAGS += -isystem $(abs_top_srcdir)/3rd-party/uthash/include
LDADD = $(top_builddir)/src/libinternal_net_plugin.la
noinst_HEADERS = test-common.h
noinst_HEADERS = test-common.hpp

noinst_PROGRAMS = \
deque \
Expand All @@ -26,21 +26,21 @@ if WANT_PLATFORM_AWS
AM_CPPFLAGS += $(CUDA_CPPFLAGS)
LDADD += $(CUDA_LIBS)
noinst_PROGRAMS += show_tuner_decisions
show_tuner_decisions_SOURCES = show_tuner_decisions.c
show_tuner_decisions_SOURCES = show_tuner_decisions.cc
show_tuner_decisions_LDADD = $(top_builddir)/src/libinternal_tuner_plugin.la
noinst_PROGRAMS += region_based_tuner
region_based_tuner_SOURCES = region_based_tuner.c
region_based_tuner_LDADD = $(top_builddir)/src/libinternal_tuner_plugin.la
endif
endif

idpool_SOURCES = idpool.c
deque_SOURCES = deque.c
freelist_SOURCES = freelist.c
msgbuff_SOURCES = msgbuff.c
scheduler_SOURCES = scheduler.c
ep_addr_list_SOURCES = ep_addr_list.c
mr_SOURCES = mr.c
idpool_SOURCES = idpool.cc
deque_SOURCES = deque.cc
freelist_SOURCES = freelist.cc
msgbuff_SOURCES = msgbuff.cc
scheduler_SOURCES = scheduler.cc
ep_addr_list_SOURCES = ep_addr_list.cc
mr_SOURCES = mr.cc

TESTS = $(noinst_PROGRAMS)
endif
2 changes: 1 addition & 1 deletion tests/unit/deque.c → tests/unit/deque.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <stdio.h>

#include "test-common.h"
#include "test-common.hpp"
#include "nccl_ofi_deque.h"

#define test_get_front(deque, expected) \
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/freelist.c → tests/unit/freelist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <stdio.h>

#include "test-common.h"
#include "test-common.hpp"
#include "nccl_ofi_freelist.h"

void *simple_base;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/idpool.c → tests/unit/idpool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <stdio.h>

#include "test-common.h"
#include "test-common.hpp"
#include "nccl_ofi_idpool.h"
#include "nccl_ofi_math.h"

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/mr.c → tests/unit/mr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <stdlib.h>

#include "test-common.h"
#include "test-common.hpp"
#include "nccl_ofi_mr.h"

static inline bool test_lookup_impl(nccl_ofi_mr_cache_t *cache, void *addr, size_t size,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/msgbuff.c → tests/unit/msgbuff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "nccl_ofi_msgbuff.h"

#include "test-common.h"
#include "test-common.hpp"

int main(int argc, char *argv[])
{
Expand Down
Loading
Loading