mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Fix deadlock issues in ThreadPool (#29885)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/29885 ### Summary Currently, we have a deadlock issue on iOS when running Resnet50. The problem happens when the task being run in the ThreadPool wants to call `getNumThread()` who will try to acquire the same mutex. And thus cause the deadlock situation. The fix is just remove the guard for `_numThreads`, as it's not likely to change after initialization. ### Test Plan 1. Generate a Resnet50 model using trace_model.py 2. Run `ios/TestApp/bootstrap.sh` to do the benchmark cc shoumikhin AshkanAliabadi Test Plan: Imported from OSS Differential Revision: D18533505 Pulled By: xta0 fbshipit-source-id: 2a069d20b59833ec8b02ff05515c3739a85a15de
This commit is contained in:
parent
0a33c3f1a1
commit
b730d04ed2
|
|
@ -214,7 +214,7 @@ int get_num_threads() {
|
|||
#else
|
||||
caffe2::ThreadPool* pool = caffe2::mobile_threadpool();
|
||||
// caffe2::ThreadPool::getNumThreads() counts the current thread.
|
||||
return !pool ? 1 /* current thread */ : pool->getNumThreads();
|
||||
return !pool || in_parallel_region() ? 1 /* current thread */ : pool->getNumThreads();
|
||||
#endif // C10_MOBILE
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,6 @@ ThreadPool::ThreadPool(int numThreads)
|
|||
ThreadPool::~ThreadPool() {}
|
||||
|
||||
int ThreadPool::getNumThreads() const {
|
||||
std::lock_guard<std::mutex> guard(executionMutex_);
|
||||
return numThreads_;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user