10000 [Caffe2] Handle `cpuinfo_initialize()` failure (#114011) · pytorch/pytorch@310e306 · GitHub
[go: up one dir, main page]

Skip to content

Commit 310e306

Browse files
malfetpytorchmergebot
authored andcommitted
[Caffe2] Handle cpuinfo_initialize() failure (#114011)
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 Pull Request resolved: #114011 Approved by: https://github.com/kit1980 ghstack dependencies: #113771
1 parent 855a5cf commit 310e306

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

caffe2/utils/threadpool/ThreadPool.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ namespace {
4646

4747
size_t getDefaultNumThreads() {
4848
#if !defined(__s390x__) && !defined(__powerpc__)
49-
CAFFE_ENFORCE(cpuinfo_initialize(), "cpuinfo initialization failed");
50-
int numThreads = cpuinfo_get_processors_count();
49+
auto numThreads = 1U;
50+
if (cpuinfo_initialize()) {
51+
numThreads = std::max(cpuinfo_get_processors_count(), 1U);
52+
} else {
53+
LOG(WARNING) << "cpuinfo initialization failed";
54+
numThreads = std::max(std::thread::hardware_concurrency(), 1U);
55+
}
5156

5257
bool applyCap = false;
5358
#if defined(C10_ANDROID)
@@ -101,7 +106,7 @@ size_t getDefaultNumThreads() {
101106
}
102107
}
103108
#else
104-
int numThreads = std::max<int>(std::thread::hardware_concurrency(), 1);
109+
auto numThreads = std::max(std::thread::hardware_concurrency(), 1U);
105110
#endif
106111

107112
if (FLAGS_pthreadpool_size) {
@@ -117,7 +122,7 @@ size_t getDefaultNumThreads() {
117122
* detect if we are running under tsan, for now capping the default
118123
* threadcount to the tsan limit unconditionally.
119124
*/
120-
int tsanThreadLimit = 63;
125+
auto tsanThreadLimit = 63U;
121126
numThreads = std::min(numThreads, tsanThreadLimit);
122127

123128
return numThreads;

0 commit comments

Comments
 (0)
0