Poor dnn::DNN_TARGET_CPU performance compared to a C++ app

Ask question on using Emgu CV with C#
Post Reply
alexyz
Posts: 2
Joined: Tue Nov 26, 2019 11:07 am

Poor dnn::DNN_TARGET_CPU performance compared to a C++ app

Post by alexyz » Tue Nov 26, 2019 11:47 am

I have inherited a simple C++ app that uses OpenCV 4.12 and does object detection using custom neural network from frames of a video source. I have written a brand new app in C# based on this C++ app using Emgu.CV. Functionally the two apps are working 100% the same. Yet while the C++ app achieves 2.3fps on my laptop, the C# app gets only about 0.75fps. I have narrowed it down to:

Code: Select all

	net.setPreferableTarget(dnn::DNN_TARGET_CPU); 
When I modify both apps to use either DNN_TARGET_OPENCL or DNN_TARGET_OPENCL_FP16, I get the same frame rate. When I use DNN_TARGET_CPU, the C++ app performs 2-3x as good. What could be slowing down the C# app? As far as I can tell EMGU.CV is just a high level wrapper around native code. Could the performance difference have something to do with the way native code was built (e.g. optimizations)?
  • CPU usage of the two apps is almost the same (82% for C++ vs 78% for C#)
  • C++ app uses OpenCV 4.12 while the C# app uses Emgu CV based on OpenCV 4.11
  • Swapping EMGU.CV for EMGU.CV-CUDA does nothing
After dumping "build information" in both apps I can see that the most notable difference is in the "CPU/HW features:" section. The C++ OpenCV build (downloaded from the OpenCV site) has the following enabled (while these are completely missing from the Emgu.CV side):

Code: Select all

    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (14 files):         + SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (4 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (27 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (3 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
Could this be the game changer? If so, is there an Emgu.CV build that has these enabled?

Build info dumps are attached.
Attachments
build-infos.zip
(4.07 KiB) Downloaded 32 times

Post Reply