diff options
author | Igor Ganichev <iga@google.com> | 2017-11-29 14:01:29 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2017-11-29 14:06:17 -0800 |
commit | cb5a63d8d2b6e049a0a128ba47560f842497db8b (patch) | |
tree | ced4a0647f9bab632a2d9a80895e7cc9bca0c78c /tensorflow/c/c_api_internal.h | |
parent | 1d0b07351d901334b33565595d4c23607f11cc27 (diff) |
Check when session cannot run because its graph was modified
With current tensorflow code, if user modifies
some operation after session.run() was called, this modification will
never make it to the C++ runtime and no errors will be raised leading
to silent wrong results.
This change adds checks for such cases when C API is enabled. We don't
change the code path for C API being disabled because C API should
be enabled by default soon.
PiperOrigin-RevId: 177359630
Diffstat (limited to 'tensorflow/c/c_api_internal.h')
-rw-r--r-- | tensorflow/c/c_api_internal.h | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/tensorflow/c/c_api_internal.h b/tensorflow/c/c_api_internal.h index bb04e01bee..aac333d9e2 100644 --- a/tensorflow/c/c_api_internal.h +++ b/tensorflow/c/c_api_internal.h @@ -81,12 +81,20 @@ struct TF_Graph { std::unordered_map<tensorflow::string, tensorflow::Node*> name_map GUARDED_BY(mu); - // TF_Graph may only / must be deleted when - // num_sessions == 0 && delete_requested == true - - // num_sessions incremented by TF_NewSession, and decremented by + // The keys of this map are all the active sessions using this graph. + // Each value is the current "runnability" status of the corresponding + // session. Under normal conditions all statuses are Status::OK(), but + // if some operation is mutated after it was run by a session (this + // is detected in RecordMutation function), that session is no longer + // safe to run. Its status will contain the error that will be returned + // to the user, should she try running this session. + // + // Sessions are added to this map in TF_NewSession, and removed in // TF_DeleteSession. - int num_sessions GUARDED_BY(mu); + // TF_Graph may only / must be deleted when + // sessions.size() == 0 && delete_requested == true + tensorflow::gtl::FlatMap<TF_Session*, tensorflow::Status> sessions + GUARDED_BY(mu); bool delete_requested GUARDED_BY(mu); // set true by TF_DeleteGraph // Used to link graphs contained in TF_WhileParams to the parent graph that @@ -167,6 +175,9 @@ TF_Tensor* TF_TensorFromTensor(const Tensor& src, TF_Status* status); Status MessageToBuffer(const tensorflow::protobuf::Message& in, TF_Buffer* out); +void RecordMutation(TF_Graph* graph, const TF_Operation& op, + const char* mutation_type); + } // end namespace tensorflow #endif // TENSORFLOW_C_C_API_INTERNAL_H_ |