파일
rocm-systems/src/include/socket.h
T

71 라인
3.0 KiB
C
Raw 일반 보기 히스토리

2018-09-24 16:06:59 -07:00
/*************************************************************************
2022-01-07 06:39:55 -08:00
* Copyright (c) 2016-2022, NVIDIA CORPORATION. All rights reserved.
2018-09-24 16:06:59 -07:00
*
* See LICENSE.txt for license information
************************************************************************/
#ifndef NCCL_SOCKET_H_
#define NCCL_SOCKET_H_
2022-01-07 06:39:55 -08:00
#include "nccl.h"
2018-09-24 16:06:59 -07:00
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <netdb.h>
2022-01-07 06:39:55 -08:00
#include <fcntl.h>
#include <poll.h>
2018-09-24 16:06:59 -07:00
2018-10-24 14:44:59 -07:00
#define MAX_IFS 16
2018-09-24 16:06:59 -07:00
#define MAX_IF_NAME_SIZE 16
2019-03-14 19:39:20 -07:00
#define SLEEP_INT 1000 // connection retry sleep interval in usec
#define RETRY_REFUSED_TIMES 2e4 // connection refused retry times before reporting a timeout (20 sec)
#define RETRY_TIMEDOUT_TIMES 3 // connection timed out retry times (each one can take 20s)
2020-09-04 14:35:05 -07:00
#define SOCKET_NAME_MAXLEN (NI_MAXHOST+NI_MAXSERV)
2018-09-24 16:06:59 -07:00
/* Common socket address storage structure for IPv4/IPv6 */
2022-01-07 06:39:55 -08:00
union ncclSocketAddress {
2018-09-24 16:06:59 -07:00
struct sockaddr sa;
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
};
2022-01-07 06:39:55 -08:00
enum ncclSocketState {
ncclSocketConnecting = 0,
ncclSocketConnected = 1,
ncclSocketError = 2,
ncclSocketStateNum = 3
} ;
struct ncclSocket {
int fd;
union ncclSocketAddress addr;
volatile uint32_t* abortFlag;
int asyncFlag;
enum ncclSocketState state;
};
2018-09-24 16:06:59 -07:00
2022-03-30 02:25:49 -07:00
const char *ncclSocketToString(union ncclSocketAddress *addr, char *buf, const int numericHostForm = 1);
2022-01-07 06:39:55 -08:00
ncclResult_t ncclGetSocketAddrFromString(union ncclSocketAddress* ua, const char* ip_port_pair);
int ncclFindInterfaceMatchSubnet(char* ifNames, union ncclSocketAddress* localAddrs, union ncclSocketAddress* remoteAddr, int ifNameMaxSize, int maxIfs);
int ncclFindInterfaces(char* ifNames, union ncclSocketAddress *ifAddrs, int ifNameMaxSize, int maxIfs);
// Create a listening socket. sock->addr can be pre-filled with IP & port info. sock->fd is set after a successful call
ncclResult_t ncclSocketListen(struct ncclSocket* sock);
// Connect to sock->addr. sock->fd is set after a successful call.
ncclResult_t ncclSocketConnect(struct ncclSocket* sock);
// Return socket connection state.
ncclResult_t ncclGetSocketState(struct ncclSocket* sock, enum ncclSocketState* state);
// Accept an incoming connection from listenSocket->fd and keep the file descriptor in sock->fd, with the remote side IP/port in sock->addr.
ncclResult_t ncclSocketAccept(struct ncclSocket* sock, struct ncclSocket* listenSocket);
2018-09-24 16:06:59 -07:00
2018-11-19 17:43:50 -08:00
#define NCCL_SOCKET_SEND 0
#define NCCL_SOCKET_RECV 1
2018-09-24 16:06:59 -07:00
2022-01-07 06:39:55 -08:00
ncclResult_t ncclSocketProgress(int op, struct ncclSocket* sock, void* ptr, int size, int* offset);
ncclResult_t ncclSocketWait(int op, struct ncclSocket* sock, void* ptr, int size, int* offset);
ncclResult_t ncclSocketSend(struct ncclSocket* sock, void* ptr, int size);
ncclResult_t ncclSocketRecv(struct ncclSocket* sock, void* ptr, int size);
ncclResult_t ncclSocketTryRecv(struct ncclSocket* sock, void* ptr, int size, int* closed);
/* initialize a socket. */
ncclResult_t ncclSocketInit(struct ncclSocket* sock, union ncclSocketAddress* addr = NULL, volatile uint32_t* abortFlag = NULL, int asyncFlag = 0);
2018-09-24 16:06:59 -07:00
#endif