Skip to content

Commit

Permalink
cpu: aarch64: fix xbyak functions for /sys access failures
Browse files Browse the repository at this point in the history
There are platforms with /sys not mounted. skip handling HW caps
for such platforms.

This fixes the issue# pytorch/pytorch#115482
  • Loading branch information
snadampal committed Mar 15, 2024
1 parent 15c7916 commit 232674a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
24 changes: 18 additions & 6 deletions src/cpu/aarch64/xbyak_aarch64/src/util_impl_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,13 @@ class CpuInfoLinux : public CpuInfo {
regex_t regexBuf;
regmatch_t match[1];

if (regcomp(&regexBuf, regex, REG_EXTENDED) != 0)
throw ERR_INTERNAL;
if (regcomp(&regexBuf, regex, REG_EXTENDED) != 0) {
/* There are platforms with /sys not mounted. return empty buffers
* in these scenarios
*/
buf[0] = '\0';
return 0;
}

const int retVal = regexec(&regexBuf, path, 1, match, 0);
regfree(&regexBuf);
Expand Down Expand Up @@ -187,8 +192,12 @@ class CpuInfoLinux : public CpuInfo {
regex_t regexBuf;
regmatch_t match[2];

if (regcomp(&regexBuf, "index[0-9]*$", REG_EXTENDED) != 0)
throw ERR_INTERNAL;
if (regcomp(&regexBuf, "index[0-9]*$", REG_EXTENDED) != 0) {
/* There are platforms with /sys not mounted. return gracefully
* in these scenarios
*/
goto init_and_return_false;
}

if (regexec(&regexBuf, dp->d_name, 1, match, 0) == 0) { // Found index[1-9][0-9]. directory
char *dir_name = buf0;
Expand Down Expand Up @@ -438,12 +447,15 @@ class CpuInfoLinux : public CpuInfo {

FILE *file = fopen(path_midr_el1, "r");
if (file == nullptr) {
throw Error(ERR_INTERNAL);
/* There are platforms with /sys not mounted. return empty buffer
* in these scenarios
*/
buf[0] = '\0';
return;
}

if (fread(buf, sizeof(char), 64, file) == 0) {
throw Error(ERR_INTERNAL);
cacheInfo_.midr_el1 = 0xFE << 24;
return;
}

Expand Down
9 changes: 6 additions & 3 deletions src/cpu/aarch64/xbyak_aarch64/src/util_impl_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,21 @@ class CpuInfoMac : public CpuInfo {
size_t val = 0;
size_t len = sizeof(val);

/* There are platforms with /sys not mounted. skip
* handling HW caps for such platforms.
*/
if (sysctlbyname(hw_opt_atomics, &val, &len, NULL, 0) != 0)
throw Error(ERR_INTERNAL);
type_ = 0;
else
type_ |= (val == 1) ? (Type)XBYAK_AARCH64_HWCAP_ATOMIC : 0;

if (sysctlbyname(hw_opt_fp, &val, &len, NULL, 0) != 0)
throw Error(ERR_INTERNAL);
type_ = 0;
else
type_ |= (val == 1) ? (Type)XBYAK_AARCH64_HWCAP_FP : 0;

if (sysctlbyname(hw_opt_neon, &val, &len, NULL, 0) != 0)
throw Error(ERR_INTERNAL);
type_ = 0;
else
type_ |= (val == 1) ? (Type)XBYAK_AARCH64_HWCAP_ADVSIMD : 0;
}
Expand Down

0 comments on commit 232674a

Please sign in to comment.