Exemple #1
0
void process_parse_trace()
{
    char proc_name[MAX_PROCESS_NAME_STR_LEN];
    sprintf(proc_name, "trace proc");
    create(proc_name);
    g_sim.m_num_CSIM_process++;

    // stream net_stream;

    WorkloadTrace* wkldTrace = (WorkloadTrace*) g_Workload;

    ((WorkloadTrace*) g_Workload)->skipTraceFile();
    hold(g_cfg.wkld_trace_skip_cycles);
    fprintf(stderr, "skipped %.0lf cycles (trace_file_id=%d).\n", g_cfg.wkld_trace_skip_cycles, wkldTrace->trace_file_id());

    double last_pkt_inject_clk = simtime();

    while (!g_EOS) {
        vector< Packet* > pkt_vec = wkldTrace->readTrace();

        if (pkt_vec.size() == 0)	
            continue;

        if (pkt_vec.size() == 1 && pkt_vec[0] == 0) // no more trace?
            break;

        if (pkt_vec[0]->m_clk_gen > last_pkt_inject_clk) {
            double hold_tm = pkt_vec[0]->m_clk_gen - last_pkt_inject_clk;
            if (hold_tm > 0.0)
                hold(hold_tm);
            last_pkt_inject_clk = simtime();
        }

        for (unsigned int n=0; n<pkt_vec.size(); n++) {
            Packet* p_pkt = pkt_vec[n];
#ifdef _DEBUG_ROUTER
printf("clk=%0.lf GEN p=%lld C:%d->%d R:%d/%d->%d/%d #flits=%d gen_clk=%.0lf\n", simtime(), p_pkt->id(), p_pkt->getSrcCoreID(), p_pkt->getDestCoreID(), p_pkt->getSrcRouterID(), p_pkt->m_NI_in_pos, p_pkt->getDestRouterID(), p_pkt->m_NI_out_pos, p_pkt->m_num_flits, p_pkt->m_clk_gen);
#endif

            // choose one network if multiple networks exist.
            if (g_cfg.net_networks > 1)
                select_network(p_pkt);

            assert(p_pkt->m_NI_in_pos < g_Core_vec[p_pkt->getSrcCoreID()]->num_NIInput());
            g_Core_vec[p_pkt->getSrcCoreID()]->forwardPkt2NI(p_pkt->m_NI_in_pos, p_pkt);
            g_sim.m_num_pkt_inj++;
        }
    }

    // After the last trace is processed, terminate simulation.
    if (!g_EOS) {
        g_EOS = true;
        g_ev_sim_done->set();
        g_sim.m_clk_sim_end = simtime();
    }

#ifdef _DEBUG_ROUTER_PROCESS
    printf("PROCESS COMPLETE: process_parse_trace\n");
#endif
}
Exemple #2
0
static int task_connect(struct supplicant_task *task)
{
	const char *address, *security, *passphrase;
	const void *ssid;
	unsigned int ssid_len;
	int err;

	address = connman_network_get_string(task->network, "Address");
	security = connman_network_get_string(task->network, "WiFi.Security");
	passphrase = connman_network_get_string(task->network, "WiFi.Passphrase");

	ssid = connman_network_get_blob(task->network, "WiFi.SSID", &ssid_len);

	_DBG_SUPPLICANT("address %s security %s", address, security);

	if (security == NULL && passphrase == NULL)
		return -EINVAL;

	if (g_str_equal(security, "none") == FALSE && passphrase == NULL)
		return -EINVAL;

	remove_network(task);

	set_ap_scan(task);

	add_network(task);

	set_network(task, ssid, ssid_len, address, security, passphrase);

	err = select_network(task);
	if (err < 0)
		return err;

	return -EINPROGRESS;
}
Exemple #3
0
void process_gen_synth_traffic(int core_id)
{
    char proc_name[MAX_PROCESS_NAME_STR_LEN];
    WorkloadSynthetic* workloadSynth = (WorkloadSynthetic*) g_Workload;

    if (workloadSynth->noInjection(core_id))
        return;

    sprintf(proc_name, "mgen-%d proc", core_id);
    create(proc_name);
    g_sim.m_num_CSIM_process++;

    while (!g_EOS) {
        double hold_time = workloadSynth->getWaitingTime(core_id);
        assert(hold_time >= 0.0);
        hold(hold_time);

        // finish simulation for the number of injected packets.
        if (g_cfg.sim_end_cond == SIM_END_BY_INJ_PKT) {
            if (g_sim.m_num_pkt_inj >= g_cfg.sim_num_inj_pkt)
                break;
        }

        Packet* p_pkt = workloadSynth->genPacket(core_id);

        // choose one network if multiple networks exist.
        if (g_cfg.net_networks > 1)
            select_network(p_pkt);

        assert(p_pkt->getSrcCoreID() == core_id);
        assert(p_pkt->m_NI_in_pos < g_Core_vec[p_pkt->getSrcCoreID()]->num_NIInput());
        g_Core_vec[p_pkt->getSrcCoreID()]->forwardPkt2NI(p_pkt->m_NI_in_pos, p_pkt);
        g_sim.m_num_pkt_inj++;
    }

    // NOTE: CSIM process synchronization problem...
    //       workaround: Wait for a sufficiently long time.
    hold(100.0);

#ifdef _DEBUG_ROUTER_PROCESS
    printf("PROCESS COMPLETE: process_gen_synth_traffic(core=%d)\n", core_id);
#endif
}
void process()
{
    while (1)
    {
        char menu = get_menu();

        switch (menu)
        {
            case 'm': // menu
            case 'M':
                break;

            case 'q': // quit
            case 'Q':
                printf("quit..!!\n");
                return;

            case 's': // start server
            case 'S':
                start_listening_server();
                break;

            case 't': // send request
            case 'T':
                send_request_all();
                break;

            case 'c': // start client
            case 'C':
                start_discovery_server();
                break;

            case 'r': // send request
            case 'R':
                send_request();
                break;

            case 'b': // send notification
            case 'B':
                send_notification();
                break;

            case 'n': // select network
            case 'N':
                select_network();
                break;

            case 'x': // unselect network
            case 'X':
                unselect_network();
                break;

            case 'h': // handle request response
            case 'H':
                handle_request_response();
                break;

            case 'w':
            case 'W':
                g_received = 0;
                start_discovery_server();
                send_secure_request();
                while (g_received == 0)
                {
                    sleep(1);
                    handle_request_response();
                }
                break;

            case 'z':
            case 'Z':
                start_listening_server();
                while (1)
                {
                    sleep(1);
                    handle_request_response();
                }
                break;

            case 'g': // get network information
            case 'G':
                get_network_info();
                break;

            default:
                printf("not supported menu!!\n");
                break;
        }
    }
}
int train_network_pool(float error_limit)
{
    int i, init = 0; //init is 0 for the first generation of the algorithm
    char index[10],file_name[100], selected_network_file[100];
    dnc* dnc_vars;
    Marchand* marchand_vars;
    float learning_rate, momentum, local_error, threshold  = 0.001;
    int selected_index, selected_source;   // selected_source = 0 -> dnc, 1 -> marchand selected index x-> xth network of selected_source
    int present_gen = 0;
    int count_mc = 0; // count misclassification
    float init_error = 1.0;

    srand(time(NULL));
    dnc_vars     =  new dnc[INIT_NET];
    marchand_vars =  new Marchand[INIT_NET];
    nn test_network;
    float present_error, previous_error;
    int increase_count = 0;

    present_error = previous_error = 1.0;
    char file_name_to_save[100];

    FILE  *fp_output = fopen("graph_input.csv","w");

    if(fp_output == NULL) printf("Error Opening File ... %s\n", "graph_input.csv");

    fprintf(fp_output, "%d,%f\n", present_gen, 1.0*NUM_GEN);

    while(present_gen < NUM_GEN)
    {
        if(present_gen)
            //if(true)
        {
            float local_error = 0.0;
            learning_rate = (double)(rand() % 10 + 2) / (double)(100);
            momentum      = (double)(rand() % 9 + 1) / (double)(10);

            cout << "GEN learing rate : " << learning_rate << " momentum : " << momentum << endl;

            int layer[3] = {ATTR_NUM, 1, NUM_CLASS};

            test_network.create_nn(3, layer, 0,  learning_rate, momentum, MAX_NODES);
            printf("running ..");
            test_network.load(selected_network_file);

            //for( int i = 0; i < TRAIN_SIZE; i++)
            for( int i = 0; i < VALIDATION_SIZE; i++)
            {
                test_network.calculate(validation_input[i]);
                local_error += test_network.get_error(validation_output[i]);
            }

            printf("Total error: %f Average error: %f\n", local_error, (float)(local_error/ TRAIN_SIZE));
            fprintf(fp_output, "%d,%f\n", present_gen, NUM_GEN * (float)(local_error/ TRAIN_SIZE));

            if( (float)(local_error/ TRAIN_SIZE) < error_limit)
            {
                test_network.save((char *) "genetic_ouptut.txt", 2);
                printf("The network is converged ...\n");
                fclose(fp_output);
                return 0;
            }
            else
            {
                test_network.save((char *) "genetic_ouptut.txt", 2);
                printf("The network is SAVED ...\n");

            }

            present_error =  (float)(local_error/ TRAIN_SIZE);
            if(fabs(present_error - previous_error) < (error_limit/10))
            {
                printf("Network Converged ... final case\n");
                test_network.save((char *) "genetic_ouptut.txt", 2);
                fclose(fp_output);
                return 0;
            }

            if(present_error > previous_error)
            {
                increase_count++;
                sprintf(file_name_to_save, "genetic/genetic_output%d", increase_count);
                test_network.save((char*) file_name_to_save);
                sprintf(file_name_to_save, "");
            }
            else if(present_error < previous_error) increase_count = 0;

            if(increase_count == MAIN_ERROR_INCREASE)
            {
                test_network.save((char *) "genetic_ouptut.txt", 2);
                printf("Returning from the main function ... %d\n", increase_count);
                fclose(fp_output);
                return 0;
            }
            else if( (present_error > previous_error) && (present_error - previous_error) < MAIN_ERROR_CHANGE)
            {

                sprintf(file_name_to_save, "genetic/genetic_outputLastCase");
                test_network.save((char*) file_name_to_save);
                sprintf(file_name_to_save, "");

                printf("Last case, Increase Count : %d\n", increase_count);
                fclose(fp_output);
                return 0;
            }
            printf("The increase count is : %d\n", increase_count);
            previous_error = present_error;


        }

        int m;
        for(i = 0; i < INIT_NET; i++)
        {
            sprintf(file_name, "dnc%d",i);
            //puts(file_name);
            //supply each network a time to stop, a random learning rate and a random permutation
            learning_rate = (double)(rand() % 10 + 2) / (double)(100);
            momentum      = (double)(rand() % 7 + 1) / (double)(10);

            cout << "learing rate : " << learning_rate << " momentum : " << momentum << endl;
            dnc_vars[i].init_dnc(ATTR_NUM, NUM_CLASS, TRAIN_SIZE, EPOCH_DNC, 0.001, MAX_NODES, learning_rate, momentum, file_name, TRAIN_TIME);
            dnc_vars[i].set_monotone_increament(5);
            dnc_vars[i].take_validation_data((float *) validation_input, (float *)validation_output, VALIDATION_SIZE); // num of validation data as last argument

            if(present_gen) dnc_vars[i].load(selected_network_file);

            error[i] = dnc_vars[i].execute((float *)input, (float *)output);
            strcpy(file_name,"");
        }

        m = i; // hold the value INIT_NET
        for(i = 0; i < INIT_NET; i++)
        {
            strcpy(file_name,"");
            sprintf(file_name, "marchand%d", i);
            //puts(file_name);

            if(!present_gen)
            {
                permutation_next();
                marchand_vars[i].init_marchand(ATTR_NUM, NUM_CLASS, TRAIN_SIZE, 200, 0.05, MAX_NODES, file_name, TRAIN_TIME/3.0);
                marchand_vars[i].take_validation_data((float *) validation_input, (float *)validation_output, VALIDATION_SIZE);
                error[m+i] = marchand_vars[i].execute((float *)input_temp, (float *)output_temp);
            }
            else
            {
                permutation_next_another((float *)remaining_input, (float *)remaining_output, count_mc);
                marchand_vars[i].init_marchand(ATTR_NUM, NUM_CLASS, count_mc, 200, 0.05, MAX_NODES, file_name, TRAIN_TIME/3.0);
                marchand_vars[i].load(selected_network_file);
                marchand_vars[i].take_validation_data((float *) validation_input, (float *)validation_output, VALIDATION_SIZE);
                error[m+i] = marchand_vars[i].execute((float *)remaining_input, (float *)remaining_output);
            }
        }

        //best selection
        select_network(&selected_index, &selected_source);
        cout << "selected index: " << selected_index << " selected source: " << selected_source << endl;

        count_mc = 0;

        if(selected_source == 0)
        {
            for(int m = 0; m < TRAIN_SIZE; m++)
            {
                local_error = dnc_vars[selected_index].calculate_for_single(input[m],output[m]);

                if(local_error > threshold)
                {
                    for(int k = 0; k < ATTR_NUM; k++) remaining_input[count_mc][k] = input[m][k];
                    for(int k = 0; k < NUM_CLASS; k++) remaining_output[count_mc][k] = output[m][k];
                    count_mc++;
                }
            }
        }

        if(!selected_source) sprintf(selected_network_file, "dnc%d", selected_index);
        else sprintf(selected_network_file, "marchand%d", selected_index);

        cout << "Generation is  : " << present_gen << endl;
        present_gen++;
    }

    delete []dnc_vars;
    delete []marchand_vars;
    return 0;
}