Skip to content

Commit

Permalink
nit: msgbuff: avoid typedef hell
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-nslick committed Sep 4, 2024
1 parent 16bcbc1 commit ddc2dc3
Showing 1 changed file with 21 additions and 14 deletions.
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" {
*/

/* 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

0 comments on commit ddc2dc3

Please sign in to comment.