MCPcopy Create free account
hub / github.com/OAID/Tengine / test_op

Function test_op

internal/bin/test_hardswish.cpp:186–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

184}
185
186int test_op(int c, int h, int w, const char* test_node_name, int layout, int data_type, float alpha, float beta)
187{
188 graph_t graph = create_test_graph(test_node_name, c, h, w, layout, data_type, alpha, beta);
189
190 if(graph == nullptr)
191 return -1;
192
193 /* set input */
194 tensor_t input_tensor = get_graph_input_tensor(graph, 0, 0);
195
196 int buf_size = get_tensor_buffer_size(input_tensor);
197 float* i_buf = ( float* )malloc(buf_size);
198 FILE *infp;
199 infp=fopen("./data/hardswish_in.bin","rb");
200 if(fread(i_buf, sizeof(float), buf_size/sizeof(float), infp)==0)
201 {
202 printf("read input data file failed!\n");
203 return false;
204 }
205 fclose(infp);
206
207 // for(unsigned int i = 0; i < buf_size/sizeof(float) ; i++)
208 // {
209 // i_buf[i] = i;
210 // }
211 set_tensor_buffer(input_tensor, i_buf, buf_size);
212 release_graph_tensor(input_tensor);
213
214 if(prerun_graph(graph) < 0)
215 {
216 std::cerr << "prerun_graph failed: ERRNO: " << get_tengine_errno() << "\n";
217 return 1;
218 }
219 // get device
220 node_t test_node = get_graph_node(graph, test_node_name);
221 // const char* dev = get_node_device(test_node);
222
223 // std::cout << "node running on dev: " << dev << "\n";
224
225 // run graph and time calc
226 int repeat_count = 1;
227 const char * rep_str=std::getenv("REPEAT");
228 if(rep_str)
229 repeat_count=strtoul(rep_str,NULL,10);
230
231 // unsigned long start_time = get_cur_time();
232 for(int i=0;i<repeat_count;i++)
233 {
234 run_graph(graph,1);
235 }
236 // unsigned long end_time = get_cur_time();
237 // unsigned long off_time = end_time - start_time;
238 // std::printf("Repeat [%d] time %.2f us per RUN. used %lu us\n", repeat_count, 1.0f * off_time / repeat_count,
239 // off_time);
240
241 tensor_t output_tensor = get_node_output_tensor(test_node, 0);
242 int size = get_tensor_buffer_size(output_tensor);
243 float* buf = ( float* )get_tensor_buffer(output_tensor);

Callers 1

mainFunction · 0.70

Calls 15

get_graph_input_tensorFunction · 0.85
get_tensor_buffer_sizeFunction · 0.85
set_tensor_bufferFunction · 0.85
release_graph_tensorFunction · 0.85
prerun_graphFunction · 0.85
get_tengine_errnoFunction · 0.85
get_graph_nodeFunction · 0.85
run_graphFunction · 0.85
get_node_output_tensorFunction · 0.85
get_tensor_bufferFunction · 0.85
release_graph_nodeFunction · 0.85
postrun_graphFunction · 0.85

Tested by

no test coverage detected