tf_status.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. ==============================================================================*/
  12. #ifndef TENSORFLOW_C_TF_STATUS_H_
  13. #define TENSORFLOW_C_TF_STATUS_H_
  14. #ifdef SWIG
  15. #define TF_CAPI_EXPORT
  16. #else
  17. #if defined(_WIN32)
  18. #ifdef TF_COMPILE_LIBRARY
  19. #define TF_CAPI_EXPORT __declspec(dllexport)
  20. #else
  21. #define TF_CAPI_EXPORT __declspec(dllimport)
  22. #endif // TF_COMPILE_LIBRARY
  23. #else
  24. #define TF_CAPI_EXPORT __attribute__((visibility("default")))
  25. #endif // _WIN32
  26. #endif // SWIG
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. typedef struct TF_Status TF_Status;
  31. // --------------------------------------------------------------------------
  32. // TF_Code holds an error code. The enum values here are identical to
  33. // corresponding values in error_codes.proto.
  34. typedef enum TF_Code {
  35. TF_OK = 0,
  36. TF_CANCELLED = 1,
  37. TF_UNKNOWN = 2,
  38. TF_INVALID_ARGUMENT = 3,
  39. TF_DEADLINE_EXCEEDED = 4,
  40. TF_NOT_FOUND = 5,
  41. TF_ALREADY_EXISTS = 6,
  42. TF_PERMISSION_DENIED = 7,
  43. TF_UNAUTHENTICATED = 16,
  44. TF_RESOURCE_EXHAUSTED = 8,
  45. TF_FAILED_PRECONDITION = 9,
  46. TF_ABORTED = 10,
  47. TF_OUT_OF_RANGE = 11,
  48. TF_UNIMPLEMENTED = 12,
  49. TF_INTERNAL = 13,
  50. TF_UNAVAILABLE = 14,
  51. TF_DATA_LOSS = 15,
  52. } TF_Code;
  53. // --------------------------------------------------------------------------
  54. // Return a new status object.
  55. TF_CAPI_EXPORT extern TF_Status* TF_NewStatus(void);
  56. // Delete a previously created status object.
  57. TF_CAPI_EXPORT extern void TF_DeleteStatus(TF_Status*);
  58. // Record <code, msg> in *s. Any previous information is lost.
  59. // A common use is to clear a status: TF_SetStatus(s, TF_OK, "");
  60. TF_CAPI_EXPORT extern void TF_SetStatus(TF_Status* s, TF_Code code,
  61. const char* msg);
  62. // Convert from an I/O error code (e.g., errno) to a TF_Status value.
  63. // Any previous information is lost. Prefer to use this instead of TF_SetStatus
  64. // when the error comes from I/O operations.
  65. TF_CAPI_EXPORT extern void TF_SetStatusFromIOError(TF_Status* s, int error_code,
  66. const char* context);
  67. // Return the code record in *s.
  68. TF_CAPI_EXPORT extern TF_Code TF_GetCode(const TF_Status* s);
  69. // Return a pointer to the (null-terminated) error message in *s. The
  70. // return value points to memory that is only usable until the next
  71. // mutation to *s. Always returns an empty string if TF_GetCode(s) is
  72. // TF_OK.
  73. TF_CAPI_EXPORT extern const char* TF_Message(const TF_Status* s);
  74. #ifdef __cplusplus
  75. } /* end extern "C" */
  76. #endif
  77. #endif // TENSORFLOW_C_TF_STATUS_H_
粤ICP备19079148号