You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by Minmin Sun via Apache TVM Discuss <no...@discuss.tvm.ai> on 2021/07/02 08:03:34 UTC

[Apache TVM Discuss] [Questions] [MultiThread][ThreadPool] Performance degradation when running relay module in multiple threads


* Device: Skylake 8163 with 48 pysical cores

* Env Setting: TVM_BIND_THREADS=0 TVM_NUM_THREADS=4

* Code Snippet:
 ```
module = graph_executor.GraphModule(lib["default"](ctx))
def thread_run:
    for i in range(repeats):
        module.run()
threads = []
    for i in range(num_threads):
       threads.append(PropagatingThread(
            target=process_run,
       ))
```

* When num_threads=1
![A1F69032-BCEC-46B1-8118-493FD1CB2F4A|690x243](upload://dp2QT4TXdrbFRbv6yymzxVzedX5.jpeg) 
There are 4 physical cores are occupied by TVM thread pool.
Each module.run() taskes 4ms.

* When num_threads=2
![7A20D611-CD6E-4979-9FEB-F4513845C1B7|690x245](upload://pF3As7eLVn24DwiT0Lq06j0W9zx.jpeg) 
There are 8  physical cores are occupied by TVM thread pools.
Each module.run() taskes 8ms.

Since there are still 4 physical cores occupied by each thread in 2-threaded run, the performace is expected to be the same as single-threaded run. But the performace of each thread in 2-threaded run actually is only as 50% of single-threaded run,  and 4 -threaded run is only as 25% and so on...

Any idea about the performance degradation in multi-threaded run?





---
[Visit Topic](https://discuss.tvm.apache.org/t/multithread-threadpool-performance-degradation-when-running-relay-module-in-multiple-threads/10374/1) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/14ff3fa1c2117c9db5c1e949ea76a403d3cbe24a869b88713393a5fb44ad9a44).

[Apache TVM Discuss] [Questions] [MultiThread][ThreadPool] Performance degradation when running relay module in multiple threads

Posted by Chenfan via Apache TVM Discuss <no...@discuss.tvm.ai>.

Help to at if anyone have experience on this

@tqchen @junrushao1994 @comaniac @FrozenGene :smiley:





---
[Visit Topic](https://discuss.tvm.apache.org/t/multithread-threadpool-performance-degradation-when-running-relay-module-in-multiple-threads/10374/2) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/0ccfb088128e6073160d76d074c3b060608b723e39a80e3eab4c82b073d56440).

[Apache TVM Discuss] [Questions] [MultiThread][ThreadPool] Performance degradation when running relay module in multiple threads

Posted by Minmin Sun via Apache TVM Discuss <no...@discuss.tvm.ai>.

Yes, it also has the same problem running on omp as threading backend. We didn't see much difference between TVM ThreadPool and OMP in such cases.





---
[Visit Topic](https://discuss.tvm.apache.org/t/multithread-threadpool-performance-degradation-when-running-relay-module-in-multiple-threads/10374/7) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/7683f252a793a7eda146b2ab8f92079c58398b64fea7740659f66d0bfb73c83f).

[Apache TVM Discuss] [Questions] [MultiThread][ThreadPool] Performance degradation when running relay module in multiple threads

Posted by Zhao Wu via Apache TVM Discuss <no...@discuss.tvm.ai>.

if we change the thread pool to OpenMP, do we have the same problem?





---
[Visit Topic](https://discuss.tvm.apache.org/t/multithread-threadpool-performance-degradation-when-running-relay-module-in-multiple-threads/10374/6) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/5176a4cf0ef6e63fd4a3e5081a1215d616e94cc30c5626e4d5d6b2f0d009aea1).

[Apache TVM Discuss] [Questions] [MultiThread][ThreadPool] Performance degradation when running relay module in multiple threads

Posted by Tristan Konolige via Apache TVM Discuss <no...@discuss.tvm.ai>.

Threads in python aren't actually executed concurrently due to the GIL. So the reason everything is slower is because you aren't actually doing anything in parallel. Also, it could be a lot of you time is actually spent in the python interpreter instead of executing you model. You should try using time evaluator (https://tvm.apache.org/docs/api/python/runtime.html#tvm.runtime.Module.time_evaluator) instead of your own python loop.





---
[Visit Topic](https://discuss.tvm.apache.org/t/multithread-threadpool-performance-degradation-when-running-relay-module-in-multiple-threads/10374/11) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/3e436386ee4915f592b2eec9812e5e7802fd90a4dfcafe8ceef5dcbe54d85d4d).

[Apache TVM Discuss] [Questions] [MultiThread][ThreadPool] Performance degradation when running relay module in multiple threads

Posted by Minmin Sun via Apache TVM Discuss <no...@discuss.tvm.ai>.

I found out that it might the problem of python thread.Thread instead of TVM.





---
[Visit Topic](https://discuss.tvm.apache.org/t/multithread-threadpool-performance-degradation-when-running-relay-module-in-multiple-threads/10374/10) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/f162c18fdf4b85cd7cf8577d4efa4fcf2d5d63528ed062fd000db51cc1fd2f69).

[Apache TVM Discuss] [Questions] [MultiThread][ThreadPool] Performance degradation when running relay module in multiple threads

Posted by Minmin Sun via Apache TVM Discuss <no...@discuss.tvm.ai>.

By "multi-prcocess" I mean run the python script two times simutaniously, while "multi-thread" is implemented by threading.Thread in python script.





---
[Visit Topic](https://discuss.tvm.apache.org/t/multithread-threadpool-performance-degradation-when-running-relay-module-in-multiple-threads/10374/9) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/f05c8b7cf0a5da90f4e7fef257b3c622cee446226f2948ab33134b647e4e55b7).

[Apache TVM Discuss] [Questions] [MultiThread][ThreadPool] Performance degradation when running relay module in multiple threads

Posted by Zhao Wu via Apache TVM Discuss <no...@discuss.tvm.ai>.

Do you mean if we use Python's multi process, you could get ideal result but use Python's multi thread, you get bad result? Or what else things you mean?





---
[Visit Topic](https://discuss.tvm.apache.org/t/multithread-threadpool-performance-degradation-when-running-relay-module-in-multiple-threads/10374/8) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/f31bb4a457e811648101962aada9d99bd00ebd320796b680d14a91c7f313f99a).

[Apache TVM Discuss] [Questions] [MultiThread][ThreadPool] Performance degradation when running relay module in multiple threads

Posted by Minmin Sun via Apache TVM Discuss <no...@discuss.tvm.ai>.

Add an addtional info: in multi-processed run, the performace of module.run() in each process does not drop.





---
[Visit Topic](https://discuss.tvm.apache.org/t/multithread-threadpool-performance-degradation-when-running-relay-module-in-multiple-threads/10374/5) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/76a72ff29158be3989b5d3a91446c9581cc3765fd96ca56b4819d6659508c921).

[Apache TVM Discuss] [Questions] [MultiThread][ThreadPool] Performance degradation when running relay module in multiple threads

Posted by Minmin Sun via Apache TVM Discuss <no...@discuss.tvm.ai>.

Thanks. It doesn't improve. Performace in both single-threaded run and multi-threaded run drop 10-20%, and CPU utilization drops from nearly 100% to nearly 50% with TVM_THREAD_POOL_SPIN_COUNT=0, which I think is reasonable.





---
[Visit Topic](https://discuss.tvm.apache.org/t/multithread-threadpool-performance-degradation-when-running-relay-module-in-multiple-threads/10374/4) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/ba15f213716dcb2e1641d54b600cbaa6a0d073539196ed39e7d446bd58a3282e).

[Apache TVM Discuss] [Questions] [MultiThread][ThreadPool] Performance degradation when running relay module in multiple threads

Posted by Zhao Wu via Apache TVM Discuss <no...@discuss.tvm.ai>.

[quote="MinminSun, post:1, topic:10374"]
TVM_NUM_THREADS
[/quote]

How about setting one environment  `TVM_THREAD_POOL_SPIN_COUNT = 0` , does it improve your case?





---
[Visit Topic](https://discuss.tvm.apache.org/t/multithread-threadpool-performance-degradation-when-running-relay-module-in-multiple-threads/10374/3) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/907a5258f5883dbd9392ef307818b4b1be3288e5dbd443f4e8aacab852f5a52d).