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

nit: deque: avoid typedef hell #561

Closed
wants to merge 8 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
4 changes: 2 additions & 2 deletions include/nccl-headers/neuron/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef NCCL_HEADERS_NEURON_ERROR_H_
#define NCCL_HEADERS_NEURON_ERROR_H_

#ifdef _cplusplus
#ifdef __cplusplus
extern "C" {
#endif

Expand All @@ -21,7 +21,7 @@ typedef enum {
ncclRemoteError = 6
} ncclResult_t;

#ifdef _cplusplus
#ifdef __cplusplus
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions include/nccl-headers/neuron/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef NCCL_HEADERS_NEURON_NET_H_
#define NCCL_HEADERS_NEURON_NET_H_

#ifdef _cplusplus
#ifdef __cplusplus
extern "C" {
#endif

Expand Down Expand Up @@ -100,7 +100,7 @@ typedef struct {
ncclResult_t (*closeListen)(void* listenComm);
} ncclNet_v4_t;

#ifdef _cplusplus
#ifdef __cplusplus
} // End extern "C"
#endif

Expand Down
9 changes: 4 additions & 5 deletions include/nccl_ofi.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#ifndef NCCL_OFI_H_
#define NCCL_OFI_H_

#ifdef _cplusplus

#ifdef __cplusplus
extern "C" {
#endif

Expand All @@ -23,7 +24,6 @@ extern "C" {
#include "nccl_ofi_idpool.h"
#include "nccl_ofi_mr.h"


/*
* NCCL_NET_HANDLE_MAXSIZE is a limited resource (and defined in NCCL).
* An endpoint address buffer of 56 bytes *should* be large enough to hold
Expand Down Expand Up @@ -192,8 +192,7 @@ typedef struct nccl_ofi_connection_info {
nccl_net_ofi_req_t* req;
} nccl_ofi_connection_info_t;
/* Since this is a message on the wire, check that it has the expected size */
_Static_assert(sizeof(nccl_ofi_connection_info_t) == 80,
"Wrong size for SENDRECV connect message");
static_assert(sizeof(nccl_ofi_connection_info_t) == 80, "Wrong size for SENDRECV connect message");

typedef struct nccl_net_ofi_conn_handle {
char ep_name[MAX_EP_ADDR];
Expand Down Expand Up @@ -590,7 +589,7 @@ int nccl_net_ofi_dealloc_mr_buffer(void *ptr, size_t size);
int nccl_net_ofi_query_provider_capabilities(const struct fi_info *selected_provider,
unsigned int num_providers);

#ifdef _cplusplus
#ifdef __cplusplus
} // End extern "C"
#endif

Expand Down
9 changes: 5 additions & 4 deletions include/nccl_ofi_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
#ifndef NET_OFI_API_H_
#define NET_OFI_API_H_

#include "nccl-headers/net.h"
#include "nccl-headers/error.h"

#ifdef _cplusplus
#ifdef __cplusplus
extern "C" {
#endif

#include "nccl-headers/net.h"
#include "nccl-headers/error.h"

struct nccl_ofi_properties;

ncclResult_t nccl_net_ofi_init(ncclDebugLogger_t logFunction);
Expand Down Expand Up @@ -42,7 +43,7 @@ ncclResult_t nccl_net_ofi_closeSend(void *sendComm);
ncclResult_t nccl_net_ofi_closeRecv(void *recvComm);
ncclResult_t nccl_net_ofi_closeListen(void *listenComm);

#ifdef _cplusplus
#ifdef __cplusplus
}
#endif // End extern "C"

Expand Down
8 changes: 8 additions & 0 deletions include/nccl_ofi_config_bottom.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
#define OFI_LIKELY(x) __builtin_expect((x), 1)
#define OFI_UNLIKELY(x) __builtin_expect((x), 0)

#ifdef __cplusplus
#define NCCL_OFI_EXPORT_SYMBOL __attribute__((visibility("default"))) [[maybe_unused]]
#else
#define NCCL_OFI_EXPORT_SYMBOL __attribute__((visibility("default")))
#endif

#ifndef __cplusplus
#define static_assert _Static_assert
#endif

/* Maximum length of directory path */
#ifdef HAVE_LINUX_LIMITS_H
Expand Down
5 changes: 3 additions & 2 deletions include/nccl_ofi_cuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#ifndef NCCL_OFI_CUDA_H_
#define NCCL_OFI_CUDA_H_

#ifdef _cplusplus

#ifdef __cplusplus
extern "C" {
#endif

Expand Down Expand Up @@ -41,7 +42,7 @@ extern CUresult (*nccl_net_ofi_cuFlushGPUDirectRDMAWrites)(CUflushGPUDirectRDMAW
extern void *nccl_net_ofi_cuFlushGPUDirectRDMAWrites;
#endif

#ifdef _cplusplus
#ifdef __cplusplus
} // End extern "C"
#endif

Expand Down
32 changes: 17 additions & 15 deletions include/nccl_ofi_deque.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#ifndef NCCL_OFI_DEQUE_H
#define NCCL_OFI_DEQUE_H

#ifdef _cplusplus

#ifdef __cplusplus
extern "C" {
#endif

Expand All @@ -22,21 +23,20 @@ extern "C" {
* this structure as a black box. Critically, the caller must ensure the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comment in 52a6994#r1714461159 needs to be addressed.

* contents of this structure are not modified while it is in the deque.
*/
struct nccl_ofi_deque_elem_t {
struct nccl_ofi_deque_elem {
/* Pointer to previous element */
struct nccl_ofi_deque_elem_t *prev;
struct nccl_ofi_deque_elem *prev;
/* Pointer to next element */
struct nccl_ofi_deque_elem_t *next;
struct nccl_ofi_deque_elem *next;
};
typedef struct nccl_ofi_deque_elem_t nccl_ofi_deque_elem_t;

/*
* Deque (doubly-ended queue) structure
*
* Core deque structure. This should be considered opaque to users
* of the deque interface
*/
struct nccl_ofi_deque_t {
struct nccl_ofi_deque {
/* "Head" of queue.
* The queue is circular. An empty queue has only this element. In an empty
* queue, head.prev and head.next point to head.
Expand All @@ -45,18 +45,17 @@ struct nccl_ofi_deque_t {
* front. insert_back and insert_front add elements to these respective
* locations.
*/
nccl_ofi_deque_elem_t head;
struct nccl_ofi_deque_elem head;
/* Lock for deque operations */
pthread_mutex_t lock;
};
typedef struct nccl_ofi_deque_t nccl_ofi_deque_t;

/*
* Initialize deque structure.
*
* @return zero on success, non-zero on non-success.
*/
int nccl_ofi_deque_init(nccl_ofi_deque_t **deque_p);
extern int nccl_ofi_deque_init(struct nccl_ofi_deque **deque_p);

/*
* Finalize a deque
Expand All @@ -65,15 +64,15 @@ int nccl_ofi_deque_init(nccl_ofi_deque_t **deque_p);
*
* @return zero on success, non-zero on non-success.
*/
int nccl_ofi_deque_finalize(nccl_ofi_deque_t *deque);
extern int nccl_ofi_deque_finalize(struct nccl_ofi_deque *deque);

/*
* Insert an element to the back of the deque
*
* @param deque_elem user-allocated storage space for list entry
* @return zero on success, non-zero on error
*/
static inline int nccl_ofi_deque_insert_back(nccl_ofi_deque_t *deque, nccl_ofi_deque_elem_t *deque_elem)
static inline int nccl_ofi_deque_insert_back(struct nccl_ofi_deque *deque, struct nccl_ofi_deque_elem *deque_elem)
{
assert(deque);
assert(deque_elem);
Expand All @@ -98,7 +97,7 @@ static inline int nccl_ofi_deque_insert_back(nccl_ofi_deque_t *deque, nccl_ofi_d
* @param deque_elem user-allocated storage space for list entry
* @return zero on success, non-zero on error
*/
static inline int nccl_ofi_deque_insert_front(nccl_ofi_deque_t *deque, nccl_ofi_deque_elem_t *deque_elem)
static inline int nccl_ofi_deque_insert_front(struct nccl_ofi_deque *deque, struct nccl_ofi_deque_elem *deque_elem)
{
assert(deque);
assert(deque_elem);
Expand All @@ -122,7 +121,7 @@ static inline int nccl_ofi_deque_insert_front(nccl_ofi_deque_t *deque, nccl_ofi_
*
* @return true if empty, false if not
*/
static inline bool nccl_ofi_deque_isempty(nccl_ofi_deque_t *deque)
static inline bool nccl_ofi_deque_isempty(struct nccl_ofi_deque *deque)
{
return deque->head.next == &deque->head;
}
Expand All @@ -132,7 +131,7 @@ static inline bool nccl_ofi_deque_isempty(nccl_ofi_deque_t *deque)
* @param deque_elem returned element; NULL if deque is empty or an error occurred
* @return zero on success, non-zero on non-success
*/
static inline int nccl_ofi_deque_remove_front(nccl_ofi_deque_t *deque, nccl_ofi_deque_elem_t **deque_elem)
static inline int nccl_ofi_deque_remove_front(struct nccl_ofi_deque *deque, struct nccl_ofi_deque_elem **deque_elem)
{
assert(deque);
assert(deque_elem);
Expand Down Expand Up @@ -162,7 +161,10 @@ static inline int nccl_ofi_deque_remove_front(nccl_ofi_deque_t *deque, nccl_ofi_
return 0;
}

#ifdef _cplusplus
typedef struct nccl_ofi_deque_elem nccl_ofi_deque_elem_t;
typedef struct nccl_ofi_deque nccl_ofi_deque_t;

#ifdef __cplusplus
} // End extern "C"
#endif

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

#ifdef __cplusplus
extern "C" {
#endif

struct nccl_ofi_ep_addr_list;
typedef struct nccl_ofi_ep_addr_list nccl_ofi_ep_addr_list_t;

Expand Down Expand Up @@ -76,4 +80,8 @@ int nccl_ofi_ep_addr_list_delete(nccl_ofi_ep_addr_list_t *ep_list, nccl_net_ofi_
*/
void nccl_ofi_ep_addr_list_fini(nccl_ofi_ep_addr_list_t *ep_list);

#ifdef __cplusplus
} // End extern "C"
#endif

#endif
17 changes: 9 additions & 8 deletions include/nccl_ofi_freelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#ifndef NCCL_OFI_FREELIST_H
#define NCCL_OFI_FREELIST_H

#ifdef _cplusplus

#ifdef __cplusplus
extern "C" {
#endif

Expand Down Expand Up @@ -94,9 +95,9 @@ struct nccl_ofi_freelist_reginfo_t {
};
typedef struct nccl_ofi_freelist_reginfo_t nccl_ofi_freelist_reginfo_t;

_Static_assert(offsetof(nccl_ofi_freelist_reginfo_t, elem) == 0,
static_assert(offsetof(nccl_ofi_freelist_reginfo_t, elem) == 0,
"elem is not the first member of the structure nccl_ofi_freelist_reginfo_t");
_Static_assert(sizeof(nccl_ofi_freelist_reginfo_t) - offsetof(nccl_ofi_freelist_reginfo_t, redzone) == MEMCHECK_REDZONE_SIZE,
static_assert(sizeof(nccl_ofi_freelist_reginfo_t) - offsetof(nccl_ofi_freelist_reginfo_t, redzone) == MEMCHECK_REDZONE_SIZE,
"redzone is not the last member of the structure nccl_ofi_freelist_reginfo_t");

/*
Expand Down Expand Up @@ -206,20 +207,20 @@ static inline void nccl_ofi_freelist_entry_set_undefined(nccl_ofi_freelist_t *fr
size_t redzone_offset = offsetof(struct nccl_ofi_freelist_reginfo_t, redzone);

/* Entry after reginfo structure is accessible but undefined */
nccl_net_ofi_mem_undefined_unaligned(entry_p + reginfo_offset + reginfo_size,
nccl_net_ofi_mem_undefined_unaligned((void*)((uintptr_t)entry_p + reginfo_offset + reginfo_size),
user_entry_size - reginfo_offset - reginfo_size);
/* Redzone at the end of the reginfo structure is
* marked as not accessible */
nccl_net_ofi_mem_noaccess_unaligned(entry_p + reginfo_offset + redzone_offset,
nccl_net_ofi_mem_noaccess_unaligned((void*)((uintptr_t)entry_p + reginfo_offset + redzone_offset),
MEMCHECK_REDZONE_SIZE);
/* Members of reginfo structure except first and last
* member are accessible and defined */
nccl_net_ofi_mem_defined_unaligned(entry_p + reginfo_offset + elem_size,
nccl_net_ofi_mem_defined_unaligned((void*)((uintptr_t)entry_p + reginfo_offset + elem_size),
redzone_offset - elem_size);
/* First member of reginfo structure, i.e.,
* nccl_ofi_freelist_elem_t structure, is marked as
* not accessible */
nccl_net_ofi_mem_noaccess_unaligned(entry_p + reginfo_offset, elem_size);
nccl_net_ofi_mem_noaccess_unaligned((void*)((uintptr_t)entry_p + reginfo_offset), elem_size);
/* First part of entry until reginfo structure is
* accessible but undefined */
nccl_net_ofi_mem_undefined(entry_p, reginfo_offset);
Expand Down Expand Up @@ -313,7 +314,7 @@ static inline void nccl_ofi_freelist_entry_free(nccl_ofi_freelist_t *freelist, v
nccl_net_ofi_mutex_unlock(&freelist->lock);
}

#ifdef _cplusplus
#ifdef __cplusplus
} // End extern "C"
#endif

Expand Down
6 changes: 3 additions & 3 deletions include/nccl_ofi_idpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#ifndef NCCL_OFI_IDPOOL_H_
#define NCCL_OFI_IDPOOL_H_

#ifdef _cplusplus

#ifdef __cplusplus
extern "C" {
#endif

#include <pthread.h>

#include <stdint.h>

/*
Expand Down Expand Up @@ -87,7 +87,7 @@ int nccl_ofi_idpool_free_id(nccl_ofi_idpool_t *idpool, int id);
*/
int nccl_ofi_idpool_fini(nccl_ofi_idpool_t *idpool);

#ifdef _cplusplus
#ifdef __cplusplus
} // End extern "C"
#endif

Expand Down
4 changes: 2 additions & 2 deletions include/nccl_ofi_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef NCCL_OFI_LOG_H_
#define NCCL_OFI_LOG_H_

#ifdef _cplusplus
#ifdef __cplusplus
extern "C" {
#endif

Expand All @@ -33,7 +33,7 @@ extern ncclDebugLogger_t ofi_log_function;
#define NCCL_OFI_TRACE(flags, fmt, ...)
#endif

#ifdef _cplusplus
#ifdef __cplusplus
} // End extern "C"
#endif

Expand Down
4 changes: 2 additions & 2 deletions include/nccl_ofi_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef NCCL_OFI_MATH_H_
#define NCCL_OFI_MATH_H_

#ifdef _cplusplus
#ifdef __cplusplus
extern "C" {
#endif

Expand Down Expand Up @@ -65,7 +65,7 @@ extern "C" {
*/
#define NCCL_OFI_ROUND_UP(x, y) NCCL_OFI_ROUND_DOWN((x) + ((y) - 1), (y))

#ifdef _cplusplus
#ifdef __cplusplus
} // End extern "C"
#endif

Expand Down
Loading
Loading