8000 [Caffe2] Handle `cpuinfo_initialize()` failure (#114418) · pytorch/pytorch@d62c757 · GitHub
[go: up one dir, main page]

Skip to content

Commit d62c757

Browse files
authored
[Caffe2] Handle cpuinfo_initialize() failure (#114418)
It can fail on ARM platform if `/sys` folder is not accessible. In that case, call `std::thread::hardware_concurrency()`, which is aligned with the thread_pool initialization logic of `c10::TaskThreadPoolBase:defaultNumThreads()` Further addresses issue raised in #113568 This is a cherry-pick of #114011 into release/2.1 branch (cherry picked from commit 310e306)
1 parent 7833889 commit d62c757

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

caffe2/utils/threadpool/ThreadPool.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ namespace {
4141
}
4242

4343
size_t getDefaultNumThreads() {
44-
CAFFE_ENFORCE(cpuinfo_initialize(), "cpuinfo initialization failed");
45-
int numThreads = cpuinfo_get_processors_count();
44+
auto numThreads = 1U;
45+
if (cpuinfo_initialize()) {
46+
numThreads = std::max(cpuinfo_get_processors_count(), 1U);
47+
} else {
48+
LOG(WARNING) << "cpuinfo initialization failed";
49+
numThreads = std::max(std::thread::hardware_concurrency(), 1U);
50+
}
4651

4752
bool applyCap = false;
4853
#if defined(C10_ANDROID)
@@ -109,7 +114,7 @@ size_t getDefaultNumThreads() {
109114
* detect if we are running under tsan, for now capping the default
110115
* threadcount to the tsan limit unconditionally.
111116
*/
112-
int tsanThreadLimit = 63;
117+
auto tsanThreadLimit = 63U;
113118
numThreads = std::min(numThreads, tsanThreadLimit);
114119

115120
return numThreads;

0 commit comments

Comments
 (0)
0