Followup patch for cpuinfo fix in ppc64le (#112707)

Previously a crash in PyTorch on power systems was fixed with #110708.
 Even with the fix, the torch_test.py test throws the following error
for one of the tests.
 "Error in cpuinfo: processor architecture is not supported in cpuinfo"
This is a follow up patch to fix this error.

Fixes #ISSUE_NUMBER

Pull Request resolved: https://github.com/pytorch/pytorch/pull/112707
Approved by: https://github.com/albanD
This commit is contained in:
vinithakv
2023-11-02 16:34:33 +00:00
committed by PyTorch MergeBot
parent 174aef71af
commit 82e428723a
10 changed files with 29 additions and 17 deletions

View File

@ -375,7 +375,7 @@ if(MKLDNN_FOUND)
list(APPEND ATen_CPU_DEPENDENCY_LIBS ${MKLDNN_LIBRARIES})
endif(MKLDNN_FOUND)
if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "s390x")
if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(s390x|ppc64le)$")
list(APPEND ATen_CPU_DEPENDENCY_LIBS cpuinfo)
endif()

View File

@ -1,6 +1,6 @@
#include <ATen/cpu/FlushDenormal.h>
#include <ATen/cpu/vec/intrinsics.h>
#if !defined(__s390x__)
#if !defined(__s390x__) && !defined(__powerpc__)
#include <cpuinfo.h>
#endif

View File

@ -1,12 +1,12 @@
#include <ATen/cpu/Utils.h>
#if !defined(__s390x__)
#if !defined(__s390x__ ) && !defined(__powerpc__)
#include <cpuinfo.h>
#endif
namespace at::cpu {
bool is_cpu_support_vnni() {
#if !defined(__s390x__)
#if !defined(__s390x__) && !defined(__powerpc__)
return cpuinfo_initialize() && cpuinfo_has_x86_avx512vnni();
#else
return false;

View File

@ -4,7 +4,7 @@
#include <c10/util/Exception.h>
#include <c10/macros/Macros.h>
#if !defined(__s390x__)
#if !defined(__s390x__) && !defined(__powerpc__)
#include <cpuinfo.h>
#endif
#include <cstdlib>

View File

@ -141,7 +141,7 @@
#include <string>
#include <tuple>
#include <utility>
#if !defined(__s390x__)
#if !defined(__s390x__) && !defined(__powerpc__)
#include <cpuinfo.h>
#endif
@ -1339,7 +1339,7 @@ static inline int64_t get_mkldnn_matmul_min_dim() {
const int64_t default_min_dim = [&] {
// Minimum dimension requirement for MKLDNN; derived based on experiments.
// By default, it's only enabled on Neoverse V1.
#if !defined(__s390x__)
#if !defined(__s390x__) && !defined(__powerpc__)
if (cpuinfo_initialize() && cpuinfo_get_uarchs_count() == 1 && cpuinfo_get_uarch(0)->uarch == cpuinfo_uarch_neoverse_v1) {
return 8;
}
@ -1358,7 +1358,7 @@ static inline int64_t get_mkldnn_matmul_min_size() {
const int64_t default_min_size = [&] {
// Minimum size requirement for MKLDNN; derived based on experiments.
// By default, it's only enabled on Neoverse V1.
#if !defined(__s390x__)
#if !defined(__s390x__) && !defined(__powerpc__)
if (cpuinfo_initialize() && cpuinfo_get_uarchs_count() == 1 && cpuinfo_get_uarch(0)->uarch == cpuinfo_uarch_neoverse_v1) {
return 8 * 1024;
}

View File

@ -4,7 +4,7 @@
#include <ATen/core/List.h>
#include <ATen/core/Tensor.h>
#include <c10/util/ArrayRef.h>
#if !defined(__s390x__)
#if !defined(__s390x__) && !defined(__powerpc__)
#include <cpuinfo.h>
#endif
#include <vector>

View File

@ -6,7 +6,7 @@
#include <ATen/native/quantized/cpu/QnnpackUtils.h>
#include <ATen/native/quantized/cpu/OnednnUtils.h>
#include <c10/util/irange.h>
#if !defined(__s390x__)
#if !defined(__s390x__) && !defined(__powerpc__)
#include <cpuinfo.h>
#endif

View File

@ -1,4 +1,4 @@
#if !defined(__s390x__)
#if !defined(__s390x__) && !defined(__powerpc__)
#include <cpuinfo.h>
#else
#include <unistd.h>
@ -18,7 +18,7 @@ uint32_t wipe_cache() {
static size_t wipe_size = 0;
if (wipe_buffer == nullptr) {
#if !defined(__s390x__)
#if !defined(__s390x__) && !defined(__powerpc__)
CAFFE_ENFORCE(cpuinfo_initialize(), "failed to initialize cpuinfo");
const cpuinfo_processor* processor = cpuinfo_get_processor(0);
if (processor->cache.l4 != nullptr) {
@ -80,7 +80,7 @@ uint32_t wipe_cache() {
break;
}
#endif
#else
#elif defined (__s390x__)
wipe_size = sysconf(_SC_LEVEL4_CACHE_SIZE);
if (wipe_size <= 0)
{
@ -89,6 +89,18 @@ uint32_t wipe_cache() {
*/
wipe_size = 1024 * 1024 * 1024;
}
#else
/* ppc64le */
wipe_size = sysconf(_SC_LEVEL4_CACHE_SIZE);
if (wipe_size <= 0) {
wipe_size = sysconf(_SC_LEVEL3_CACHE_SIZE);
if (wipe_size <= 0) {
wipe_size = sysconf(_SC_LEVEL2_CACHE_SIZE);
if(wipe_size <= 0) {
wipe_size = sysconf(_SC_LEVEL1D_CACHE_SIZE);
}
}
}
#endif
LOG(INFO) << "Allocating cache wipe buffer of size " << wipe_size;
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc)

View File

@ -2,7 +2,7 @@
#include "WorkersPool.h"
#include "caffe2/core/logging.h"
#if !defined(__s390x__)
#if !defined(__s390x__) && !defined(__powerpc__)
#include <cpuinfo.h>
#else
#include <thread>
@ -45,7 +45,7 @@ namespace {
}
size_t getDefaultNumThreads() {
#if !defined(__s390x__)
#if !defined(__s390x__) && !defined(__powerpc__)
CAFFE_ENFORCE(cpuinfo_initialize(), "cpuinfo initialization failed");
int numThreads = cpuinfo_get_processors_count();

View File

@ -432,9 +432,9 @@ else()
set(USE_PTHREADPOOL OFF CACHE BOOL "" FORCE)
endif()
if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "s390x")
if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(s390x|ppc64le)$")
# ---[ Caffe2 uses cpuinfo library in the thread pool
# ---[ But it doesn't support s390x and thus not used on s390x
# ---[ But it doesn't support s390x/powerpc and thus not used on s390x/powerpc
if(NOT TARGET cpuinfo AND USE_SYSTEM_CPUINFO)
add_library(cpuinfo SHARED IMPORTED)
find_library(CPUINFO_LIBRARY cpuinfo)