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
hack in the case that it is used. This is pretty horrible, and should be
cleaned up sooner rather than later.
  • Loading branch information
aws-nslick committed Oct 4, 2024
1 parent 05c874e commit 44ddf9d
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions include/nccl_ofi_mr.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,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 @@ -101,29 +102,23 @@ static inline uintptr_t nccl_ofi_mr_ckey_len(nccl_ofi_mr_ckey_ref ckey)
#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)
{
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

0 comments on commit 44ddf9d

Please sign in to comment.