oneDNN icon indicating copy to clipboard operation
oneDNN copied to clipboard

Performance issue on windows PC

Open uu-praveeng opened this issue 7 years ago • 18 comments

Hi,

I have created a sample network using MKLDNN apis and when I try to run inference in a continuous loop I am not seeing the 100% CPU usage . But in Linux when I repeat the same experiment I see 100% CPU usage .

Is there any constraint impose on Windows side by the OS ? How can we make sure the CPU resources are efficiently used by MKLDNN on Windows side?

Thank you, Praveen.

uu-praveeng avatar Jan 08 '19 15:01 uu-praveeng

Hi @uu-praveeng,

In general there should not be big difference in performance of Intel MKL-DNN on Windows or Linux. So I would say the behavior your observe is strange.

The only 2 differences that come to my mind are:

  • MSVC doesn't support some OpenMP features; but that should not matter a lot
  • On Linux if you use GCC 6+ or Intel Compiler the library is built with -march=native (or similar), that tunes the code for the given platform, while on Windows for MSVC generic flags are used; but that should not matter a lot as well since most of the code in the library is jitted

So to understand what happens more information is needed. Could you please provide the following information:

  • Compilers you use on both systems
  • Whether you use or not Intel MKL-ML binary dependency
  • Run you application with MKLDNN_VERBOSE=1 so that we can understand which primitive behaves differently

emfomenk avatar Jan 09 '19 03:01 emfomenk

Hi @emfomenk ,

  • Compilers you use on both systems

Linux compiler - g++ (Debian 6.3.0-18+deb9u1) 6.3.0 20170516 Windows compiler - Default compiler shipped in MSVC 2017(Visual C++ 14.1)

  • Whether you use or not Intel MKL-ML binary dependency Yes we are using the MKL-ML binaries
  • Run you application with MKLDNN_VERBOSE=1 so that we can understand which primitive behaves differently We have attached the same for your reference . Windows and Linux PC as the same configuration Intel Xeon CPU E5-1650 v4 @ 3.60GHz

Note We tried to run the sample network on 2 Windows PCs . One of the PC has Windows as a virtaul machine and has 2 virtual cores and the other has Windows as a primay OS and it has 6cores(12 logical cores) .When we ran on 2 PC's we are getting the numbers to be almost same 1.9 seconds. Ideally the numbers should bump up on the 2nd PC which has the 6 cores. So this confirms that mkldnn is not fully utilizing the resources.

Thank you, Praveen. Linux_mkldnnverbose.txt windows_mkldnnverbose.txt

uu-praveeng avatar Jan 09 '19 06:01 uu-praveeng

Hi @uu-praveeng,

Thanks for the log files and info! Seems like on Windows Intel MKL-DNN doesn't user OpenMP parallelization for some reasons... May I ask you to post you a cmake output as well (appeared when you built Intel MKL-DNN).

Can you please also confirm that OMP_NUM_THREADS environment variable is not set.

Finally (and maybe the most important), what version of Intel MKL-DNN do you use? I assume you use relatively fresh version of Intel MKL-DNN (at least v0.16, better v0.17+). If not, please try to update the library.

emfomenk avatar Jan 10 '19 10:01 emfomenk

Hi @emfomenk ,

Below is the cmake output when we generated the cmake files -- Selecting Windows SDK version 10.0.15063.0 to target Windows 10.0.17134. -- The C compiler identification is MSVC 19.11.25507.1 -- The CXX compiler identification is MSVC 19.11.25507.1 -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.11.25503/bin/HostX86/x64/cl.exe -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.11.25503/bin/HostX86/x64/cl.exe -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.11.25503/bin/HostX86/x64/cl.exe -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.11.25503/bin/HostX86/x64/cl.exe -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- CMAKE_BUILD_TYPE is unset, defaulting to Release -- Detecting Intel(R) MKL: trying mklml_intel -- Detecting Intel(R) MKL: trying mklml_gnu -- Detecting Intel(R) MKL: trying mklml -- Intel(R) MKL: include C:/Praveen/Project/DeepLearning/Intel/mkl-dnn-0.17.2/mkl-dnn-0.17.2/external/include -- Intel(R) MKL: lib C:/Praveen/Project/DeepLearning/Intel/mkl-dnn-0.17.2/mkl-dnn-0.17.2/external/lib/mklml.lib -- Intel(R) MKL: dll C:/Praveen/Project/DeepLearning/Intel/mkl-dnn-0.17.2/mkl-dnn-0.17.2/external/lib/mklml.dll -- OpenMP lib: C:/Praveen/Project/DeepLearning/Intel/mkl-dnn-0.17.2/mkl-dnn-0.17.2/external/lib/libiomp5md.lib -- OpenMP dll: C:/Praveen/Project/DeepLearning/Intel/mkl-dnn-0.17.2/mkl-dnn-0.17.2/external/lib/libiomp5md.lib -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) -- VTune profiling environment is unset -- Looking for pthread.h -- Looking for pthread.h - not found -- Found Threads: TRUE -- Configuring done -- Generating done -- Build files have been written to: C:/Praveen/Project/DeepLearning/Intel/mkl-dnn-0.17.2/mkl-dnn-0.17.2/build

Is this the cmake that you need? I didnot set OMP_NUM_THREADS environment variable. I am using the mkldnn v.17

Thank you, Praveen.

uu-praveeng avatar Jan 10 '19 11:01 uu-praveeng

Hi @uu-praveeng,

Yes, that what I wanted to look at. Thanks! Everything looks good to me here. And now I am almost run out of ideas...

In fact in the verbose output you sent there are few places where Windows is faster than Linux. But this is just a side note.

I know that memory initialization might be quite expensive on Windows. Do you pre-allocate memory in your benchmark, or allocation happens every time before a primitive runs? Does benchmark do a real inference or it just runs primitives on uninitialized memory to proxy the real execution?

emfomenk avatar Jan 10 '19 11:01 emfomenk

Another side note.

I noticed your topology has quite regular pattern: conv -> relu. Intel MKL-DNN supports fusion of such sequence: conv (w/ post-op: relu). The API is described here. An example can be seen here.

Based on logs you sent the fusion might save you another ~100 ms out of 700ms.

This is just for your information and is not related to the issue itself.

emfomenk avatar Jan 10 '19 11:01 emfomenk

Hi @emfomenk ,

Our workflow is as mentioned below

  • We do the memory initialization prior and it is only once .
  • Once the memory and layer primitives are initialized I give a sample image and loop the inference continuously.
  • We have used chrono to capture start and end time and display it for every inference.

Thanks for pointing out though on the conv relu fusion . Yes it does save some ms. But our problem is beyond that.

Could you profile any standard network(alexnet) on the linux and windows and compare the result. I just want to know if this behaviour is specific to my network.

Thank you, Praveen.

uu-praveeng avatar Jan 10 '19 11:01 uu-praveeng

Hi @uu-praveeng,

We do the memory initialization prior and it is only once .

Does it mean that the memory allocated and you put some values there as well? So that Intel MKL-DNN primitives never touch uninitialized memory (even the output memory).

Could you profile any standard network(alexnet) on the linux and windows and compare the result. I just want to know if this behaviour is specific to my network.

I don't have an access to any Windows system right now, so I will ask someone from the team to make an experiment you suggested (we exactly have a pseudo-AlexNet inference in our examples). But so far we've never faced the case when Windows is much slower than Linux because of the library.

Meanwhile may I ask you to run few convolutions using benchdnn -- our performance benchmark. Once you built Intel MKL-DNN, benchdnn should be compiled as well. Let's take the convolution that differs the most between Linux and Windows:

$ ./tests/benchdnn/benchdnn --conv --mode=P \
    mb1_g1ic128oc128_ih184oh184kh3sh1dh0ph1_iw136ow136kw3sw1dw0pw1

On my 4 cores Skylake (client) system the output was:

perf,"wip",g1mb1ic128ih184iw136oc128oh184ow136kh3kw3ph1pw1n"wip",7.31709,0,22.3428,327.493,24.2459,301.786
tests:1 passed:0 skipped:0 mistrusted:0 unimplemented:0 failed:0
total perf: min(ms):22.3428 avg(ms):24.2459

Please run the command at least on Windows to check whether the numbers would match what we saw in the verbose: 120 ms on Windows or 12 ms on Linux.

emfomenk avatar Jan 10 '19 11:01 emfomenk

Hi @emfomenk ,

Yes, we initialize the weights and bias primitives with the network filter weights and biases one time . Rest of the memories like layer input and output will be allocated but not be filled ,they will be updated during the runtime.

I will run the command " ./tests/benchdnn/benchdnn --conv --mode=P
mb1_g1ic128oc128_ih184oh184kh3sh1dh0ph1_iw136ow136kw3sw1dw0pw1 " and will update the results for both windows and linux.

Thank you, Praveen.

uu-praveeng avatar Jan 11 '19 08:01 uu-praveeng

Hi @uu-praveeng,

input and output will be allocated but not be filled ,they will be updated during the runtime

That might be the issue. While input is not an issue, since this input is actually an output for someone else, the untouched output might cause this difference. Malloc returns a pointer that OS might prepare only at first touch. This preparation might be very time consuming.

Hence the code like:

    dst = malloc(dst_sz);
    conv(src, wei, dst); // conv touches the dst for the first time,
                         // so OS intercepts the process to prepare actually memory pages.
                         // That leads to a 'slow' convolution

might make the convolution slow due to OS specifics.

Hopefully, benchdnn will shed light on the situation. If the performance of a convolution would be as good as on Linux -- than I think the reason is as I said. Otherwise something really weird is going on.

emfomenk avatar Jan 11 '19 09:01 emfomenk

Hi @emfomenk ,

I agree that for the first inference of the network the numbers could be high. However, we are seeing consistently higher numbers which I shared you in the log file.

I shall get back to you once I run the conv.

Thank you, Praveen.

uu-praveeng avatar Jan 11 '19 09:01 uu-praveeng

I see. So your code is actually:

    dst = malloc(dst_size);
    for (i = 0; i < iters; ++i) // iters > 1
        conv(src, wei, dst);

If this is the case, then you are right, my guess is most likely incorrect...

emfomenk avatar Jan 11 '19 09:01 emfomenk

Yes, that is true @emfomenk.

uu-praveeng avatar Jan 11 '19 09:01 uu-praveeng

Hi @emfomenk, Sorry for delayed response and I have couple of observations

  1. In MKLDNN V0.17, simple_net.cpp that is shipped with the mkldnn source gives almost same number on both Windows and Linux.
  2. In MKLDNN V0.14, simple_net.cpp that is shipped with the mkldnn source gives different number on both Windows and Linux. Linux has better performance than windows.

Please let me know if my observations are correct.

Thank you, Praveen.

Subarukun avatar Feb 01 '19 08:02 Subarukun

Hi @Subarukun,

Please let me know if my observations are correct.

In general, I confirm this. Some details:

In v0.14 we didn't have OpenMP enabled for MSVC (Windows), so the performance might be significantly worse on this platform. There should not be significant difference if Intel Compiler is used though.

For v0.17 OpenMP is enabled for both Windows and Linux, so the performance should be similar.

emfomenk avatar Feb 04 '19 15:02 emfomenk

Thank you @emfomenk, this answers my queries.

uu-praveeng avatar Feb 04 '19 17:02 uu-praveeng

Hi @emfomenk,

You have stated "In v0.14 we didn't have OpenMP enabled for MSVC (Windows)," I am just curious to know ,Is there any way the user can enable the openmp in during the build process of V0.14 on Windows.

Thank you, Praveen.

uu-praveeng avatar Feb 05 '19 16:02 uu-praveeng

Well, that wouldn't be a trivial task. Basically you would need to backport the commit dae437dd6289ba1798983747930b2d1a70dcfded. Or update v0.14 to at least v0.15...

emfomenk avatar Feb 05 '19 16:02 emfomenk