mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

Concurrent threads make inference slow [C++]

Open indhub opened this issue 9 years ago • 4 comments

I tried doing multiple inference in parallel on EC2 C4.8xl. If it takes one second to run inference on one image using one thread, I would expect the time (1 sec) to remain the same if I run inference using multiple threads in parallel given C4.8xl has 36 virtual CPUs. But here is what I observe:

Running one thread: Each inference takes around 1.5 sec

Running 2 concurrent threads: Each inference takes around 2.5 sec

Running 4 concurrent threads: Each inference takes around 5 sec

Here is the code I used to test: https://github.com/indhub/MultithreadTest I used the Inception BN model from http://data.mxnet.io/models/imagenet/inception-bn/

Here is output from the above code on C4.8XL:

$ ./MultithreadTest 1 1 ~/market.jpg ./Inception-BN-symbol.json ./Inception-BN-0126.params
./Inception-BN-symbol.json ... 116922 bytes
./Inception-BN-0126.params ... 45284780 bytes
[18:36:12] src/nnvm/legacy_json_util.cc:175: Loading symbol saved by previous version v0.8.0. Attempting to upgrade...
Thread 0, inference: 0 took 1.41173 sec
Thread 0, inference: 1 took 1.74076 sec
Thread 0, inference: 2 took 1.42546 sec
Thread 0, inference: 3 took 1.60324 sec
^C
$ ./MultithreadTest 1 2 ~/market.jpg ./Inception-BN-symbol.json ./Inception-BN-0126.params
./Inception-BN-symbol.json ... 116922 bytes
./Inception-BN-0126.params ... 45284780 bytes
[18:36:24] src/nnvm/legacy_json_util.cc:175: Loading symbol saved by previous version v0.8.0. Attempting to upgrade...
[18:36:24] src/nnvm/legacy_json_util.cc:175: Loading symbol saved by previous version v0.8.0. Attempting to upgrade...
Thread 1, inference: 0 took Thread 0, inference: 0 took 2.696722.69671 sec sec

Thread 1, inference: 1 took 2.60908 sec
Thread 0, inference: 1 took 2.60915 sec
Thread 1, inference: 2 took 2.78573 sec
Thread 0, inference: 2 took 2.78579 sec
Thread 1, inference: 3 took 2.57807 sec
Thread 0, inference: 3 took 2.57808 sec
^C
$ ./MultithreadTest 1 4 ~/market.jpg ./Inception-BN-symbol.json ./Inception-BN-0126.params
./Inception-BN-symbol.json ... 116922 bytes
./Inception-BN-0126.params ... 45284780 bytes
[18:36:40] src/nnvm/legacy_json_util.cc:175: Loading symbol saved by previous version v0.8.0. Attempting to upgrade...
[18:36:41] src/nnvm/legacy_json_util.cc:175: Loading symbol saved by previous version v0.8.0. Attempting to upgrade...
[18:36:41] src/nnvm/legacy_json_util.cc:175: Loading symbol saved by previous version v0.8.0. Attempting to upgrade...
[18:36:41] src/nnvm/legacy_json_util.cc:175: Loading symbol saved by previous version v0.8.0. Attempting to upgrade...
Thread 3, inference: 0 took Thread 2, inference: 0 took Thread 0, inference: 0 took Thread 1, inference: 0 took 4.25137 sec4.251344.25141 sec sec
4.25136 sec


Thread 1, inference: 1 took 4.31107 sec
Thread 2, inference: 1 took 4.31115 sec
Thread 0, inference: 1 took 4.31267 sec
Thread 3, inference: 1 took 4.31262 sec
Thread 1, inference: 2 took 4.98741 sec
Thread 2, inference: 2 took 4.98754 sec
Thread 0, inference: 2 took 4.98776 sec
Thread 3, inference: 2 took 4.98756 sec
Thread 1, inference: 3 took 5.01988 sec
Thread 2, inference: 3 took 5.01992 sec
Thread 0, inference: 3 took 5.01987 sec
Thread 3, inference: 3 took 5.01987 sec

Environment info

Operating System: Amazon Linux

Compiler: gcc --version gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9) Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Package used (Python/R/Scala/Julia): C++

MXNet version:

Or if installed from source:

MXNet commit hash (git rev-parse HEAD): git rev-parse HEAD e4d5e60ec3feaff7f844ae2f35431189ead1f52e

Minimum reproducible example

https://github.com/indhub/MultithreadTest

Steps to reproduce

https://github.com/indhub/MultithreadTest/blob/master/README.md

indhub avatar Mar 16 '17 18:03 indhub

how did you build mxnet? what's your config? unless you turned off openmp, blas, and mkl, mxnet is already multi threaded

piiswrong avatar Mar 16 '17 19:03 piiswrong

I didn't turn off any of that. I left config as it is except for setting "USE_BLAS=openblas".

If I understand you correct, you are saying MXNet is already multithreaded and no big throughput gain can be achieved by running multiple inference in parallel using concurrent threads. Is my understanding correct?

indhub avatar Mar 16 '17 19:03 indhub

yes

piiswrong avatar Mar 16 '17 20:03 piiswrong

Thanks for the clarification. I'll close this ticket.

indhub avatar Mar 16 '17 22:03 indhub