Server 1(P40): 50fps, inference time is about 20 ms (image preprocessing 6-7ms + tvm m.set_input 2-3ms + tvm m.run/m.get_output 2.5ms + tvm api nms 0.2ms + cv2 read video frame 8-9ms)
Server 2(V100): 22fps, inference time is about 43 ms (image preprocessing 32-33ms + tvm m.set_input 2-3ms + tvm m.run/m.get_output 1-2ms + tvm api nms 0.2ms + cv2 read video frame 5-6ms)
Server 1: haven’t rebuilt tvm. before running python darknet_evaluate.py, set env var export TVM_NUM_THREADS=8 & export TVM_BIND_THREADS=8, then i get 80-90 fps.
Server 2: rebuild tvm with set(USE_OPENMP gnu),then i get 90-100fps.
I think the reason is exclude_worker0. We default set it be true and will bind the master thread to core 0. When OpenCV thread enter into, then I find core0 is 100% very long time.
So I think better way is set exclude_worker0 to be false default.
// if excluding worker 0 and using master to run task 0
#ifndef _LIBCPP_SGX_CONFIG
bool exclude_worker0_{true};
#else
bool exclude_worker0_{false};
#endif
We set exclude_worker0_ to be true by default because in most of the cases the master has not much to do. In your case if you have heavy work in the master, you can manually set it to be false. BTW, I think we should have a way to specify this value via an ENV VAR.
So yes, we should add env var to do it. For example, we could add TVM_EXCLUDER_WORKER0 to handle it. Then if users pass TVM_EXCLUDER_WORKER0=0, we change the value be false. How about this solution?
A common use case is auto tuning. If we quantize a model (which starts threadpool during constant folding), and then extract tasks and tune them, it will be very slow because only thread0 is used instead of every thread. So it is necessary to let users to know
@vinx13@yidawang would you mind I opening one PR to get the environment TVM_EXCLUDER_WORKER0 value? I think it is common to meet this problem when to use OpenCV or auto tuning said by @vinx13. We should have one way to solve it.
@vinx13 I agree with you. At lease 2 cases we need it.
OpenCV + TVM at this case, which is common when we use TVM deploy CNN models in production
Auto Tuning
I prefere change the default value of exclude_worker0_, i.e. bool exclude_worker0_{false}; then we expose one environment of TVM_EXCLUDER_WORKER0, when we meet 1, we change it to be true. I think it is more reasonable.