|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "sparse_matmul/layers/errno_mapping.h" |
|
|
|
#include <string> |
|
|
|
#include "absl/strings/str_cat.h" |
|
|
|
namespace csrblocksparse { |
|
|
|
namespace { |
|
|
|
absl::StatusCode ErrnoToCode(int error_number) { |
|
switch (error_number) { |
|
case 0: |
|
return absl::StatusCode::kOk; |
|
case EINVAL: |
|
case ENAMETOOLONG: |
|
case E2BIG: |
|
case EDESTADDRREQ: |
|
case EDOM: |
|
case EFAULT: |
|
case EILSEQ: |
|
case ENOPROTOOPT: |
|
case ENOSTR: |
|
case ENOTSOCK: |
|
case ENOTTY: |
|
case EPROTOTYPE: |
|
case ESPIPE: |
|
return absl::StatusCode::kInvalidArgument; |
|
case ETIMEDOUT: |
|
case ETIME: |
|
return absl::StatusCode::kDeadlineExceeded; |
|
case ENODEV: |
|
case ENOENT: |
|
#ifdef ENOMEDIUM |
|
case ENOMEDIUM: |
|
#endif |
|
case ENXIO: |
|
case ESRCH: |
|
return absl::StatusCode::kNotFound; |
|
case EEXIST: |
|
case EADDRNOTAVAIL: |
|
case EALREADY: |
|
#ifdef ENOTUNIQ |
|
case ENOTUNIQ: |
|
#endif |
|
return absl::StatusCode::kAlreadyExists; |
|
case EPERM: |
|
case EACCES: |
|
#ifdef ENOKEY |
|
case ENOKEY: |
|
#endif |
|
case EROFS: |
|
return absl::StatusCode::kPermissionDenied; |
|
case ENOTEMPTY: |
|
case EISDIR: |
|
case ENOTDIR: |
|
case EADDRINUSE: |
|
case EBADF: |
|
#ifdef EBADFD |
|
case EBADFD: |
|
#endif |
|
case EBUSY: |
|
case ECHILD: |
|
case EISCONN: |
|
#ifdef EISNAM |
|
case EISNAM: |
|
#endif |
|
#ifdef ENOTBLK |
|
case ENOTBLK: |
|
#endif |
|
case ENOTCONN: |
|
case EPIPE: |
|
#ifdef ESHUTDOWN |
|
case ESHUTDOWN: |
|
#endif |
|
case ETXTBSY: |
|
#ifdef EUNATCH |
|
case EUNATCH: |
|
#endif |
|
return absl::StatusCode::kFailedPrecondition; |
|
case ENOSPC: |
|
#ifdef EDQUOT |
|
case EDQUOT: |
|
#endif |
|
case EMFILE: |
|
case EMLINK: |
|
case ENFILE: |
|
case ENOBUFS: |
|
case ENODATA: |
|
case ENOMEM: |
|
case ENOSR: |
|
#ifdef EUSERS |
|
case EUSERS: |
|
#endif |
|
return absl::StatusCode::kResourceExhausted; |
|
#ifdef ECHRNG |
|
case ECHRNG: |
|
#endif |
|
case EFBIG: |
|
case EOVERFLOW: |
|
case ERANGE: |
|
return absl::StatusCode::kOutOfRange; |
|
#ifdef ENOPKG |
|
case ENOPKG: |
|
#endif |
|
case ENOSYS: |
|
case ENOTSUP: |
|
case EAFNOSUPPORT: |
|
#ifdef EPFNOSUPPORT |
|
case EPFNOSUPPORT: |
|
#endif |
|
case EPROTONOSUPPORT: |
|
#ifdef ESOCKTNOSUPPORT |
|
case ESOCKTNOSUPPORT: |
|
#endif |
|
case EXDEV: |
|
return absl::StatusCode::kUnimplemented; |
|
case EAGAIN: |
|
#ifdef ECOMM |
|
case ECOMM: |
|
#endif |
|
case ECONNREFUSED: |
|
case ECONNABORTED: |
|
case ECONNRESET: |
|
case EINTR: |
|
#ifdef EHOSTDOWN |
|
case EHOSTDOWN: |
|
#endif |
|
case EHOSTUNREACH: |
|
case ENETDOWN: |
|
case ENETRESET: |
|
case ENETUNREACH: |
|
case ENOLCK: |
|
case ENOLINK: |
|
#ifdef ENONET |
|
case ENONET: |
|
#endif |
|
return absl::StatusCode::kUnavailable; |
|
case EDEADLK: |
|
#ifdef ESTALE |
|
case ESTALE: |
|
#endif |
|
return absl::StatusCode::kAborted; |
|
case ECANCELED: |
|
return absl::StatusCode::kCancelled; |
|
default: |
|
return absl::StatusCode::kUnknown; |
|
} |
|
} |
|
|
|
|
|
ABSL_ATTRIBUTE_UNUSED std::string StrErrorResult(int result, const char* buffer, |
|
int error_code) { |
|
if (ABSL_PREDICT_FALSE(result != 0)) { |
|
return absl::StrCat("Unknown error ", error_code); |
|
} |
|
return buffer; |
|
} |
|
|
|
|
|
ABSL_ATTRIBUTE_UNUSED std::string StrErrorResult(char* result, |
|
const char* buffer, |
|
int error_code) { |
|
return result; |
|
} |
|
|
|
std::string StrError(int error_code) { |
|
char message[256]; |
|
return StrErrorResult(strerror_r(error_code, message, sizeof(message)), |
|
message, error_code); |
|
} |
|
|
|
} |
|
|
|
absl::Status ErrnoToCanonicalStatus(int error_number, |
|
absl::string_view message) { |
|
return absl::Status(ErrnoToCode(error_number), |
|
absl::StrCat(message, ": ", StrError(error_number))); |
|
} |
|
|
|
} |
|
|