Move tensorflow::Status to tensorflow/core/platform
This is to make TF code structure better/easier to follow. PiperOrigin-RevId: 282599457 Change-Id: I1fabbbaf7231e8f306d392633ff2a1adf5f639c8
This commit is contained in:
parent
2887d751cf
commit
3ba5046626
@ -433,6 +433,7 @@ filegroup(
|
|||||||
"//tensorflow/core/platform:profile_utils/i_cpu_utils_helper.h",
|
"//tensorflow/core/platform:profile_utils/i_cpu_utils_helper.h",
|
||||||
"//tensorflow/core/platform:stacktrace.h",
|
"//tensorflow/core/platform:stacktrace.h",
|
||||||
"//tensorflow/core/platform:stacktrace_handler.h",
|
"//tensorflow/core/platform:stacktrace_handler.h",
|
||||||
|
"//tensorflow/core/platform:status.h",
|
||||||
"//tensorflow/core/platform:stringpiece.h",
|
"//tensorflow/core/platform:stringpiece.h",
|
||||||
"//tensorflow/core/platform:stringprintf.h",
|
"//tensorflow/core/platform:stringprintf.h",
|
||||||
"//tensorflow/core/platform:strcat.h",
|
"//tensorflow/core/platform:strcat.h",
|
||||||
@ -491,6 +492,7 @@ cc_library(
|
|||||||
"//tensorflow/core/platform:macros",
|
"//tensorflow/core/platform:macros",
|
||||||
"//tensorflow/core/platform:protobuf",
|
"//tensorflow/core/platform:protobuf",
|
||||||
"//tensorflow/core/platform:platform",
|
"//tensorflow/core/platform:platform",
|
||||||
|
"//tensorflow/core/platform:status",
|
||||||
"//tensorflow/core/platform:stringpiece",
|
"//tensorflow/core/platform:stringpiece",
|
||||||
"//tensorflow/core/platform:tstring",
|
"//tensorflow/core/platform:tstring",
|
||||||
"//tensorflow/core/platform:types",
|
"//tensorflow/core/platform:types",
|
||||||
@ -529,9 +531,6 @@ cc_library(
|
|||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
":lib_internal",
|
":lib_internal",
|
||||||
"//tensorflow/core/platform:str_util",
|
|
||||||
"//tensorflow/core/platform:stringpiece",
|
|
||||||
"//tensorflow/core/platform:stringprintf",
|
|
||||||
"@com_google_absl//absl/container:inlined_vector",
|
"@com_google_absl//absl/container:inlined_vector",
|
||||||
"@com_google_absl//absl/strings",
|
"@com_google_absl//absl/strings",
|
||||||
"@com_google_absl//absl/types:optional",
|
"@com_google_absl//absl/types:optional",
|
||||||
@ -2160,7 +2159,6 @@ cc_library(
|
|||||||
"@com_google_absl//absl/strings",
|
"@com_google_absl//absl/strings",
|
||||||
"//third_party/eigen3",
|
"//third_party/eigen3",
|
||||||
"@com_google_absl//absl/base:core_headers",
|
"@com_google_absl//absl/base:core_headers",
|
||||||
"//tensorflow/core/platform:regexp",
|
|
||||||
"//tensorflow/core/platform/default/build_config:platformlib",
|
"//tensorflow/core/platform/default/build_config:platformlib",
|
||||||
] + if_static([":lib_internal_impl"]),
|
] + if_static([":lib_internal_impl"]),
|
||||||
)
|
)
|
||||||
@ -2281,9 +2279,11 @@ cc_library(
|
|||||||
"//tensorflow/core/platform:regexp",
|
"//tensorflow/core/platform:regexp",
|
||||||
"//tensorflow/core/platform:scanner",
|
"//tensorflow/core/platform:scanner",
|
||||||
"//tensorflow/core/platform:setround",
|
"//tensorflow/core/platform:setround",
|
||||||
"//tensorflow/core/platform:strong_hash",
|
"//tensorflow/core/platform:status",
|
||||||
"//tensorflow/core/platform:strcat",
|
"//tensorflow/core/platform:strcat",
|
||||||
|
"//tensorflow/core/platform:stringpiece",
|
||||||
"//tensorflow/core/platform:stringprintf",
|
"//tensorflow/core/platform:stringprintf",
|
||||||
|
"//tensorflow/core/platform:strong_hash",
|
||||||
"//tensorflow/core/platform:str_util",
|
"//tensorflow/core/platform:str_util",
|
||||||
"//tensorflow/core/platform:subprocess",
|
"//tensorflow/core/platform:subprocess",
|
||||||
"//tensorflow/core/platform:tensor_coding",
|
"//tensorflow/core/platform:tensor_coding",
|
||||||
|
@ -100,21 +100,9 @@ cc_library(
|
|||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "status",
|
name = "status",
|
||||||
srcs = ["status.cc"],
|
|
||||||
hdrs = ["status.h"],
|
hdrs = ["status.h"],
|
||||||
deps = [
|
deps = [
|
||||||
":error_codes_proto_cc",
|
"//tensorflow/core/platform:status",
|
||||||
"//tensorflow/core:error_codes_proto_impl_cc",
|
|
||||||
"//tensorflow/core/platform:logging",
|
|
||||||
"//tensorflow/core/platform:macros",
|
|
||||||
"//tensorflow/core/platform:mutex",
|
|
||||||
"//tensorflow/core/platform:stacktrace",
|
|
||||||
"//tensorflow/core/platform:str_util",
|
|
||||||
"//tensorflow/core/platform:strcat",
|
|
||||||
"//tensorflow/core/platform:stringpiece",
|
|
||||||
"//tensorflow/core/platform:stringprintf",
|
|
||||||
"//tensorflow/core/platform:types",
|
|
||||||
"@com_google_absl//absl/base",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -190,7 +178,6 @@ filegroup(
|
|||||||
"arena.cc",
|
"arena.cc",
|
||||||
"bitmap.cc",
|
"bitmap.cc",
|
||||||
"coding.cc",
|
"coding.cc",
|
||||||
"status.cc",
|
|
||||||
],
|
],
|
||||||
visibility = ["//tensorflow/core:__pkg__"],
|
visibility = ["//tensorflow/core:__pkg__"],
|
||||||
)
|
)
|
||||||
|
@ -16,185 +16,6 @@ limitations under the License.
|
|||||||
#ifndef TENSORFLOW_CORE_LIB_CORE_STATUS_H_
|
#ifndef TENSORFLOW_CORE_LIB_CORE_STATUS_H_
|
||||||
#define TENSORFLOW_CORE_LIB_CORE_STATUS_H_
|
#define TENSORFLOW_CORE_LIB_CORE_STATUS_H_
|
||||||
|
|
||||||
#include <functional>
|
#include "tensorflow/core/platform/status.h"
|
||||||
#include <iosfwd>
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "tensorflow/core/platform/logging.h"
|
|
||||||
#include "tensorflow/core/platform/macros.h"
|
|
||||||
#include "tensorflow/core/platform/stringpiece.h"
|
|
||||||
#include "tensorflow/core/platform/types.h"
|
|
||||||
#include "tensorflow/core/protobuf/error_codes.pb.h"
|
|
||||||
|
|
||||||
namespace tensorflow {
|
|
||||||
|
|
||||||
#if defined(__clang__)
|
|
||||||
// Only clang supports warn_unused_result as a type annotation.
|
|
||||||
class TF_MUST_USE_RESULT Status;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// @ingroup core
|
|
||||||
/// Denotes success or failure of a call in Tensorflow.
|
|
||||||
class Status {
|
|
||||||
public:
|
|
||||||
/// Create a success status.
|
|
||||||
Status() {}
|
|
||||||
|
|
||||||
/// \brief Create a status with the specified error code and msg as a
|
|
||||||
/// human-readable string containing more detailed information.
|
|
||||||
Status(tensorflow::error::Code code, tensorflow::StringPiece msg);
|
|
||||||
|
|
||||||
/// Copy the specified status.
|
|
||||||
Status(const Status& s);
|
|
||||||
Status& operator=(const Status& s);
|
|
||||||
#ifndef SWIG
|
|
||||||
Status(Status&& s) noexcept;
|
|
||||||
Status& operator=(Status&& s) noexcept;
|
|
||||||
#endif // SWIG
|
|
||||||
|
|
||||||
static Status OK() { return Status(); }
|
|
||||||
|
|
||||||
/// Returns true iff the status indicates success.
|
|
||||||
bool ok() const { return (state_ == NULL); }
|
|
||||||
|
|
||||||
tensorflow::error::Code code() const {
|
|
||||||
return ok() ? tensorflow::error::OK : state_->code;
|
|
||||||
}
|
|
||||||
|
|
||||||
const string& error_message() const {
|
|
||||||
return ok() ? empty_string() : state_->msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(const Status& x) const;
|
|
||||||
bool operator!=(const Status& x) const;
|
|
||||||
|
|
||||||
/// \brief If `ok()`, stores `new_status` into `*this`. If `!ok()`,
|
|
||||||
/// preserves the current status, but may augment with additional
|
|
||||||
/// information about `new_status`.
|
|
||||||
///
|
|
||||||
/// Convenient way of keeping track of the first error encountered.
|
|
||||||
/// Instead of:
|
|
||||||
/// `if (overall_status.ok()) overall_status = new_status`
|
|
||||||
/// Use:
|
|
||||||
/// `overall_status.Update(new_status);`
|
|
||||||
void Update(const Status& new_status);
|
|
||||||
|
|
||||||
/// \brief Return a string representation of this status suitable for
|
|
||||||
/// printing. Returns the string `"OK"` for success.
|
|
||||||
string ToString() const;
|
|
||||||
|
|
||||||
// Ignores any errors. This method does nothing except potentially suppress
|
|
||||||
// complaints from any tools that are checking that errors are not dropped on
|
|
||||||
// the floor.
|
|
||||||
void IgnoreError() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static const string& empty_string();
|
|
||||||
struct State {
|
|
||||||
tensorflow::error::Code code;
|
|
||||||
string msg;
|
|
||||||
};
|
|
||||||
// OK status has a `NULL` state_. Otherwise, `state_` points to
|
|
||||||
// a `State` structure containing the error code and message(s)
|
|
||||||
std::unique_ptr<State> state_;
|
|
||||||
|
|
||||||
void SlowCopyFrom(const State* src);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Helper class to manage multiple child status values.
|
|
||||||
class StatusGroup {
|
|
||||||
public:
|
|
||||||
// Utility function to mark a Status as derived. By marking derived status,
|
|
||||||
// Derived status messages are ignored when reporting errors to end users.
|
|
||||||
static Status MakeDerived(const Status& s);
|
|
||||||
static bool IsDerived(const Status& s);
|
|
||||||
|
|
||||||
// Enable warning and error log collection for appending to the aggregated
|
|
||||||
// status. This function may be called more than once.
|
|
||||||
static void ConfigureLogHistory();
|
|
||||||
|
|
||||||
// Return a merged status with combined child status messages with a summary.
|
|
||||||
Status as_summary_status() const;
|
|
||||||
// Return a merged status with combined child status messages with
|
|
||||||
// concatenation.
|
|
||||||
Status as_concatenated_status() const;
|
|
||||||
|
|
||||||
bool ok() const { return ok_; }
|
|
||||||
|
|
||||||
// Augment this group with the child status `status`.
|
|
||||||
void Update(const Status& status);
|
|
||||||
|
|
||||||
// Attach recent warning and error log messages
|
|
||||||
void AttachLogMessages();
|
|
||||||
bool HasLogMessages() const { return !recent_logs_.empty(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool ok_ = true;
|
|
||||||
size_t num_ok_ = 0;
|
|
||||||
std::vector<Status> children_;
|
|
||||||
std::vector<std::string> recent_logs_; // recent warning and error logs
|
|
||||||
};
|
|
||||||
|
|
||||||
inline Status::Status(const Status& s)
|
|
||||||
: state_((s.state_ == nullptr) ? nullptr : new State(*s.state_)) {}
|
|
||||||
|
|
||||||
inline Status& Status::operator=(const Status& s) {
|
|
||||||
// The following condition catches both aliasing (when this == &s),
|
|
||||||
// and the common case where both s and *this are ok.
|
|
||||||
if (state_ != s.state_) {
|
|
||||||
SlowCopyFrom(s.state_.get());
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef SWIG
|
|
||||||
inline Status::Status(Status&& s) noexcept : state_(std::move(s.state_)) {}
|
|
||||||
|
|
||||||
inline Status& Status::operator=(Status&& s) noexcept {
|
|
||||||
if (state_ != s.state_) {
|
|
||||||
state_ = std::move(s.state_);
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
#endif // SWIG
|
|
||||||
|
|
||||||
inline bool Status::operator==(const Status& x) const {
|
|
||||||
return (this->state_ == x.state_) || (ToString() == x.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Status::operator!=(const Status& x) const { return !(*this == x); }
|
|
||||||
|
|
||||||
/// @ingroup core
|
|
||||||
std::ostream& operator<<(std::ostream& os, const Status& x);
|
|
||||||
|
|
||||||
typedef std::function<void(const Status&)> StatusCallback;
|
|
||||||
|
|
||||||
extern tensorflow::string* TfCheckOpHelperOutOfLine(
|
|
||||||
const ::tensorflow::Status& v, const char* msg);
|
|
||||||
|
|
||||||
inline tensorflow::string* TfCheckOpHelper(::tensorflow::Status v,
|
|
||||||
const char* msg) {
|
|
||||||
if (v.ok()) return nullptr;
|
|
||||||
return TfCheckOpHelperOutOfLine(v, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TF_DO_CHECK_OK(val, level) \
|
|
||||||
while (auto _result = ::tensorflow::TfCheckOpHelper(val, #val)) \
|
|
||||||
LOG(level) << *(_result)
|
|
||||||
|
|
||||||
#define TF_CHECK_OK(val) TF_DO_CHECK_OK(val, FATAL)
|
|
||||||
#define TF_QCHECK_OK(val) TF_DO_CHECK_OK(val, QFATAL)
|
|
||||||
|
|
||||||
// DEBUG only version of TF_CHECK_OK. Compiler still parses 'val' even in opt
|
|
||||||
// mode.
|
|
||||||
#ifndef NDEBUG
|
|
||||||
#define TF_DCHECK_OK(val) TF_CHECK_OK(val)
|
|
||||||
#else
|
|
||||||
#define TF_DCHECK_OK(val) \
|
|
||||||
while (false && (::tensorflow::Status::OK() == (val))) LOG(FATAL)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace tensorflow
|
|
||||||
|
|
||||||
#endif // TENSORFLOW_CORE_LIB_CORE_STATUS_H_
|
#endif // TENSORFLOW_CORE_LIB_CORE_STATUS_H_
|
||||||
|
@ -427,6 +427,16 @@ cc_library(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "setround",
|
||||||
|
srcs = ["setround.cc"],
|
||||||
|
hdrs = ["setround.h"],
|
||||||
|
deps = [
|
||||||
|
":logging",
|
||||||
|
":macros",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "stacktrace",
|
name = "stacktrace",
|
||||||
hdrs = ["stacktrace.h"],
|
hdrs = ["stacktrace.h"],
|
||||||
@ -453,12 +463,21 @@ cc_library(
|
|||||||
)
|
)
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "setround",
|
name = "status",
|
||||||
srcs = ["setround.cc"],
|
srcs = ["status.cc"],
|
||||||
hdrs = ["setround.h"],
|
hdrs = ["status.h"],
|
||||||
deps = [
|
deps = [
|
||||||
":logging",
|
":logging",
|
||||||
":macros",
|
":macros",
|
||||||
|
":mutex",
|
||||||
|
":stacktrace",
|
||||||
|
":str_util",
|
||||||
|
":strcat",
|
||||||
|
":stringpiece",
|
||||||
|
":stringprintf",
|
||||||
|
":types",
|
||||||
|
"//tensorflow/core:error_codes_proto_impl_cc",
|
||||||
|
"@com_google_absl//absl/base",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -805,6 +824,7 @@ filegroup(
|
|||||||
"protobuf_util.cc",
|
"protobuf_util.cc",
|
||||||
"scanner.cc",
|
"scanner.cc",
|
||||||
"setround.cc",
|
"setround.cc",
|
||||||
|
"status.cc",
|
||||||
"strcat.cc",
|
"strcat.cc",
|
||||||
"stringprintf.cc",
|
"stringprintf.cc",
|
||||||
"str_util.cc",
|
"str_util.cc",
|
||||||
|
@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
|
|
||||||
#include "tensorflow/core/lib/core/status.h"
|
#include "tensorflow/core/platform/status.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
200
tensorflow/core/platform/status.h
Normal file
200
tensorflow/core/platform/status.h
Normal file
@ -0,0 +1,200 @@
|
|||||||
|
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==============================================================================*/
|
||||||
|
|
||||||
|
#ifndef TENSORFLOW_CORE_PLATFORM_STATUS_H_
|
||||||
|
#define TENSORFLOW_CORE_PLATFORM_STATUS_H_
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <iosfwd>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "tensorflow/core/platform/logging.h"
|
||||||
|
#include "tensorflow/core/platform/macros.h"
|
||||||
|
#include "tensorflow/core/platform/stringpiece.h"
|
||||||
|
#include "tensorflow/core/platform/types.h"
|
||||||
|
#include "tensorflow/core/protobuf/error_codes.pb.h"
|
||||||
|
|
||||||
|
namespace tensorflow {
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
// Only clang supports warn_unused_result as a type annotation.
|
||||||
|
class TF_MUST_USE_RESULT Status;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// @ingroup core
|
||||||
|
/// Denotes success or failure of a call in Tensorflow.
|
||||||
|
class Status {
|
||||||
|
public:
|
||||||
|
/// Create a success status.
|
||||||
|
Status() {}
|
||||||
|
|
||||||
|
/// \brief Create a status with the specified error code and msg as a
|
||||||
|
/// human-readable string containing more detailed information.
|
||||||
|
Status(tensorflow::error::Code code, tensorflow::StringPiece msg);
|
||||||
|
|
||||||
|
/// Copy the specified status.
|
||||||
|
Status(const Status& s);
|
||||||
|
Status& operator=(const Status& s);
|
||||||
|
#ifndef SWIG
|
||||||
|
Status(Status&& s) noexcept;
|
||||||
|
Status& operator=(Status&& s) noexcept;
|
||||||
|
#endif // SWIG
|
||||||
|
|
||||||
|
static Status OK() { return Status(); }
|
||||||
|
|
||||||
|
/// Returns true iff the status indicates success.
|
||||||
|
bool ok() const { return (state_ == NULL); }
|
||||||
|
|
||||||
|
tensorflow::error::Code code() const {
|
||||||
|
return ok() ? tensorflow::error::OK : state_->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
const string& error_message() const {
|
||||||
|
return ok() ? empty_string() : state_->msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const Status& x) const;
|
||||||
|
bool operator!=(const Status& x) const;
|
||||||
|
|
||||||
|
/// \brief If `ok()`, stores `new_status` into `*this`. If `!ok()`,
|
||||||
|
/// preserves the current status, but may augment with additional
|
||||||
|
/// information about `new_status`.
|
||||||
|
///
|
||||||
|
/// Convenient way of keeping track of the first error encountered.
|
||||||
|
/// Instead of:
|
||||||
|
/// `if (overall_status.ok()) overall_status = new_status`
|
||||||
|
/// Use:
|
||||||
|
/// `overall_status.Update(new_status);`
|
||||||
|
void Update(const Status& new_status);
|
||||||
|
|
||||||
|
/// \brief Return a string representation of this status suitable for
|
||||||
|
/// printing. Returns the string `"OK"` for success.
|
||||||
|
string ToString() const;
|
||||||
|
|
||||||
|
// Ignores any errors. This method does nothing except potentially suppress
|
||||||
|
// complaints from any tools that are checking that errors are not dropped on
|
||||||
|
// the floor.
|
||||||
|
void IgnoreError() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const string& empty_string();
|
||||||
|
struct State {
|
||||||
|
tensorflow::error::Code code;
|
||||||
|
string msg;
|
||||||
|
};
|
||||||
|
// OK status has a `NULL` state_. Otherwise, `state_` points to
|
||||||
|
// a `State` structure containing the error code and message(s)
|
||||||
|
std::unique_ptr<State> state_;
|
||||||
|
|
||||||
|
void SlowCopyFrom(const State* src);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper class to manage multiple child status values.
|
||||||
|
class StatusGroup {
|
||||||
|
public:
|
||||||
|
// Utility function to mark a Status as derived. By marking derived status,
|
||||||
|
// Derived status messages are ignored when reporting errors to end users.
|
||||||
|
static Status MakeDerived(const Status& s);
|
||||||
|
static bool IsDerived(const Status& s);
|
||||||
|
|
||||||
|
// Enable warning and error log collection for appending to the aggregated
|
||||||
|
// status. This function may be called more than once.
|
||||||
|
static void ConfigureLogHistory();
|
||||||
|
|
||||||
|
// Return a merged status with combined child status messages with a summary.
|
||||||
|
Status as_summary_status() const;
|
||||||
|
// Return a merged status with combined child status messages with
|
||||||
|
// concatenation.
|
||||||
|
Status as_concatenated_status() const;
|
||||||
|
|
||||||
|
bool ok() const { return ok_; }
|
||||||
|
|
||||||
|
// Augment this group with the child status `status`.
|
||||||
|
void Update(const Status& status);
|
||||||
|
|
||||||
|
// Attach recent warning and error log messages
|
||||||
|
void AttachLogMessages();
|
||||||
|
bool HasLogMessages() const { return !recent_logs_.empty(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool ok_ = true;
|
||||||
|
size_t num_ok_ = 0;
|
||||||
|
std::vector<Status> children_;
|
||||||
|
std::vector<std::string> recent_logs_; // recent warning and error logs
|
||||||
|
};
|
||||||
|
|
||||||
|
inline Status::Status(const Status& s)
|
||||||
|
: state_((s.state_ == nullptr) ? nullptr : new State(*s.state_)) {}
|
||||||
|
|
||||||
|
inline Status& Status::operator=(const Status& s) {
|
||||||
|
// The following condition catches both aliasing (when this == &s),
|
||||||
|
// and the common case where both s and *this are ok.
|
||||||
|
if (state_ != s.state_) {
|
||||||
|
SlowCopyFrom(s.state_.get());
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef SWIG
|
||||||
|
inline Status::Status(Status&& s) noexcept : state_(std::move(s.state_)) {}
|
||||||
|
|
||||||
|
inline Status& Status::operator=(Status&& s) noexcept {
|
||||||
|
if (state_ != s.state_) {
|
||||||
|
state_ = std::move(s.state_);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
#endif // SWIG
|
||||||
|
|
||||||
|
inline bool Status::operator==(const Status& x) const {
|
||||||
|
return (this->state_ == x.state_) || (ToString() == x.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool Status::operator!=(const Status& x) const { return !(*this == x); }
|
||||||
|
|
||||||
|
/// @ingroup core
|
||||||
|
std::ostream& operator<<(std::ostream& os, const Status& x);
|
||||||
|
|
||||||
|
typedef std::function<void(const Status&)> StatusCallback;
|
||||||
|
|
||||||
|
extern tensorflow::string* TfCheckOpHelperOutOfLine(
|
||||||
|
const ::tensorflow::Status& v, const char* msg);
|
||||||
|
|
||||||
|
inline tensorflow::string* TfCheckOpHelper(::tensorflow::Status v,
|
||||||
|
const char* msg) {
|
||||||
|
if (v.ok()) return nullptr;
|
||||||
|
return TfCheckOpHelperOutOfLine(v, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TF_DO_CHECK_OK(val, level) \
|
||||||
|
while (auto _result = ::tensorflow::TfCheckOpHelper(val, #val)) \
|
||||||
|
LOG(level) << *(_result)
|
||||||
|
|
||||||
|
#define TF_CHECK_OK(val) TF_DO_CHECK_OK(val, FATAL)
|
||||||
|
#define TF_QCHECK_OK(val) TF_DO_CHECK_OK(val, QFATAL)
|
||||||
|
|
||||||
|
// DEBUG only version of TF_CHECK_OK. Compiler still parses 'val' even in opt
|
||||||
|
// mode.
|
||||||
|
#ifndef NDEBUG
|
||||||
|
#define TF_DCHECK_OK(val) TF_CHECK_OK(val)
|
||||||
|
#else
|
||||||
|
#define TF_DCHECK_OK(val) \
|
||||||
|
while (false && (::tensorflow::Status::OK() == (val))) LOG(FATAL)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace tensorflow
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_CORE_PLATFORM_STATUS_H_
|
@ -276,7 +276,7 @@ string ReadFromStream(tensorflow::io::BufferedInputStream* stream,
|
|||||||
TF_Status* status);
|
TF_Status* status);
|
||||||
|
|
||||||
%ignore tensorflow::Status::operator=;
|
%ignore tensorflow::Status::operator=;
|
||||||
%include "tensorflow/core/lib/core/status.h"
|
%include "tensorflow/core/platform/status.h"
|
||||||
|
|
||||||
%ignoreall
|
%ignoreall
|
||||||
%unignore tensorflow::io;
|
%unignore tensorflow::io;
|
||||||
|
Loading…
Reference in New Issue
Block a user