| 60 | } |
| 61 | |
| 62 | int test_graph(graph_t graph, const char* dump_file, const float means[], const float scale) |
| 63 | { |
| 64 | /* get input tensor */ |
| 65 | tensor_t input_tensor = get_graph_input_tensor(graph, 0, 0); |
| 66 | if(input_tensor == nullptr) |
| 67 | { |
| 68 | std::printf("Cannot find input tensor of graph\n"); |
| 69 | return -1; |
| 70 | } |
| 71 | |
| 72 | int dims[] = {1, 3, img_h, img_w}; |
| 73 | set_tensor_shape(input_tensor, dims, 4); |
| 74 | |
| 75 | /* setup input buffer */ |
| 76 | float* input_data = ( float* )malloc(sizeof(float) * img_h * img_w * 3); |
| 77 | get_input_data(image_file, input_data, img_h, img_w, means, scale); |
| 78 | |
| 79 | if(set_tensor_buffer(input_tensor, input_data, 3 * img_h * img_w * 4) < 0) |
| 80 | { |
| 81 | std::printf("Set buffer for tensor failed\n"); |
| 82 | return -1; |
| 83 | } |
| 84 | |
| 85 | /* run the graph */ |
| 86 | int ret_prerun = prerun_graph(graph); |
| 87 | if(ret_prerun < 0) |
| 88 | { |
| 89 | std::printf("prerun failed\n"); |
| 90 | return -1; |
| 91 | } |
| 92 | // dump_graph(graph); |
| 93 | |
| 94 | unsigned long start_time = get_cur_time(); |
| 95 | |
| 96 | for(int i = 0; i < repeat_count; i++) |
| 97 | run_graph(graph, 1); |
| 98 | |
| 99 | unsigned long end_time = get_cur_time(); |
| 100 | |
| 101 | unsigned long off_time = end_time - start_time; |
| 102 | std::printf("Repeat [%d] time %.2f us per RUN. used %lu us\n", repeat_count, 1.0f * off_time / repeat_count, |
| 103 | off_time); |
| 104 | |
| 105 | /* get output tensor */ |
| 106 | tensor_t output_tensor = get_graph_output_tensor(graph, 0, 0); |
| 107 | if(output_tensor == nullptr) |
| 108 | { |
| 109 | std::printf("Cannot find output tensor\n"); |
| 110 | return -1; |
| 111 | } |
| 112 | |
| 113 | int size = get_tensor_buffer_size(output_tensor); |
| 114 | std::printf("output tensor buffer size: %d\n", size); |
| 115 | |
| 116 | float* data1 = ( float* )get_tensor_buffer(output_tensor); |
| 117 | |
| 118 | dump_float(dump_file, data1, size / 4); |
| 119 |
no test coverage detected