Example #1
0
gboolean
te_graph_trigger(gpointer user_data)
{
    enum transition_status graph_rc = -1;

    if (transition_graph == NULL) {
        crm_debug("Nothing to do");
        return TRUE;
    }

    crm_trace("Invoking graph %d in state %s", transition_graph->id, fsa_state2string(fsa_state));

    switch (fsa_state) {
        case S_STARTING:
        case S_PENDING:
        case S_NOT_DC:
        case S_HALT:
        case S_ILLEGAL:
        case S_STOPPING:
        case S_TERMINATE:
            return TRUE;
            break;
        default:
            break;
    }

    if (transition_graph->complete == FALSE) {
        int limit = transition_graph->batch_limit;

        transition_graph->batch_limit = throttle_get_total_job_limit(limit);
        graph_rc = run_graph(transition_graph);
        transition_graph->batch_limit = limit; /* Restore the configured value */

        /* significant overhead... */
        /* print_graph(LOG_DEBUG_3, transition_graph); */

        if (graph_rc == transition_active) {
            crm_trace("Transition not yet complete");
            return TRUE;

        } else if (graph_rc == transition_pending) {
            crm_trace("Transition not yet complete - no actions fired");
            return TRUE;
        }

        if (graph_rc != transition_complete) {
            crm_warn("Transition failed: %s", transition_status(graph_rc));
            print_graph(LOG_NOTICE, transition_graph);
        }
    }

    crm_debug("Transition %d is now complete", transition_graph->id);
    transition_graph->complete = TRUE;
    notify_crmd(transition_graph);

    return TRUE;
}
Example #2
0
gboolean
te_graph_trigger(gpointer user_data)
{
    enum transition_status graph_rc = -1;

    if (transition_graph == NULL) {
        crm_debug("Nothing to do");
        return TRUE;
    }

    crm_debug_2("Invoking graph %d in state %s", transition_graph->id, fsa_state2string(fsa_state));

    switch (fsa_state) {
    case S_STARTING:
    case S_PENDING:
    case S_NOT_DC:
    case S_HALT:
    case S_ILLEGAL:
    case S_STOPPING:
    case S_TERMINATE:
        return TRUE;
        break;
    default:
        break;
    }

    if (transition_graph->complete == FALSE) {
        graph_rc = run_graph(transition_graph);
        print_graph(LOG_DEBUG_3, transition_graph);

        if (graph_rc == transition_active) {
            crm_debug_3("Transition not yet complete");
            return TRUE;

        } else if (graph_rc == transition_pending) {
            crm_debug_3("Transition not yet complete - no actions fired");
            return TRUE;
        }

        if (graph_rc != transition_complete) {
            crm_err("Transition failed: %s", transition_status(graph_rc));
            print_graph(LOG_WARNING, transition_graph);
        }
    }

    crm_info("Transition %d is now complete", transition_graph->id);
    transition_graph->complete = TRUE;
    notify_crmd(transition_graph);

    return TRUE;
}
Example #3
0
static void run_graphs(MSTicker *s, MSList *execution_list, bool_t force_schedule){
	MSList *it;
	MSList *unschedulable=NULL;
	for(it=execution_list;it!=NULL;it=it->next){
		run_graph((MSFilter*)it->data,s,&unschedulable,force_schedule);
	}
	/* filters that are part of a loop haven't been called in process() because one of their input refers to a filter that could not be scheduled (because they could not be scheduled themselves)... Do you understand ?*/
	/* we resolve this by simply assuming that they must be called anyway 
	for the loop to run correctly*/
	/* we just recall run_graphs on them, as if they were source filters */
	if (unschedulable!=NULL) {
		run_graphs(s,unschedulable,TRUE);
		ms_list_free(unschedulable);
	}
}
Example #4
0
static void
process_next_job(void* data)
{
	crm_graph_t *transition = (crm_graph_t *)data;
	enum transition_status graph_rc;

	qb_enter();

	if (!graph_updated) {
		qb_loop_job_add(NULL, QB_LOOP_MED, transition, process_next_job);
		qb_leave();
		return;
	}

	graph_updated = FALSE;
	graph_rc = run_graph(transition);

	qb_log(LOG_DEBUG, "run_graph returned: %s", transition_status(graph_rc));

	if (graph_rc == transition_active || graph_rc == transition_pending) {
		qb_loop_job_add(NULL, QB_LOOP_MED, transition, process_next_job);
		qb_leave();
		return;
	}

	if (graph_rc != transition_complete) {
		qb_log(LOG_ERR, "Transition failed: %s",
		       transition_status(graph_rc));
	}
	destroy_graph(transition);

	// we don't want to free the input xml
	working_set->input = NULL;
	cleanup_alloc_calculations(working_set);
	free(working_set);
	working_set = NULL;

	completed_fn(run_user_data, graph_rc);

	qb_leave();
	return;
}
Example #5
0
static void run_graph(MSFilter *f, MSTicker *s, MSList **unschedulable, bool_t force_schedule){
	int i;
	MSQueue *l;
	if (f->last_tick!=s->ticks ){
		if (filter_can_process(f,s->ticks) || force_schedule) {
			/* this is a candidate */
			f->last_tick=s->ticks;
			call_process(f);	
			/* now recurse to next filters */		
			for(i=0;i<f->desc->noutputs;i++){
				l=f->outputs[i];
				if (l!=NULL){
					run_graph(l->next.filter,s,unschedulable, force_schedule);
				}
			}
		}else{
			/* this filter has not all inputs that have been filled by filters before it. */
			*unschedulable=ms_list_prepend(*unschedulable,f);
		}
	}
}
Example #6
0
File: main.c Project: g8ecj/turbine
int main(void)
{
	init();

	while (1)
	{
		// keep the clock ticking
		run_rtc();
      // run volts/amps/temperature reading stuff on the onewire interface
      run_measure();
      // decide if inverter or shunt load is needed to be turned on
      run_control();
      // keep the log data in dataflash up to date
      run_log();
      // calculate turbine RPM from period of raw AC
      run_rpm();
      // save values for graphic display of power in/out
      run_graph();
      // display stuff on the LCD & get user input
      run_ui();

	}
}
Example #7
0
int main(int argc, char *argv[])
{
    const std::string root_path = get_root_path();
    std::string proto_file;
    std::string model_file;
    std::string image_file;
    std::string save_name="save.jpg";
	const char * device=nullptr;

    int res;
    while( ( res=getopt(argc,argv,"p:m:i:hd:"))!= -1)
    {
        switch(res)
        {
            case 'p':
                proto_file=optarg;
                break;
            case 'm':
                model_file=optarg;
                break;
            case 'i':
                image_file=optarg;
                break;
			case 'd':
				device=optarg;
				break;
            case 'h':
                std::cout << "[Usage]: " << argv[0] << " [-h]\n"
                          << "   [-p proto_file] [-m model_file] [-i image_file]\n";
                return 0;
            default:
                break;
        }
    }



    const char *model_name = "mssd_300";
    if(proto_file.empty())
    {
        proto_file = root_path + DEF_PROTO;
        std::cout<< "proto file not specified,using "<<proto_file<< " by default\n";

    }
    if(model_file.empty())
    {
        model_file = root_path + DEF_MODEL;
        std::cout<< "model file not specified,using "<<model_file<< " by default\n";
    }
    if(image_file.empty())
    {
        image_file = root_path + DEF_IMAGE;
        std::cout<< "image file not specified,using "<<image_file<< " by default\n";
    }

    // init tengine
    init_tengine_library();
    if (request_tengine_version("0.1") < 0)
        return 1;
    if (load_model(model_name, "caffe", proto_file.c_str(), model_file.c_str()) < 0)
        return 1;
    std::cout << "load model done!\n";
   
    // create graph
    graph_t graph = create_runtime_graph("graph", model_name, NULL);
    if (!check_graph_valid(graph))
    {
        std::cout << "create graph0 failed\n";
        return 1;
    }

	if(device!=nullptr)
	{
		set_graph_device(graph,device);
	}

	//dump_graph(graph);

    // input
    int img_h = 300;
    int img_w = 300;
    int img_size = img_h * img_w * 3;
    float *input_data = (float *)malloc(sizeof(float) * img_size);

    int node_idx=0;
    int tensor_idx=0;
    tensor_t input_tensor = get_graph_input_tensor(graph, node_idx, tensor_idx);
    if(!check_tensor_valid(input_tensor))
    {
        printf("Get input node failed : node_idx: %d, tensor_idx: %d\n",node_idx,tensor_idx);
        return 1;
    }

    int dims[] = {1, 3, img_h, img_w};
    set_tensor_shape(input_tensor, dims, 4);
    prerun_graph(graph);

    int repeat_count = 1;
    const char *repeat = std::getenv("REPEAT_COUNT");

    if (repeat)
        repeat_count = std::strtoul(repeat, NULL, 10);

	//warm up
    get_input_data_ssd(image_file, input_data, img_h,  img_w);
    set_tensor_buffer(input_tensor, input_data, img_size * 4);
    run_graph(graph, 1);


    struct timeval t0, t1;
    float total_time = 0.f;
    for (int i = 0; i < repeat_count; i++)
    {
        get_input_data_ssd(image_file, input_data, img_h,  img_w);
  
        gettimeofday(&t0, NULL);
        set_tensor_buffer(input_tensor, input_data, img_size * 4);
        run_graph(graph, 1);

        gettimeofday(&t1, NULL);
        float mytime = (float)((t1.tv_sec * 1000000 + t1.tv_usec) - (t0.tv_sec * 1000000 + t0.tv_usec)) / 1000;
        total_time += mytime;

    }
    std::cout << "--------------------------------------\n";
    std::cout << "repeat " << repeat_count << " times, avg time per run is " << total_time / repeat_count << " ms\n";
    tensor_t out_tensor = get_graph_output_tensor(graph, 0,0);//"detection_out");
    int out_dim[4];
    get_tensor_shape( out_tensor, out_dim, 4);
    float *outdata = (float *)get_tensor_buffer(out_tensor);
    int num=out_dim[1];
    float show_threshold=0.5;
    
    post_process_ssd(image_file,show_threshold, outdata, num,save_name);
	
	put_graph_tensor(out_tensor);
    put_graph_tensor(input_tensor);
    
    postrun_graph(graph);
    free(input_data);
    destroy_runtime_graph(graph);
    remove_model(model_name);

    return 0;
}
int main(int argc, char *argv[])
{
    if (argc < 4)
    {
        std::cout << "[Usage]: " << argv[0] << " <proto> <caffemodel> <size> \n";
        return 0;
    }

  

    // init tengine
    init_tengine_library();
    if (request_tengine_version("0.1") < 0)
        return 1;

    // load model
    const char *model_name = "test";
    std::string proto_name_ =argv[1];
    std::string mdl_name_ = argv[2];
    if (load_model(model_name, "caffe", proto_name_.c_str(), mdl_name_.c_str()) < 0)
        return 1;
    std::cout << "load model done!\n";

    // create graph
    graph_t graph = create_runtime_graph("graph", model_name, NULL);
    if (!check_graph_valid(graph))
    {
        std::cout << "create graph0 failed\n";
        return 1;
    }

    // input
    int img_h = atoi(argv[3]);
    int img_w = img_h;
    if (argc==5) img_w=atoi(argv[4]);
    int img_size = img_h * img_w * 3;

    float *input_data = (float *)malloc(sizeof(float) * img_size);

    for(int i=0;i<img_size;i++) 
		input_data[i]=(i%123)*0.017;
    

	int node_idx = 0;
	int tensor_idx = 0;

	tensor_t input_tensor=get_graph_input_tensor(graph , node_idx , tensor_idx );


    int dims[] = {1, 3, img_h, img_w};
    set_tensor_shape(input_tensor, dims, 4);
    prerun_graph(graph);

    int repeat_count = 1;
    const char *repeat = std::getenv("REPEAT_COUNT");

    if (repeat)
        repeat_count = std::strtoul(repeat, NULL, 10);

    struct timeval t0, t1;
    float avg_time = 0.f;

    set_tensor_buffer(input_tensor, input_data, img_size * 4);

    gettimeofday(&t0, NULL);

    for (int i = 0; i < repeat_count; i++)
        run_graph(graph, 1);

    gettimeofday(&t1, NULL);

    float mytime = (float)((t1.tv_sec * 1000000 + t1.tv_usec) - (t0.tv_sec * 1000000 + t0.tv_usec)) / 1000;
    avg_time += mytime;
    
    std::cout << "--------------------------------------\n";
    std::cout << "repeat " << repeat_count << " times, avg time per run is " << avg_time / repeat_count << " ms\n";

	put_graph_tensor(input_tensor);
    free(input_data);
    postrun_graph(graph);
    destroy_runtime_graph(graph);

    remove_model(model_name);

    std::cout << "ALL TEST DONE\n";

	release_tengine_library();

    return 0;
}