[2/N] Use thread-safe strerror (#141011)

Fixes #ISSUE_NUMBER

Pull Request resolved: https://github.com/pytorch/pytorch/pull/141011
Approved by: https://github.com/ezyang
This commit is contained in:
cyy 2024-11-22 07:02:30 +00:00 committed by PyTorch MergeBot
parent 8b13ed594a
commit 1bdb92cbff

View file

@ -4,6 +4,7 @@
#include <c10/util/Flags.h>
#include <c10/util/Logging.h>
#include <c10/util/env.h>
#include <c10/util/error.h>
#include <c10/util/irange.h>
#include <c10/util/numa.h>
@ -121,7 +122,7 @@ void* alloc_cpu(size_t nbytes) {
" bytes. Error code ",
err,
" (",
strerror(err),
c10::utils::str_error(err),
")");
if (is_thp_alloc(nbytes)) {
#ifdef __linux__
@ -129,7 +130,9 @@ void* alloc_cpu(size_t nbytes) {
// general posix compliant systems can check POSIX_MADV_SEQUENTIAL advise.
int ret = madvise(data, nbytes, MADV_HUGEPAGE);
if (ret != 0) {
TORCH_WARN_ONCE("thp madvise for HUGEPAGE failed with ", strerror(errno));
TORCH_WARN_ONCE(
"thp madvise for HUGEPAGE failed with ",
c10::utils::str_error(errno));
}
#endif
}