From ad901e5489564d0035be0b4ec41f1cff4be96610 Mon Sep 17 00:00:00 2001 From: Dmitrii Zarukin Date: Sun, 10 Oct 2021 22:45:37 -0700 Subject: [PATCH] threadpool: work around an issue of zero threads identified on AMD XByak can't identify threads on AMD due to implementation limitation. To work around it, we use a method from std if XByak returned zero threads. It may happen that Intel HW not supported via XByak may result in same issue but the chance is pretty low. --- src/cpu/platform.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cpu/platform.cpp b/src/cpu/platform.cpp index 9570c78d741..980a604d7c5 100644 --- a/src/cpu/platform.cpp +++ b/src/cpu/platform.cpp @@ -160,6 +160,13 @@ unsigned get_num_cores() { // function supports process affinity. unsigned get_max_threads_to_use() { int num_cores_per_socket = (int)dnnl::impl::cpu::platform::get_num_cores(); + // It may happen that XByak doesn't get num of threads identified, e.g. for + // AMD. In order to make threadpool working, we supply an additional + // condition to have some reasonable number of threads available at + // primitive descriptor creation time. + if (num_cores_per_socket == 0) + num_cores_per_socket = std::thread::hardware_concurrency(); + #if defined(_WIN32) DWORD_PTR proc_affinity_mask; DWORD_PTR sys_affinity_mask;