mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Add and use thread-safe strerror (#140472)
Fixes #ISSUE_NUMBER Pull Request resolved: https://github.com/pytorch/pytorch/pull/140472 Approved by: https://github.com/ezyang
This commit is contained in:
@ -9,6 +9,7 @@
|
||||
|
||||
#include <c10/core/CPUAllocator.h>
|
||||
|
||||
#include <c10/util/error.h>
|
||||
#ifdef _WIN32
|
||||
#include <c10/util/Unicode.h>
|
||||
#endif
|
||||
@ -252,13 +253,13 @@ MapAllocator::MapAllocator(WithFd, std::string_view filename, int fd, int flags,
|
||||
if (flags_ & ALLOCATOR_MAPPED_SHARED) {
|
||||
// NOLINTNEXTLINE(bugprone-assignment-in-if-condition)
|
||||
if ((fd = open(filename_.c_str(), flags, (mode_t)0600)) == -1) {
|
||||
TORCH_CHECK(false, "unable to open file <", filename_, "> in read-write mode: ", strerror(errno), " (", errno, ")");
|
||||
TORCH_CHECK(false, "unable to open file <", filename_, "> in read-write mode: ", c10::utils::str_error(errno), " (", errno, ")");
|
||||
}
|
||||
} else if (flags_ & ALLOCATOR_MAPPED_SHAREDMEM) {
|
||||
#ifdef HAVE_SHM_OPEN
|
||||
// NOLINTNEXTLINE(bugprone-assignment-in-if-condition)
|
||||
if((fd = shm_open(filename_.c_str(), flags, (mode_t)0600)) == -1) {
|
||||
TORCH_CHECK(false, "unable to open shared memory object <", filename_, "> in read-write mode: ", strerror(errno), " (", errno, ")");
|
||||
TORCH_CHECK(false, "unable to open shared memory object <", filename_, "> in read-write mode: ", c10::utils::str_error(errno), " (", errno, ")");
|
||||
}
|
||||
#else
|
||||
TORCH_CHECK(false, "unable to open file <", filename_, "> in sharedmem mode, shm_open unavailable on this platform");
|
||||
@ -266,7 +267,7 @@ MapAllocator::MapAllocator(WithFd, std::string_view filename, int fd, int flags,
|
||||
} else {
|
||||
// NOLINTNEXTLINE(bugprone-assignment-in-if-condition)
|
||||
if ((fd = open(filename_.c_str(), O_RDONLY)) == -1) {
|
||||
TORCH_CHECK(false, "unable to open file <", filename_, "> in read-only mode: ", strerror(errno), " (", errno, ")");
|
||||
TORCH_CHECK(false, "unable to open file <", filename_, "> in read-only mode: ", c10::utils::str_error(errno), " (", errno, ")");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -281,21 +282,21 @@ MapAllocator::MapAllocator(WithFd, std::string_view filename, int fd, int flags,
|
||||
if (!(flags_ & ALLOCATOR_MAPPED_FROMFD)) {
|
||||
::close(fd);
|
||||
}
|
||||
TORCH_CHECK(false, "unable to stat the file <", filename_, ">: ", strerror(last_err), " (", last_err, ")");
|
||||
TORCH_CHECK(false, "unable to stat the file <", filename_, ">: ", c10::utils::str_error(last_err), " (", last_err, ")");
|
||||
}
|
||||
|
||||
if (size > 0) {
|
||||
if (static_cast<int64_t>(size) > file_stat.st_size) {
|
||||
if (flags_) {
|
||||
if (ftruncate(fd, static_cast<off_t>(size)) == -1) {
|
||||
TORCH_CHECK(false, "unable to resize file <", filename_, "> to the right size: ", strerror(errno), " (", errno, ")");
|
||||
TORCH_CHECK(false, "unable to resize file <", filename_, "> to the right size: ", c10::utils::str_error(errno), " (", errno, ")");
|
||||
}
|
||||
if (fstat(fd, &file_stat) == -1 || file_stat.st_size < static_cast<int64_t>(size)) {
|
||||
#ifndef STRIP_ERROR_MESSAGES
|
||||
int last_err = errno;
|
||||
#endif
|
||||
::close(fd);
|
||||
TORCH_CHECK(false, "unable to stretch file <", filename_, "> to the right size: ", strerror(last_err), " (", last_err, ")");
|
||||
TORCH_CHECK(false, "unable to stretch file <", filename_, "> to the right size: ", c10::utils::str_error(last_err), " (", last_err, ")");
|
||||
}
|
||||
/* on macOS write returns with errno 45 (Opperation not supported) when used
|
||||
* with a file descriptor obtained via shm_open
|
||||
@ -306,7 +307,7 @@ MapAllocator::MapAllocator(WithFd, std::string_view filename, int fd, int flags,
|
||||
int last_err = errno;
|
||||
#endif
|
||||
::close(fd);
|
||||
TORCH_CHECK(false, "unable to write to file <", filename_, ">: ", strerror(last_err), " (", last_err, ")");
|
||||
TORCH_CHECK(false, "unable to write to file <", filename_, ">: ", c10::utils::str_error(last_err), " (", last_err, ")");
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
@ -329,7 +330,7 @@ MapAllocator::MapAllocator(WithFd, std::string_view filename, int fd, int flags,
|
||||
|
||||
if (base_ptr_ == MAP_FAILED) {
|
||||
base_ptr_ = nullptr; /* let's be sure it is NULL */
|
||||
TORCH_CHECK(false, "unable to mmap ", size_, " bytes from file <", filename_, ">: ", strerror(errno), " (", errno, ")");
|
||||
TORCH_CHECK(false, "unable to mmap ", size_, " bytes from file <", filename_, ">: ", c10::utils::str_error(errno), " (", errno, ")");
|
||||
}
|
||||
|
||||
#if !defined(__APPLE__) && !defined(__ANDROID__)
|
||||
@ -341,7 +342,7 @@ MapAllocator::MapAllocator(WithFd, std::string_view filename, int fd, int flags,
|
||||
fd_ = fd;
|
||||
} else {
|
||||
if (::close(fd) == -1) {
|
||||
TORCH_CHECK(false, "Error closing file <", filename_, ">: ", strerror(errno), " (", errno, ")");
|
||||
TORCH_CHECK(false, "Error closing file <", filename_, ">: ", c10::utils::str_error(errno), " (", errno, ")");
|
||||
}
|
||||
fd_ = -1;
|
||||
}
|
||||
@ -350,14 +351,14 @@ MapAllocator::MapAllocator(WithFd, std::string_view filename, int fd, int flags,
|
||||
if (flags_ & ALLOCATOR_MAPPED_SHAREDMEM) {
|
||||
#ifdef HAVE_SHM_UNLINK
|
||||
if (shm_unlink(filename_.c_str()) == -1) {
|
||||
TORCH_CHECK(false, "could not unlink the shared memory file ", filename_, " : ", strerror(errno), " (", errno, ")");
|
||||
TORCH_CHECK(false, "could not unlink the shared memory file ", filename_, " : ", c10::utils::str_error(errno), " (", errno, ")");
|
||||
}
|
||||
#else
|
||||
TORCH_CHECK(false, "could not unlink the shared memory file ", filename_, ", shm_unlink not available on platform");
|
||||
#endif
|
||||
} else {
|
||||
if (unlink(filename_.c_str()) == -1)
|
||||
TORCH_CHECK(false, "could not unlink file ", filename_, " : ", strerror(errno), " (", errno, ")");
|
||||
TORCH_CHECK(false, "could not unlink file ", filename_, " : ", c10::utils::str_error(errno), " (", errno, ")");
|
||||
}
|
||||
}
|
||||
|
||||
@ -411,19 +412,19 @@ void MapAllocator::close() {
|
||||
#else /* _WIN32 */
|
||||
if (flags_ & ALLOCATOR_MAPPED_KEEPFD) {
|
||||
if (::close(fd_) == -1) {
|
||||
TORCH_CHECK(false, "could not close file descriptor ", fd_, " :", strerror(errno), " (", errno, ")" );
|
||||
TORCH_CHECK(false, "could not close file descriptor ", fd_, " :", c10::utils::str_error(errno), " (", errno, ")" );
|
||||
}
|
||||
}
|
||||
|
||||
if (munmap(base_ptr_, size_)) {
|
||||
TORCH_CHECK(false, "could not unmap the shared memory file: ", strerror(errno), " (", errno, ")");
|
||||
TORCH_CHECK(false, "could not unmap the shared memory file: ", c10::utils::str_error(errno), " (", errno, ")");
|
||||
}
|
||||
|
||||
if (!(flags_ & (ALLOCATOR_MAPPED_FROMFD | ALLOCATOR_MAPPED_UNLINK))) {
|
||||
if (flags_ & ALLOCATOR_MAPPED_SHAREDMEM) {
|
||||
#ifdef HAVE_SHM_UNLINK
|
||||
if (shm_unlink(filename_.c_str()) == -1) {
|
||||
TORCH_CHECK(false, "could not unlink the shared memory file ", filename_, " : ", strerror(errno), " (", errno, ")");
|
||||
TORCH_CHECK(false, "could not unlink the shared memory file ", filename_, " : ", c10::utils::str_error(errno), " (", errno, ")");
|
||||
}
|
||||
#else
|
||||
TORCH_CHECK(false, "could not unlink the shared memory file ", filename_, ", shm_unlink not available on platform");
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <ATen/Config.h>
|
||||
|
||||
#include <c10/util/CallOnce.h>
|
||||
#include <c10/util/error.h>
|
||||
|
||||
#include <thread>
|
||||
|
||||
@ -120,7 +121,7 @@ struct Workspace {
|
||||
// Won't work on Windows, but NNPACK doesn't support Windows either
|
||||
auto res = posix_memalign(&buffer, nnpack_memory_alignment_boundary, size);
|
||||
if (res != 0) {
|
||||
TORCH_CHECK(false, "posix_memalign failed:", strerror(errno), " (", errno, ")");
|
||||
TORCH_CHECK(false, "posix_memalign failed:", c10::utils::str_error(errno), " (", errno, ")");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <c10/util/ScopeExit.h>
|
||||
#include <c10/util/UniqueVoidPtr.h>
|
||||
#include <c10/util/env.h>
|
||||
#include <c10/util/error.h>
|
||||
#include <c10/util/flat_hash_map.h>
|
||||
#include <c10/util/hash.h>
|
||||
#include <c10/util/llvmMathExtras.h>
|
||||
@ -486,7 +487,7 @@ struct ExpandableSegment {
|
||||
pidfd != -1 || errno != ENOSYS,
|
||||
"The kernel on this machine does not support the pidfd_open syscall needed to use IPC for CUDA tensors when expandable_segments:True is set. "
|
||||
"Consider using expandable_segments:False via torch.cuda.memory._set_allocator_settings('expandable_segments:False') for this allocation.");
|
||||
TORCH_CHECK(pidfd != -1, "pidfd_open:", std::strerror(errno));
|
||||
TORCH_CHECK(pidfd != -1, "pidfd_open:", c10::utils::str_error(errno));
|
||||
for (auto i : c10::irange(header.num_handles)) {
|
||||
(void)i;
|
||||
int fd = 0;
|
||||
@ -504,7 +505,7 @@ struct ExpandableSegment {
|
||||
err != ENOSYS,
|
||||
"The kernel on this machine does not support the pidfd_getfd syscall needed to use IPC for CUDA tensors when expandable_segments:True is set. "
|
||||
"Consider using expandable_segments:False via torch.cuda.memory._set_allocator_settings('expandable_segments:False') for this allocation.");
|
||||
TORCH_CHECK(false, "pidfd_getfd: ", std::strerror(err));
|
||||
TORCH_CHECK(false, "pidfd_getfd: ", c10::utils::str_error(err));
|
||||
}
|
||||
CUmemGenericAllocationHandle handle = 0;
|
||||
C10_CUDA_DRIVER_CHECK(DriverAPI::get()->cuMemImportFromShareableHandle_(
|
||||
|
14
c10/test/util/error_test.cpp
Normal file
14
c10/test/util/error_test.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
#include <c10/util/error.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstring>
|
||||
|
||||
using namespace ::testing;
|
||||
|
||||
TEST(StrErrorTest, cmp_test) {
|
||||
for (int err = 0; err <= EACCES; err++) {
|
||||
// NOLINTNEXTLINE(concurrency-mt-unsafe)
|
||||
ASSERT_EQ(c10::utils::str_error(err), std::string(strerror(err)));
|
||||
}
|
||||
}
|
30
c10/util/error.cpp
Normal file
30
c10/util/error.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include <cstring>
|
||||
|
||||
#include <c10/util/error.h>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
namespace c10::utils {
|
||||
|
||||
// Get an error string in the thread-safe way.
|
||||
std::string str_error(int errnum) {
|
||||
auto old_errno = errno;
|
||||
std::string buf(256, '\0');
|
||||
#if defined(_WIN32)
|
||||
auto res [[maybe_unused]] = strerror_s(buf.data(), buf.size(), errnum);
|
||||
buf.resize(strlen(buf.c_str()));
|
||||
#else
|
||||
auto res [[maybe_unused]] = strerror_r(errnum, buf.data(), buf.size());
|
||||
if constexpr (std::is_same_v<decltype(res), int>) {
|
||||
buf.resize(strlen(buf.c_str()));
|
||||
} else {
|
||||
if (res) {
|
||||
buf = res;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
errno = old_errno;
|
||||
return buf;
|
||||
}
|
||||
|
||||
} // namespace c10::utils
|
11
c10/util/error.h
Normal file
11
c10/util/error.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <c10/macros/Export.h>
|
||||
#include <string>
|
||||
|
||||
namespace c10::utils {
|
||||
|
||||
// Get an error string in the thread-safe way.
|
||||
C10_API std::string str_error(int errnum);
|
||||
|
||||
} // namespace c10::utils
|
@ -1,5 +1,6 @@
|
||||
#include <c10/util/Exception.h>
|
||||
#include <c10/util/env.h>
|
||||
#include <c10/util/error.h>
|
||||
#include <c10/util/tempfile.h>
|
||||
#include <fmt/format.h>
|
||||
|
||||
@ -74,7 +75,8 @@ TempFile make_tempfile(std::string_view name_prefix) {
|
||||
if (auto tempfile = try_make_tempfile(name_prefix)) {
|
||||
return std::move(*tempfile);
|
||||
}
|
||||
TORCH_CHECK(false, "Error generating temporary file: ", std::strerror(errno));
|
||||
TORCH_CHECK(
|
||||
false, "Error generating temporary file: ", c10::utils::str_error(errno));
|
||||
}
|
||||
|
||||
/// Attempts to return a temporary directory or returns `nullopt` if an error
|
||||
@ -156,7 +158,9 @@ TempDir make_tempdir(std::string_view name_prefix) {
|
||||
}
|
||||
#if !defined(_WIN32)
|
||||
TORCH_CHECK(
|
||||
false, "Error generating temporary directory: ", std::strerror(errno));
|
||||
false,
|
||||
"Error generating temporary directory: ",
|
||||
c10::utils::str_error(errno));
|
||||
#else // defined(_WIN32)
|
||||
TORCH_CHECK(false, "Error generating temporary directory");
|
||||
#endif // defined(_WIN32)
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <c10/util/error.h>
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <torch/csrc/utils/pybind.h>
|
||||
|
||||
@ -16,7 +17,7 @@ template <
|
||||
std::string cuGDSFileGetErrorString(T status) {
|
||||
status = std::abs(status);
|
||||
return IS_CUFILE_ERR(status) ? std::string(CUFILE_ERRSTR(status))
|
||||
: std::string(std::strerror(errno));
|
||||
: std::string(c10::utils::str_error(errno));
|
||||
}
|
||||
|
||||
// To get error message for Buf/Handle registeration APIs that return
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <ATen/cuda/CUDAContext.h>
|
||||
#include <c10/cuda/CUDACachingAllocator.h>
|
||||
#include <c10/cuda/CUDAGuard.h>
|
||||
#include <c10/util/error.h>
|
||||
|
||||
#if !defined(USE_ROCM) && defined(PYTORCH_C10_DRIVER_API_SUPPORTED)
|
||||
#include <c10/cuda/driver_api.h>
|
||||
@ -57,7 +58,7 @@ class IpcChannel {
|
||||
TORCH_CHECK(
|
||||
(socket_ = socket(AF_UNIX, SOCK_DGRAM, 0)) != 0,
|
||||
"Failed to create socket: ",
|
||||
strerror(errno));
|
||||
c10::utils::str_error(errno));
|
||||
|
||||
struct sockaddr_un addr = {.sun_family = AF_UNIX};
|
||||
std::copy(socket_name_.begin(), socket_name_.end(), addr.sun_path);
|
||||
@ -65,7 +66,7 @@ class IpcChannel {
|
||||
TORCH_CHECK(
|
||||
bind(socket_, (struct sockaddr*)&addr, SUN_LEN(&addr)) == 0,
|
||||
"Failed to bind socket: ",
|
||||
strerror(errno));
|
||||
c10::utils::str_error(errno));
|
||||
}
|
||||
|
||||
~IpcChannel() {
|
||||
@ -104,7 +105,7 @@ class IpcChannel {
|
||||
}
|
||||
|
||||
TORCH_CHECK(
|
||||
sendmsg(socket_, &msg, 0) > 0, "Failed to send fd: ", strerror(errno));
|
||||
sendmsg(socket_, &msg, 0) > 0, "Failed to send fd: ", c10::utils::str_error(errno));
|
||||
}
|
||||
|
||||
int recv_fd() {
|
||||
@ -123,7 +124,7 @@ class IpcChannel {
|
||||
TORCH_CHECK(
|
||||
recvmsg(socket_, &msg, 0) > 0,
|
||||
"Failed to receive fd: ",
|
||||
strerror(errno));
|
||||
c10::utils::str_error(errno));
|
||||
|
||||
if (msg.msg_controllen == 0) {
|
||||
return -1;
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <c10/util/error.h>
|
||||
#include <torch/csrc/distributed/c10d/FileStore.hpp>
|
||||
|
||||
#include <fcntl.h>
|
||||
@ -22,9 +23,9 @@
|
||||
|
||||
#include <c10/util/Exception.h>
|
||||
|
||||
#define SYSASSERT(rv, ...) \
|
||||
if ((rv) < 0) { \
|
||||
C10_THROW_ERROR(DistStoreError, std::strerror(errno)); \
|
||||
#define SYSASSERT(rv, ...) \
|
||||
if ((rv) < 0) { \
|
||||
C10_THROW_ERROR(DistStoreError, c10::utils::str_error(errno)); \
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <c10/util/Exception.h>
|
||||
#include <c10/util/error.h>
|
||||
#include <torch/csrc/distributed/c10d/ProcessGroupGloo.hpp>
|
||||
|
||||
#ifdef USE_C10D_GLOO
|
||||
@ -713,7 +714,7 @@ std::shared_ptr<::gloo::transport::Device> ProcessGroupGloo::
|
||||
std::array<char, HOST_NAME_MAX> hostname{};
|
||||
auto rv = gethostname(hostname.data(), HOST_NAME_MAX);
|
||||
if (rv != 0) {
|
||||
C10_THROW_ERROR(DistBackendError, std::strerror(errno));
|
||||
C10_THROW_ERROR(DistBackendError, c10::utils::str_error(errno));
|
||||
}
|
||||
|
||||
// Use this machine's hostname if it resolves to an address.
|
||||
@ -740,7 +741,7 @@ std::shared_ptr<::gloo::transport::Device> ProcessGroupGloo::
|
||||
auto hostname = std::unique_ptr<char[]>(new char[hostNameMax]);
|
||||
auto rv = gethostname(hostname.get(), hostNameMax);
|
||||
if (rv != 0) {
|
||||
C10_THROW_ERROR(DistBackendError, std::strerror(errno));
|
||||
C10_THROW_ERROR(DistBackendError, c10::utils::str_error(errno));
|
||||
}
|
||||
|
||||
// Use this machine's hostname if it resolves to an address.
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <ATen/ATen.h>
|
||||
#include <c10/util/Exception.h>
|
||||
#include <c10/util/accumulate.h>
|
||||
#include <c10/util/error.h>
|
||||
#include <c10/util/irange.h>
|
||||
#include <torch/csrc/distributed/c10d/Types.hpp>
|
||||
|
||||
@ -569,40 +570,40 @@ using SizeType = uint64_t;
|
||||
// `fork()`, we can use `SYSCHECK(pid = fork(), pid != -1)`. The function output
|
||||
// is stored in variable `__output` and may be used in `success_cond`.
|
||||
#ifdef _WIN32
|
||||
#define SYSCHECK(expr, success_cond) \
|
||||
while (true) { \
|
||||
auto __output = (expr); \
|
||||
auto errno_local = WSAGetLastError(); \
|
||||
(void)__output; \
|
||||
if (!(success_cond)) { \
|
||||
if (errno == EINTR) { \
|
||||
continue; \
|
||||
} else if ( \
|
||||
errno_local == WSAETIMEDOUT || errno_local == WSAEWOULDBLOCK) { \
|
||||
C10_THROW_ERROR(DistNetworkError, "Socket Timeout"); \
|
||||
} else { \
|
||||
C10_THROW_ERROR(DistNetworkError, std::strerror(errno_local)); \
|
||||
} \
|
||||
} else { \
|
||||
break; \
|
||||
} \
|
||||
#define SYSCHECK(expr, success_cond) \
|
||||
while (true) { \
|
||||
auto __output = (expr); \
|
||||
auto errno_local = WSAGetLastError(); \
|
||||
(void)__output; \
|
||||
if (!(success_cond)) { \
|
||||
if (errno == EINTR) { \
|
||||
continue; \
|
||||
} else if ( \
|
||||
errno_local == WSAETIMEDOUT || errno_local == WSAEWOULDBLOCK) { \
|
||||
C10_THROW_ERROR(DistNetworkError, "Socket Timeout"); \
|
||||
} else { \
|
||||
C10_THROW_ERROR(DistNetworkError, c10::utils::str_error(errno_local)); \
|
||||
} \
|
||||
} else { \
|
||||
break; \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define SYSCHECK(expr, success_cond) \
|
||||
while (true) { \
|
||||
auto __output = (expr); \
|
||||
(void)__output; \
|
||||
if (!(success_cond)) { \
|
||||
if (errno == EINTR) { \
|
||||
continue; \
|
||||
} else if (errno == EAGAIN || errno == EWOULDBLOCK) { \
|
||||
C10_THROW_ERROR(DistNetworkError, "Socket Timeout"); \
|
||||
} else { \
|
||||
C10_THROW_ERROR(DistNetworkError, std::strerror(errno)); \
|
||||
} \
|
||||
} else { \
|
||||
break; \
|
||||
} \
|
||||
#define SYSCHECK(expr, success_cond) \
|
||||
while (true) { \
|
||||
auto __output = (expr); \
|
||||
(void)__output; \
|
||||
if (!(success_cond)) { \
|
||||
if (errno == EINTR) { \
|
||||
continue; \
|
||||
} else if (errno == EAGAIN || errno == EWOULDBLOCK) { \
|
||||
C10_THROW_ERROR(DistNetworkError, "Socket Timeout"); \
|
||||
} else { \
|
||||
C10_THROW_ERROR(DistNetworkError, c10::utils::str_error(errno)); \
|
||||
} \
|
||||
} else { \
|
||||
break; \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
// This source code is licensed under the BSD-style license found in the
|
||||
// LICENSE file in the root directory of this source tree.
|
||||
|
||||
#include <c10/util/error.h>
|
||||
#include <torch/csrc/distributed/c10d/socket.h>
|
||||
|
||||
#include <cstring>
|
||||
@ -115,7 +116,7 @@ void delay(std::chrono::milliseconds d) {
|
||||
// We don't care about error conditions other than EINTR since a failure
|
||||
// here is not critical.
|
||||
if (err == std::errc::interrupted) {
|
||||
C10_THROW_ERROR(DistNetworkError, std::strerror(err.value()));
|
||||
C10_THROW_ERROR(DistNetworkError, c10::utils::str_error(err.value()));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -315,7 +316,7 @@ std::unique_ptr<SocketImpl> SocketImpl::accept() const {
|
||||
if (hnd == invalid_socket) {
|
||||
std::error_code err = getSocketError();
|
||||
if (err == std::errc::interrupted) {
|
||||
C10_THROW_ERROR(DistNetworkError, std::strerror(err.value()));
|
||||
C10_THROW_ERROR(DistNetworkError, c10::utils::str_error(err.value()));
|
||||
}
|
||||
|
||||
std::string msg{};
|
||||
@ -916,7 +917,7 @@ SocketConnectOp::ConnectResult SocketConnectOp::tryConnect(
|
||||
if (cr == ConnectResult::Error) {
|
||||
std::error_code err = getSocketError();
|
||||
if (err == std::errc::interrupted) {
|
||||
C10_THROW_ERROR(DistNetworkError, std::strerror(err.value()));
|
||||
C10_THROW_ERROR(DistNetworkError, c10::utils::str_error(err.value()));
|
||||
}
|
||||
|
||||
// Retry if the server is not yet listening or if its backlog is exhausted.
|
||||
|
@ -1,5 +1,6 @@
|
||||
#if !defined(C10_MOBILE) && !defined(ANDROID)
|
||||
|
||||
#include <c10/util/error.h>
|
||||
#include <torch/csrc/inductor/aoti_package/model_package_loader.h>
|
||||
#include <torch/csrc/inductor/aoti_runner/model_container_runner.h>
|
||||
#include <torch/csrc/inductor/aoti_runner/model_container_runner_cpu.h>
|
||||
@ -49,7 +50,7 @@ std::string create_temp_dir() {
|
||||
if (mkdtemp(temp_dir.data()) == nullptr) {
|
||||
throw std::runtime_error(
|
||||
std::string("Failed to create temporary directory: ") +
|
||||
strerror(errno));
|
||||
c10::utils::str_error(errno));
|
||||
}
|
||||
return temp_dir;
|
||||
#endif
|
||||
@ -327,7 +328,9 @@ AOTIModelPackageLoader::AOTIModelPackageLoader(
|
||||
std::string parent_path = output_path_str.substr(0, parent_path_idx);
|
||||
if (!recursive_mkdir(parent_path.c_str())) {
|
||||
throw std::runtime_error(fmt::format(
|
||||
"Failed to create directory {}: {}", parent_path, strerror(errno)));
|
||||
"Failed to create directory {}: {}",
|
||||
parent_path,
|
||||
c10::utils::str_error(errno)));
|
||||
}
|
||||
|
||||
// Extracts file to the temp directory
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <c10/util/error.h>
|
||||
#include <torch/csrc/instruction_counter/Module.h>
|
||||
#include <torch/csrc/utils/pybind.h>
|
||||
#include <cerrno>
|
||||
@ -38,7 +39,7 @@ long start() {
|
||||
fprintf(
|
||||
stderr,
|
||||
"Failed to open instruction count event: %s.\n",
|
||||
strerror(errno));
|
||||
c10::utils::str_error(errno).c_str());
|
||||
return -1;
|
||||
}
|
||||
ioctl((int)fd, PERF_EVENT_IOC_RESET, 0); // Reset the counter
|
||||
@ -57,7 +58,7 @@ uint64_t end(int fd) {
|
||||
stderr,
|
||||
"Error disabling perf event (fd: %d): %s\n",
|
||||
fd,
|
||||
strerror(errno));
|
||||
c10::utils::str_error(errno).c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -66,7 +67,10 @@ uint64_t end(int fd) {
|
||||
// Read results
|
||||
long ret_val = read(fd, &total_instructions, sizeof(total_instructions));
|
||||
if (ret_val == -1) {
|
||||
fprintf(stderr, "Error reading perf event results: %s\n", strerror(errno));
|
||||
fprintf(
|
||||
stderr,
|
||||
"Error reading perf event results: %s\n",
|
||||
c10::utils::str_error(errno).c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <c10/util/error.h>
|
||||
#include <torch/csrc/profiler/perf-inl.h>
|
||||
#include <torch/csrc/profiler/perf.h>
|
||||
|
||||
@ -63,7 +64,6 @@ void PerfEvent::Init() {
|
||||
}
|
||||
|
||||
struct perf_event_attr attr {};
|
||||
memset(&attr, 0, sizeof(attr));
|
||||
|
||||
attr.size = sizeof(perf_event_attr);
|
||||
attr.type = it->second.first;
|
||||
@ -87,7 +87,9 @@ void PerfEvent::Init() {
|
||||
fd_ = static_cast<int>(perf_event_open(&attr, pid, cpu, group_fd, flags));
|
||||
if (fd_ == -1) {
|
||||
TORCH_CHECK(
|
||||
false, "perf_event_open() failed, error: ", std::strerror(errno));
|
||||
false,
|
||||
"perf_event_open() failed, error: ",
|
||||
c10::utils::str_error(errno));
|
||||
}
|
||||
Reset();
|
||||
}
|
||||
@ -100,7 +102,7 @@ uint64_t PerfEvent::ReadCounter() const {
|
||||
"Read failed for Perf event fd, event : ",
|
||||
name_,
|
||||
", error: ",
|
||||
std::strerror(errno));
|
||||
c10::utils::str_error(errno));
|
||||
TORCH_CHECK(
|
||||
counter.time_enabled == counter.time_running,
|
||||
"Hardware performance counter time multiplexing is not handled yet",
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <c10/util/error.h>
|
||||
#include <elf.h>
|
||||
#include <fcntl.h>
|
||||
#include <fmt/format.h>
|
||||
@ -41,12 +42,19 @@ struct MemFile {
|
||||
explicit MemFile(const char* filename_)
|
||||
: fd_(open(filename_, O_RDONLY)), name_(filename_) {
|
||||
UNWIND_CHECK(
|
||||
fd_ != -1, "failed to open {}: {}", filename_, strerror(errno));
|
||||
fd_ != -1,
|
||||
"failed to open {}: {}",
|
||||
filename_,
|
||||
c10::utils::str_error(errno));
|
||||
// NOLINTNEXTLINE
|
||||
struct stat s;
|
||||
if (-1 == fstat(fd_, &s)) {
|
||||
close(fd_); // destructors don't run during exceptions
|
||||
UNWIND_CHECK(false, "failed to stat {}: {}", filename_, strerror(errno));
|
||||
UNWIND_CHECK(
|
||||
false,
|
||||
"failed to stat {}: {}",
|
||||
filename_,
|
||||
c10::utils::str_error(errno));
|
||||
}
|
||||
n_bytes_ = s.st_size;
|
||||
UNWIND_CHECK(
|
||||
@ -54,7 +62,11 @@ struct MemFile {
|
||||
mem_ = (char*)mmap(nullptr, n_bytes_, PROT_READ, MAP_SHARED, fd_, 0);
|
||||
if (MAP_FAILED == mem_) {
|
||||
close(fd_);
|
||||
UNWIND_CHECK(false, "failed to mmap {}: {}", filename_, strerror(errno));
|
||||
UNWIND_CHECK(
|
||||
false,
|
||||
"failed to mmap {}: {}",
|
||||
filename_,
|
||||
c10::utils::str_error(errno));
|
||||
}
|
||||
ehdr_ = (Elf64_Ehdr*)mem_;
|
||||
#define ELF_CHECK(cond) UNWIND_CHECK(cond, "not an ELF file: {}", filename_)
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <ATen/ops/from_blob.h>
|
||||
#include <c10/core/CPUAllocator.h>
|
||||
#include <c10/util/error.h>
|
||||
#include <torch/csrc/THP.h>
|
||||
#include <torch/csrc/serialization.h>
|
||||
|
||||
@ -169,7 +170,11 @@ void doRead(io fildes, void* raw_buf, size_t nbytes) {
|
||||
continue;
|
||||
} else {
|
||||
TORCH_CHECK(
|
||||
false, "read(): fd ", fildes, " failed with ", strerror(err));
|
||||
false,
|
||||
"read(): fd ",
|
||||
fildes,
|
||||
" failed with ",
|
||||
c10::utils::str_error(err));
|
||||
}
|
||||
} else if (r == 0) {
|
||||
break;
|
||||
@ -211,7 +216,11 @@ void doWrite(io fildes, void* raw_buf, size_t nbytes) {
|
||||
continue;
|
||||
} else {
|
||||
TORCH_CHECK(
|
||||
false, "write(): fd ", fildes, " failed with ", strerror(err));
|
||||
false,
|
||||
"write(): fd ",
|
||||
fildes,
|
||||
" failed with ",
|
||||
c10::utils::str_error(err));
|
||||
}
|
||||
}
|
||||
buf += r;
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <c10/util/error.h>
|
||||
|
||||
#include <libshm/err.h>
|
||||
#include <libshm/libshm.h>
|
||||
@ -36,7 +37,7 @@ void start_manager() {
|
||||
execl(manager_executable_path.c_str(), "torch_shm_manager", NULL);
|
||||
|
||||
std::string msg("ERROR: execl failed: ");
|
||||
msg += std::strerror(errno);
|
||||
msg += c10::utils::str_error(errno);
|
||||
msg += '\n';
|
||||
auto res = write(1, msg.c_str(), msg.size());
|
||||
(void)res;
|
||||
|
Reference in New Issue
Block a user