Skip to content

Commit

Permalink
fix(mr_ckey): add C++ compatibility with GCC7
Browse files Browse the repository at this point in the history
g++7 fails to initialize C-style tagged unions with the following error
message:

> sorry, unimplemented: non-trivial designated initializers not
> supported

Note that gcc7 handles this fine when the file is parsed as C, as well
as g++8 and beyond, and the problem only exists when operating in C++
mode under g++7. AL2 is still using this ancient toolchain, so add a
workaround in the case that it is used.
  • Loading branch information
aws-nslick committed Sep 30, 2024
1 parent f5e19b0 commit dece4bb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions include/nccl_ofi_mr.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ extern "C" {

#include <rdma/fi_domain.h>

/* AL2's GCC7 is incapable of initializing tagged unions without these
* constructors, but only in C++ mode.. */
#if defined(__cplusplus) && defined(__GNUG__) && defined(__GNUC__) && __GNUC__ < 8
#define GCC_7_CPP_COMPAT_REQUIRED 1
#else
#define GCC_7_CPP_COMPAT_REQUIRED 0
#endif

enum nccl_ofi_mr_ckey_type {
NCCL_OFI_MR_CKEY_INVALID = 0,
NCCL_OFI_MR_CKEY_IOVEC,
Expand All @@ -37,7 +45,18 @@ struct nccl_ofi_mr_ckey {
#endif
};
const enum nccl_ofi_mr_ckey_type type;

/* AL2's GCC7 is incapable of initializing tagged unions without these
* constructors, but only in C++ mode.. */
#if GCC_7_CPP_COMPAT_REQUIRED
constexpr explicit nccl_ofi_mr_ckey(void *iov_base, size_t iov_len)
: iovec{iov_base, iov_len}, type{NCCL_OFI_MR_CKEY_IOVEC} {}

constexpr explicit nccl_ofi_mr_ckey(int fd, uint64_t offset, size_t len, void *base_addr)
: fi_mr_dmabuf{fd, offset, len, base_addr}, type{NCCL_OFI_MR_CKEY_DMABUF} {}
#endif
};

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 @@ -98,6 +117,10 @@ static inline uintptr_t nccl_ofi_mr_ckey_len(nccl_ofi_mr_ckey_ref ckey)
}
}

#if GCC_7_CPP_COMPAT_REQUIRED
#define nccl_ofi_mr_ckey_mk_dmabuf nccl_ofi_mr_ckey
#define nccl_ofi_mr_ckey_mk_vec nccl_ofi_mr_ckey
#else
#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)
{
Expand Down Expand Up @@ -125,6 +148,7 @@ static inline nccl_ofi_mr_ckey_t nccl_ofi_mr_ckey_mk_vec(void *iov_base, size_t
.type = NCCL_OFI_MR_CKEY_IOVEC,
};
}
#endif

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

0 comments on commit dece4bb

Please sign in to comment.