Example #1
0
static void onaccept(void* userptr, SOCK_HANDLE sock, const SOCK_ADDR* pname)
{
	int idx;
	CUBE_CONNECTION* conn;
	NETWORK_EVENT event;

	os_mutex_lock(&room_mtx);

	for(idx=0; idx<sizeof(conn_list)/sizeof(conn_list[0]); idx++) {
		if(conn_list[idx]==NULL) break;
	}
	if(idx==sizeof(conn_list)/sizeof(conn_list[0])) {
		sock_close(sock);
		os_mutex_unlock(&room_mtx);
		return;
	}

	conn = (CUBE_CONNECTION*)mempool_alloc(conn_pool);
	if(conn==NULL) {
		sock_close(sock);
		os_mutex_unlock(&room_mtx);
		return;
	}

	event.OnConnect = onconnect;
	event.OnData = ondata;
	event.OnDisconnect = ondisconnect;
	event.recvbuf_buf = conn->recv_buf;
	event.recvbuf_max = sizeof(conn->recv_buf);
	event.recvbuf_pool = NULL;
	memset(conn, 0, sizeof(*conn));
	conn->index = idx;
	conn_list[idx] = conn;

	conn->handle = network_add(sock, &event, conn);
	if(!conn->handle) {
		mempool_free(conn_pool, conn);
		sock_close(sock);
		os_mutex_unlock(&room_mtx);
		return;
	}

	os_mutex_unlock(&room_mtx);
}
Example #2
0
void onaccept_proc(void* userptr, SOCK_HANDLE sock, const SOCK_ADDR* pname)
{
	char addr[50];
	NETWORK_EVENT event;

	printf("accept from %s\n", sock_addr2str(pname, addr));
	sock_nonblock(sock);

	event.OnConnect = onconnect_proc;
	event.OnData = ondata_proc;
	event.OnDisconnect = ondisconnect_proc;
	event.recvbuf_pool = recvbuf_pool;
	event.recvbuf_buf = NULL;
	event.recvbuf_max = recvbuf_size;

	if(!network_add(sock, &event, NULL)) {
		sock_disconnect(sock);
		sock_close(sock);
	}
}
Example #3
0
// Model referenced in paper: http://delivery.acm.org/10.1145/2750000/2744788/a108-cavigelli.pdf?ip=131.111.184.18&id=2744788&acc=ACTIVE%20SERVICE&key=BF07A2EE685417C5%2E6CDC43D2A5950A53%2E4D4702B0C3E38B35%2E4D4702B0C3E38B35&CFID=693103990&CFTOKEN=72630065&__acm__=1436879082_abb335b0c6bff6ea2d573dafecbbe01a
// Used as a benchmark in Origami paper
Network* construct_scene_labeling_net() {
  Network* net = make_network(1);

  network_add(net, make_conv_layer(28, 28, 1, 5, 6, 1, 0));
  /*
  network_add(net, make_max_pool_layer(net->layers[0]->out_sx, net->layers[0]->out_sy, net->layers[0]->out_depth, 2, 2));
  network_add(net, make_relu_layer(net->layers[1]->out_sx, net->layers[1]->out_sy, net->layers[1]->out_depth));

  network_add(net, make_conv_layer(net->layers[2]->out_sx, net->layers[2]->out_sy, net->layers[2]->out_depth, 7, 64, 1, 0));
  network_add(net, make_max_pool_layer(net->layers[3]->out_sx, net->layers[3]->out_sy, net->layers[3]->out_depth, 2, 2));
  network_add(net, make_relu_layer(net->layers[4]->out_sx, net->layers[4]->out_sy, net->layers[4]->out_depth));

  network_add(net, make_conv_layer(net->layers[5]->out_sx, net->layers[5]->out_sy, net->layers[5]->out_depth, 7, 256, 1, 0));
  network_add(net, make_relu_layer(net->layers[6]->out_sx, net->layers[6]->out_sy, net->layers[6]->out_depth));

  network_add(net, make_fc_layer(net->layers[7]->out_sx, net->layers[7]->out_sy, net->layers[7]->out_depth, 64));
  network_add(net, make_relu_layer(net->layers[8]->out_sx, net->layers[8]->out_sy, net->layers[8]->out_depth));
  network_add(net, make_fc_layer(net->layers[9]->out_sx, net->layers[9]->out_sy, net->layers[9]->out_depth, 8));
  network_add(net, make_softmax_layer(net->layers[10]->out_sx, net->layers[10]->out_sy, net->layers[10]->out_depth));
  */
  return net;
}
Example #4
0
// Neural Network -------------------------------------------------------------
// Load the snapshot of the CNN we are going to run.
Network* construct_gtsrb_net() {
  fprintf(stderr, "Constructing GTSRB Network \n");
  Network* net = make_network(12);

  network_add(net, make_conv_layer(48, 48, 3, 3, 100, 1, 0));
  network_add(net, make_relu_layer(net->layers[0]->out_sx, net->layers[0]->out_sy, net->layers[0]->out_depth));
  network_add(net, make_max_pool_layer(net->layers[1]->out_sx, net->layers[1]->out_sy, net->layers[1]->out_depth, 2, 2));
  network_add(net, make_conv_layer(net->layers[2]->out_sx, net->layers[2]->out_sy, net->layers[2]->out_depth, 4, 150, 1, 0));
  network_add(net, make_relu_layer(net->layers[3]->out_sx, net->layers[3]->out_sy, net->layers[3]->out_depth));
  network_add(net, make_max_pool_layer(net->layers[4]->out_sx, net->layers[4]->out_sy, net->layers[4]->out_depth, 2, 2));
  network_add(net, make_conv_layer(net->layers[5]->out_sx, net->layers[5]->out_sy, net->layers[5]->out_depth, 3, 250, 1, 0));
  network_add(net, make_relu_layer(net->layers[6]->out_sx, net->layers[6]->out_sy, net->layers[6]->out_depth));
  network_add(net, make_max_pool_layer(net->layers[7]->out_sx, net->layers[7]->out_sy, net->layers[7]->out_depth, 2, 2));
  network_add(net, make_fc_layer(net->layers[8]->out_sx, net->layers[8]->out_sy, net->layers[8]->out_depth, 200));
  network_add(net, make_fc_layer(net->layers[9]->out_sx, net->layers[9]->out_sy, net->layers[9]->out_depth, 43));
  network_add(net, make_softmax_layer(net->layers[10]->out_sx, net->layers[10]->out_sy, net->layers[10]->out_depth));

  // load pre-trained weights
  conv_load(net->layers[0], conv1_params, conv1_data);
  conv_load(net->layers[3], conv2_params, conv2_data);
  conv_load(net->layers[6], conv3_params, conv3_data);
  fc_load(net->layers[9], ip1_params, ip1_data);
  fc_load(net->layers[10], ip2_params, ip2_data);
  return net;
}