|
| 1 | +cpu: aarch64: fix xbyak functions for /sys access failures |
| 2 | + |
| 3 | +There are platforms with /sys not mounted. skip handling HW caps |
| 4 | +for such platforms. |
| 5 | + |
| 6 | +This fixes the issue# pytorch/pytorch#115482 |
| 7 | +--- |
| 8 | + .../xbyak_aarch64/src/util_impl_linux.h | 24 ++++++++++++++----- |
| 9 | + .../aarch64/xbyak_aarch64/src/util_impl_mac.h | 9 ++++--- |
| 10 | + 2 files changed, 24 insertions(+), 9 deletions(-) |
| 11 | + |
| 12 | +diff --git a/src/cpu/aarch64/xbyak_aarch64/src/util_impl_linux.h b/src/cpu/aarch64/xbyak_aarch64/src/util_impl_linux.h |
| 13 | +index 2c7b28e58b..860a05700f 100644 |
| 14 | +--- a/src/cpu/aarch64/xbyak_aarch64/src/util_impl_linux.h |
| 15 | ++++ b/src/cpu/aarch64/xbyak_aarch64/src/util_impl_linux.h |
| 16 | +@@ -144,8 +144,13 @@ private: |
| 17 | + regex_t regexBuf; |
| 18 | + regmatch_t match[1]; |
| 19 | + |
| 20 | +- if (regcomp(®exBuf, regex, REG_EXTENDED) != 0) |
| 21 | +- throw ERR_INTERNAL; |
| 22 | ++ if (regcomp(®exBuf, regex, REG_EXTENDED) != 0) { |
| 23 | ++ /* There are platforms with /sys not mounted. return empty buffers |
| 24 | ++ * in these scenarios |
| 25 | ++ */ |
| 26 | ++ buf[0] = '\0'; |
| 27 | ++ return 0; |
| 28 | ++ } |
| 29 | + |
| 30 | + const int retVal = regexec(®exBuf, path, 1, match, 0); |
| 31 | + regfree(®exBuf); |
| 32 | +@@ -187,8 +192,12 @@ private: |
| 33 | + regex_t regexBuf; |
| 34 | + regmatch_t match[2]; |
| 35 | + |
| 36 | +- if (regcomp(®exBuf, "index[0-9]*$", REG_EXTENDED) != 0) |
| 37 | +- throw ERR_INTERNAL; |
| 38 | ++ if (regcomp(®exBuf, "index[0-9]*$", REG_EXTENDED) != 0) { |
| 39 | ++ /* There are platforms with /sys not mounted. return gracefully |
| 40 | ++ * in these scenarios |
| 41 | ++ */ |
| 42 | ++ goto init_and_return_false; |
| 43 | ++ } |
| 44 | + |
| 45 | + if (regexec(®exBuf, dp->d_name, 1, match, 0) == 0) { // Found index[1-9][0-9]. directory |
| 46 | + char *dir_name = buf0; |
| 47 | +@@ -438,12 +447,15 @@ private: |
| 48 | + |
| 49 | + FILE *file = fopen(path_midr_el1, "r"); |
| 50 | + if (file == nullptr) { |
| 51 | +- throw Error(ERR_INTERNAL); |
| 52 | ++ /* There are platforms with /sys not mounted. return empty buffer |
| 53 | ++ * in these scenarios |
| 54 | ++ */ |
| 55 | ++ cacheInfo_.midr_el1 = 0xFE << 24; |
| 56 | + return; |
| 57 | + } |
| 58 | + |
| 59 | + if (fread(buf, sizeof(char), 64, file) == 0) { |
| 60 | +- throw Error(ERR_INTERNAL); |
| 61 | ++ cacheInfo_.midr_el1 = 0xFE << 24; |
| 62 | + return; |
| 63 | + } |
| 64 | + |
| 65 | +diff --git a/src/cpu/aarch64/xbyak_aarch64/src/util_impl_mac.h b/src/cpu/aarch64/xbyak_aarch64/src/util_impl_mac.h |
| 66 | +index ebd6dba7c0..93bdae1d7a 100644 |
| 67 | +--- a/src/cpu/aarch64/xbyak_aarch64/src/util_impl_mac.h |
| 68 | ++++ b/src/cpu/aarch64/xbyak_aarch64/src/util_impl_mac.h |
| 69 | +@@ -102,18 +102,21 @@ private: |
| 70 | + size_t val = 0; |
| 71 | + size_t len = sizeof(val); |
| 72 | + |
| 73 | ++ /* There are platforms with /sys not mounted. skip |
| 74 | ++ * handling HW caps for such platforms. |
| 75 | ++ */ |
| 76 | + if (sysctlbyname(hw_opt_atomics, &val, &len, NULL, 0) != 0) |
| 77 | +- throw Error(ERR_INTERNAL); |
| 78 | ++ type_ = 0; |
| 79 | + else |
| 80 | + type_ |= (val == 1) ? (Type)XBYAK_AARCH64_HWCAP_ATOMIC : 0; |
| 81 | + |
| 82 | + if (sysctlbyname(hw_opt_fp, &val, &len, NULL, 0) != 0) |
| 83 | +- throw Error(ERR_INTERNAL); |
| 84 | ++ type_ = 0; |
| 85 | + else |
| 86 | + type_ |= (val == 1) ? (Type)XBYAK_AARCH64_HWCAP_FP : 0; |
| 87 | + |
| 88 | + if (sysctlbyname(hw_opt_neon, &val, &len, NULL, 0) != 0) |
| 89 | +- throw Error(ERR_INTERNAL); |
| 90 | ++ type_ = 0; |
| 91 | + else |
| 92 | + type_ |= (val == 1) ? (Type)XBYAK_AARCH64_HWCAP_ADVSIMD : 0; |
| 93 | + } |
| 94 | +-- |
| 95 | +2.34.1 |
| 96 | + |
0 commit comments