"profiler/profile_conv_fwd_bias_relu_add.cpp" did not exist on "4041850f11248629bca42fdf1e111c309aeabf23"
Commit 4c56e774 authored by Antoine Kaufmann's avatar Antoine Kaufmann
Browse files

lib/simbricks/base: add SimBricksBaseIfEstablish()

SimBricksBaseIfEstablish handles parallel connections and handshakes on
multiple simbricks connections.
parent d267f8a6
......@@ -713,6 +713,90 @@ int SimbricksBaseIfIntroFd(struct SimbricksBaseIf *base_if)
}
}
int SimBricksBaseIfEstablish(struct SimBricksBaseIfEstablishData *ifs,
size_t n)
{
struct pollfd pfds[n];
unsigned n_pfd;
size_t established = 0;
int ret;
while (established < n) {
size_t i;
n_pfd = 0;
established = 0;
for (i = 0; i < n; i++) {
struct SimbricksBaseIf *bif = ifs[i].base_if;
// woops something went wrong on this connection
if (bif->conn_state == kConnClosed) {
fprintf(stderr, "SimBricksBaseIfEstablish: connection %zu is "
"closed\n", i);
return -1;
}
// check if it is connected yet (this might change that)
ret = SimbricksBaseIfConnected(bif);
if (ret < 0) {
fprintf(stderr, "SimBricksBaseIfEstablish: connecting %zu failed\n", i);
return -1;
} else if (ret > 0) {
pfds[n_pfd].fd = SimbricksBaseIfConnFd(bif);
pfds[n_pfd].events = (bif->conn_state == kConnListening ? POLLIN :
POLLOUT);
pfds[n_pfd].revents = 0;
n_pfd++;
assert(n_pfd <= n);
}
// next check if we are now ready to send the handshake
if ((bif->conn_state == kConnAwaitHandshakeTx ||
bif->conn_state == kConnAwaitHandshakeRxTx) &&
SimbricksBaseIfIntroSend(bif, ifs[i].tx_intro, ifs[i].tx_intro_len)
!= 0) {
fprintf(stderr, "SimBricksBaseIfEstablish: Sending intro on %zu "
"failed\n", i);
return -1;
}
// finally check if we can receive the handshake now
if (bif->conn_state == kConnAwaitHandshakeRx) {
ret = SimbricksBaseIfIntroRecv(bif, ifs[i].rx_intro,
&ifs[i].rx_intro_len);
if (ret < 0) {
fprintf(stderr, "SimBricksBaseIfEstablish: Receiving intro on %zu "
"failed\n", i);
return -1;
} else if (ret > 0) {
pfds[n_pfd].fd = SimbricksBaseIfIntroFd(bif);
pfds[n_pfd].events = POLLIN;
pfds[n_pfd].revents = 0;
n_pfd++;
assert(n_pfd <= n);
}
}
if (bif->conn_state == kConnOpen) {
established++;
}
}
if (n_pfd == 0 && established != n) {
fprintf(stderr, "SimBricksBaseIfEstablish: no poll events to wait for "
"but not all established (BUG)\n");
abort();
} else if (n_pfd > 0) {
ret = poll(pfds, n_pfd, -1);
if (ret < 0) {
fprintf(stderr, "SimBricksBaseIfEstablish: poll failed\n");
return -1;
}
}
}
return 0;
}
void SimbricksBaseIfClose(struct SimbricksBaseIf *base_if)
{
if (base_if->conn_state == kConnListening) {
......
......@@ -105,6 +105,16 @@ struct SimbricksBaseIf {
bool listener;
};
struct SimBricksBaseIfEstablishData {
struct SimbricksBaseIf *base_if;
const void *tx_intro;
size_t tx_intro_len;
void *rx_intro;
size_t rx_intro_len;
};
/** Create and map a new shared memory pool with the specified path and size. */
int SimbricksBaseIfSHMPoolCreate(struct SimbricksBaseIfSHMPool *pool,
......@@ -151,6 +161,19 @@ int SimbricksBaseIfIntroRecv(struct SimbricksBaseIf *base_if,
/** FD to wait on for intro events. */
int SimbricksBaseIfIntroFd(struct SimbricksBaseIf *base_if);
/**
* Completely establish multiple base-ifs in parallel. This handles the parallel
* connecting and handshake transmission and reception. Expects all base ifs to
* be in non-blocking mode.
*
* @param ifs Array of structs with info about each baseif including pointers
* and lengths for intro messages.
* @param n Number of ifs to establish.
*
* @return 0 on success, != 0 otherwise.
*/
int SimBricksBaseIfEstablish(struct SimBricksBaseIfEstablishData *ifs,
size_t n);
void SimbricksBaseIfClose(struct SimbricksBaseIf *base_if);
void SimbricksBaseIfUnlink(struct SimbricksBaseIf *base_if);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment