Joseph Redmon
2016-09-08 0e610b056dbcd85affa23f64f9f8da4d197f110a
src/server.c
@@ -15,7 +15,7 @@
#include "connected_layer.h"
#include "convolutional_layer.h"
#define SERVER_PORT 9876
#define SERVER_PORT 9423
#define STR(x) #x
int socket_setup(int server)
@@ -46,32 +46,10 @@
typedef struct{
    int fd;
    int *counter;
    int counter;
    network net;
} connection_info;
void read_all(int fd, char *buffer, size_t bytes)
{
    //printf("Want %d\n", bytes);
    size_t n = 0;
    while(n < bytes){
        int next = read(fd, buffer + n, bytes-n);
        if(next <= 0) error("read failed");
        n += next;
    }
}
void write_all(int fd, char *buffer, size_t bytes)
{
    //printf("Writ %d\n", bytes);
    size_t n = 0;
    while(n < bytes){
        int next = write(fd, buffer + n, bytes-n);
        if(next <= 0) error("write failed");
        n += next;
    }
}
void read_and_add_into(int fd, float *a, int n)
{
    float *buff = calloc(n, sizeof(float));
@@ -85,6 +63,11 @@
    connection_info info = *(connection_info *) pointer;
    free(pointer);
    //printf("New Connection\n");
    if(info.counter%100==0){
        char buff[256];
        sprintf(buff, "unikitty/net_%d.part", info.counter);
        save_network(info.net, buff);
    }
    int fd = info.fd;
    network net = info.net;
    int i;
@@ -126,15 +109,15 @@
void server_update(network net)
{
    int fd = socket_setup(1);
    int counter = 0;
    listen(fd, 10);
    int counter = 18000;
    listen(fd, 64);
    struct sockaddr_in client;     /* remote address */
    socklen_t client_size = sizeof(client);   /* length of addresses */
    time_t t=0;
    while(1){
        connection_info *info = calloc(1, sizeof(connection_info));
        info->net = net;
        info->counter = &counter;
        info->counter = counter;
        pthread_t worker;
        int connection = accept(fd, (struct sockaddr *) &client, &client_size);
        if(!t) t=time(0);
@@ -142,10 +125,8 @@
        pthread_create(&worker, NULL, (void *) &handle_connection, info);
        ++counter;
        printf("%d\n", counter);
        if(counter == 1024) break;
        if(counter%1000==0) save_network(net, "cfg/nist.part");
        //if(counter == 1024) break;
    }
    printf("1024 epochs: %d seconds\n", time(0)-t);
    close(fd);
}
@@ -204,7 +185,9 @@
            int num = layer.n*layer.c*layer.size*layer.size;
            read_all(fd, (char*) layer.filters, num*sizeof(float));
#ifdef GPU
            push_convolutional_layer(layer);
            #endif
        }
        if(net.types[i] == CONNECTED){
            connected_layer layer = *(connected_layer *) net.layers[i];
@@ -212,7 +195,9 @@
            read_all(fd, (char *)layer.biases, layer.outputs*sizeof(float));
            read_all(fd, (char *)layer.weights, layer.outputs*layer.inputs*sizeof(float));
#ifdef GPU
            push_connected_layer(layer);
            #endif
        }
    }
    //printf("Updated\n");