RDMANetwork.h 3.2 KB
Newer Older
1
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
Z
zhangjinchao01 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#pragma once

#ifndef PADDLE_DISABLE_RDMA
#include "sxi_sock.h"
#else
#define PROMPT_ERR() LOG(FATAL) << "Paddle is not compiled with rdma"
#endif
X
Xin Pan 已提交
22
#include "paddle/legacy/utils/Logging.h"
Z
zhangjinchao01 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

#include <netinet/in.h>
struct sxi_sock;
struct sxi_socket;

#ifndef MAX_VEC_SIZE
// define default MAX_VEC_SIZE
#define MAX_VEC_SIZE (1UL << 16)
#endif

namespace paddle {
/// Namespace rdma is adaptors for sxi_sock.h. Make paddle not depend on it
/// when disable rdma support
namespace rdma {
inline int numCpus() {
#ifndef PADDLE_DISABLE_RDMA
  return sxi_num_configured_cpus();
#else
  return 0;
#endif
}

inline sxi_socket* ssocket(int cpuId) {
#ifndef PADDLE_DISABLE_RDMA
  return sxi_ssocket(cpuId);
#else
  PROMPT_ERR();
#endif
}

inline int listen(sxi_socket* s) {
#ifndef PADDLE_DISABLE_RDMA
  return sxi_listen(s);
#else
  PROMPT_ERR();
#endif
}

inline int bind(sxi_socket* s, const char* str) {
#ifndef PADDLE_DISABLE_RDMA
  return sxi_bind(s, str);
#else
  PROMPT_ERR();
#endif
}

inline sxi_sock* accept(sxi_socket* s) {
#ifndef PADDLE_DISABLE_RDMA
  return sxi_accept(s);
#else
  PROMPT_ERR();
#endif
}

inline sockaddr_in* getSourceAddress(sxi_sock* sock) {
#ifndef PADDLE_DISABLE_RDMA
79
  return reinterpret_cast<sockaddr_in*>(&sock->sa);
Z
zhangjinchao01 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
#else
  PROMPT_ERR();
#endif
}

inline int close(sxi_socket* sock) {
#ifndef PADDLE_DISABLE_RDMA
  return sxi_socket_close(sock);
#else
  PROMPT_ERR();
#endif
}

inline int close(sxi_sock* sock) {
#ifndef PADDLE_DISABLE_RDMA
  return sxi_sock_close(sock);
#else
  PROMPT_ERR();
#endif
}

inline void init() {
#ifndef PADDLE_DISABLE_RDMA
  sxi_module_init();
#else
  PROMPT_ERR();
#endif
}

inline sxi_socket* csocket(int cpuId) {
#ifndef PADDLE_DISABLE_RDMA
  return sxi_csocket(cpuId);
#else
  PROMPT_ERR();
#endif
}

inline ssize_t read(sxi_sock* channel, void* data, size_t len) {
#ifndef PADDLE_DISABLE_RDMA
  return sxi_read(channel, data, len);
#else
  PROMPT_ERR();
#endif
}

inline ssize_t write(sxi_sock* channel, void* data, size_t len) {
#ifndef PADDLE_DISABLE_RDMA
  return sxi_write(channel, data, len);
#else
  PROMPT_ERR();
#endif
}

inline ssize_t readv(sxi_sock* channel, iovec* iov, int count) {
#ifndef PADDLE_DISABLE_RDMA
  return sxi_readv(channel, iov, count);
#else
  PROMPT_ERR();
#endif
}

inline ssize_t writev(sxi_sock* channel, iovec* iov, int count) {
#ifndef PADDLE_DISABLE_RDMA
  return sxi_writev(channel, iov, count);
#else
  PROMPT_ERR();
#endif
}

inline sxi_sock* connect(sxi_socket* socket, const char* url) {
#ifndef PADDLE_DISABLE_RDMA
  return sxi_connect(socket, url);
#else
  PROMPT_ERR();
#endif
}

}  //  namespace rdma
}  //  namespace paddle