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: msgbuff: avoid typedef hell #562

Closed
wants to merge 1 commit into from
Closed
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: 21 additions & 14 deletions include/nccl_ofi_msgbuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extern "C" {
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to #561, this is not the solution we're looking for.


/* Enumeration to keep track of different msg statuses. */
typedef enum {
enum nccl_ofi_msgbuff_status {
/** The message has been marked completed **/
NCCL_OFI_MSGBUFF_COMPLETED,
/** The message has been added to the buffer but not marked complete **/
Expand All @@ -52,39 +52,40 @@ typedef enum {
NCCL_OFI_MSGBUFF_NOTSTARTED,
/** The index is not in the range of completed or not-started messages **/
NCCL_OFI_MSGBUFF_UNAVAILABLE,
} nccl_ofi_msgbuff_status_t;
};

typedef enum {
enum nccl_ofi_msgbuff_result {
/** Operation completed successfully **/
NCCL_OFI_MSGBUFF_SUCCESS,
/** The provided index was invalid; see msg_idx_status output **/
NCCL_OFI_MSGBUFF_INVALID_IDX,
/** Other error **/
NCCL_OFI_MSGBUFF_ERROR,
} nccl_ofi_msgbuff_result_t;
};

/* Type of element stored in msg buffer. This is used to distinguish between
reqs and bounce buffers (when we don't have req) stored in the message buffer */
typedef enum {
enum nccl_ofi_msgbuff_elemtype {
/* Request */
NCCL_OFI_MSGBUFF_REQ,
/* Bounce buffer */
NCCL_OFI_MSGBUFF_BUFF
} nccl_ofi_msgbuff_elemtype_t;
};

/* Internal buffer storage type, used to keep status of elements currently stored in
* buffer */
typedef struct {
struct nccl_ofi_msgbuff_elem {
// Status of message: COMPLETED, INPROGRESS, or NOTSTARTED
nccl_ofi_msgbuff_status_t stat;
enum nccl_ofi_msgbuff_status stat;
// Type of element
nccl_ofi_msgbuff_elemtype_t type;
enum nccl_ofi_msgbuff_elemtype type;
void *elem;
} nccl_ofi_msgbuff_elem_t;
};

typedef struct {

struct nccl_ofi_msgbuff {
// Element storage buffer. Allocated in msgbuff_init
nccl_ofi_msgbuff_elem_t *buff;
struct nccl_ofi_msgbuff_elem *buff;
/* Max number of INPROGRESS elements. These are the only
* ones backed by the storage buffer, so this is also the
* size of the storage buffer */
Expand All @@ -101,7 +102,13 @@ typedef struct {
uint16_t msg_next;
// Mutex for this msg buffer -- locks all non-init operations
pthread_mutex_t lock;
} nccl_ofi_msgbuff_t;
};

typedef enum nccl_ofi_msgbuff_elemtype nccl_ofi_msgbuff_elemtype_t;
typedef enum nccl_ofi_msgbuff_status nccl_ofi_msgbuff_status_t;
typedef enum nccl_ofi_msgbuff_result nccl_ofi_msgbuff_result_t;
typedef struct nccl_ofi_msgbuff_elem nccl_ofi_msgbuff_elem_t;
typedef struct nccl_ofi_msgbuff nccl_ofi_msgbuff_t;

/**
* Allocates and initializes a new message buffer.
Expand Down Expand Up @@ -182,7 +189,7 @@ nccl_ofi_msgbuff_result_t nccl_ofi_msgbuff_retrieve(nccl_ofi_msgbuff_t *msgbuff,
nccl_ofi_msgbuff_result_t nccl_ofi_msgbuff_complete(nccl_ofi_msgbuff_t *msgbuff,
uint16_t msg_index, nccl_ofi_msgbuff_status_t *msg_idx_status);

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

Expand Down
Loading