You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

status.h 5.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MINDSPORE_INCLUDE_API_STATUS_H
  17. #define MINDSPORE_INCLUDE_API_STATUS_H
  18. #include <string>
  19. #include <ostream>
  20. #include <climits>
  21. namespace mindspore {
  22. enum CompCode : uint32_t {
  23. kCore = 0x00000000u,
  24. kMD = 0x10000000u,
  25. kME = 0x20000000u,
  26. kMC = 0x30000000u,
  27. kLite = 0xF0000000u,
  28. };
  29. enum StatusCode : uint32_t {
  30. kSuccess = 0,
  31. // Core
  32. kCoreFailed = kCore | 0x1,
  33. // MD
  34. kMDOutOfMemory = kMD | 1,
  35. kMDShapeMisMatch = kMD | 2,
  36. kMDInterrupted = kMD | 3,
  37. kMDNoSpace = kMD | 4,
  38. kMDPyFuncException = kMD | 5,
  39. kMDDuplicateKey = kMD | 6,
  40. kMDPythonInterpreterFailure = kMD | 7,
  41. kMDTDTPushFailure = kMD | 8,
  42. kMDFileNotExist = kMD | 9,
  43. kMDProfilingError = kMD | 10,
  44. kMDBoundingBoxOutOfBounds = kMD | 11,
  45. kMDBoundingBoxInvalidShape = kMD | 12,
  46. kMDSyntaxError = kMD | 13,
  47. kMDTimeOut = kMD | 14,
  48. kMDBuddySpaceFull = kMD | 15,
  49. kMDNetWorkError = kMD | 16,
  50. kMDNotImplementedYet = kMD | 17,
  51. // Make this error code the last one. Add new error code above it.
  52. kMDUnexpectedError = kMD | 127,
  53. // ME
  54. kMEFailed = kME | 0x1,
  55. kMEInvalidInput = kME | 0x2,
  56. // MC
  57. kMCFailed = kMC | 0x1,
  58. kMCDeviceError = kMC | 0x2,
  59. kMCInvalidInput = kMC | 0x3,
  60. kMCInvalidArgs = kMC | 0x4,
  61. // Lite // Common error code, range: [-1, -100)
  62. kLiteError = kLite | (0x0FFFFFFF & -1), /**< Common error code. */
  63. kLiteNullptr = kLite | (0x0FFFFFFF & -2), /**< NULL pointer returned.*/
  64. kLiteParamInvalid = kLite | (0x0FFFFFFF & -3), /**< Invalid parameter.*/
  65. kLiteNoChange = kLite | (0x0FFFFFFF & -4), /**< No change. */
  66. kLiteSuccessExit = kLite | (0x0FFFFFFF & -5), /**< No error but exit. */
  67. kLiteMemoryFailed = kLite | (0x0FFFFFFF & -6), /**< Fail to create memory. */
  68. kLiteNotSupport = kLite | (0x0FFFFFFF & -7), /**< Fail to support. */
  69. kLiteThreadPoolError = kLite | (0x0FFFFFFF & -8), /**< Error occur in thread pool. */
  70. // Executor error code, range: [-100,-200)
  71. kLiteOutOfTensorRange = kLite | (0x0FFFFFFF & -100), /**< Failed to check range. */
  72. kLiteInputTensorError = kLite | (0x0FFFFFFF & -101), /**< Failed to check input tensor. */
  73. kLiteReentrantError = kLite | (0x0FFFFFFF & -102), /**< Exist executor running. */
  74. // Graph error code, range: [-200,-300)
  75. kLiteGraphFileError = kLite | (0x0FFFFFFF & -200), /**< Failed to verify graph file. */
  76. // Node error code, range: [-300,-400)
  77. kLiteNotFindOp = kLite | (0x0FFFFFFF & -300), /**< Failed to find operator. */
  78. kLiteInvalidOpName = kLite | (0x0FFFFFFF & -301), /**< Invalid operator name. */
  79. kLiteInvalidOpAttr = kLite | (0x0FFFFFFF & -302), /**< Invalid operator attr. */
  80. kLiteOpExecuteFailure = kLite | (0x0FFFFFFF & -303), /**< Failed to execution operator. */
  81. // Tensor error code, range: [-400,-500)
  82. kLiteFormatError = kLite | (0x0FFFFFFF & -400), /**< Failed to checking tensor format. */
  83. // InferShape error code, range: [-500,-600)
  84. kLiteInferError = kLite | (0x0FFFFFFF & -500), /**< Failed to infer shape. */
  85. kLiteInferInvalid = kLite | (0x0FFFFFFF & -501), /**< Invalid infer shape before runtime. */
  86. // User input param error code, range: [-600, 700)
  87. kLiteInputParamInvalid = kLite | (0x0FFFFFFF & -600), /**< Invalid input param by user. */
  88. };
  89. class Status {
  90. public:
  91. Status() : status_code_(kSuccess), line_of_code_(-1) {}
  92. Status(enum StatusCode status_code, const std::string &status_msg = "") // NOLINT(runtime/explicit)
  93. : status_code_(status_code), status_msg_(status_msg), line_of_code_(-1) {}
  94. Status(const StatusCode code, int line_of_code, const char *file_name, const std::string &extra = "");
  95. ~Status() = default;
  96. enum StatusCode StatusCode() const { return status_code_; }
  97. const std::string &ToString() const { return status_msg_; }
  98. int GetLineOfCode() const { return line_of_code_; }
  99. const std::string &GetErrDescription() const { return status_msg_; }
  100. const std::string &SetErrDescription(const std::string &err_description);
  101. friend std::ostream &operator<<(std::ostream &os, const Status &s);
  102. bool operator==(const Status &other) const { return status_code_ == other.status_code_; }
  103. bool operator==(enum StatusCode other_code) const { return status_code_ == other_code; }
  104. bool operator!=(const Status &other) const { return status_code_ != other.status_code_; }
  105. bool operator!=(enum StatusCode other_code) const { return status_code_ != other_code; }
  106. explicit operator bool() const { return (status_code_ == kSuccess); }
  107. explicit operator int() const { return static_cast<int>(status_code_); }
  108. static Status OK() { return Status(StatusCode::kSuccess); }
  109. bool IsOk() const { return (StatusCode() == StatusCode::kSuccess); }
  110. bool IsError() const { return !IsOk(); }
  111. static std::string CodeAsString(enum StatusCode c);
  112. private:
  113. enum StatusCode status_code_;
  114. std::string status_msg_;
  115. int line_of_code_;
  116. std::string file_name_;
  117. std::string err_description_;
  118. };
  119. } // namespace mindspore
  120. #endif // MINDSPORE_INCLUDE_API_STATUS_H