aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/ops/resource_variable_ops.cc
diff options
context:
space:
mode:
authorGravatar Alexandre Passos <apassos@google.com>2017-02-23 15:05:45 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-02-23 15:37:47 -0800
commit9f12227ae9930decb915062614792aa01617264d (patch)
tree1d296256d90546629d648902d1194ee68eb6a06d /tensorflow/core/ops/resource_variable_ops.cc
parente9786df5e89f0345b2eb32d688c7be31c5259ba0 (diff)
Do an aliasing read of a resource variable when fetching.
Change: 148396841
Diffstat (limited to 'tensorflow/core/ops/resource_variable_ops.cc')
-rw-r--r--tensorflow/core/ops/resource_variable_ops.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/tensorflow/core/ops/resource_variable_ops.cc b/tensorflow/core/ops/resource_variable_ops.cc
index c8183edc42..7316328f44 100644
--- a/tensorflow/core/ops/resource_variable_ops.cc
+++ b/tensorflow/core/ops/resource_variable_ops.cc
@@ -84,6 +84,35 @@ resource: handle to the resource in which to store the variable.
dtype: the dtype of the value.
)");
+REGISTER_OP("_UnsafeReadVariable")
+ .Input("resource: resource")
+ .Output("value: dtype")
+ .Attr("dtype: type")
+ .SetShapeFn([](InferenceContext* c) {
+ DataType handle_dtype = c->input_handle_dtype(0);
+ DataType value_dtype;
+ c->GetAttr("dtype", &value_dtype);
+ if (handle_dtype != value_dtype) {
+ return errors::InvalidArgument(
+ "Trying to read variable with wrong dtype. "
+ "Expected ",
+ handle_dtype, " got ", value_dtype);
+ }
+ c->set_output(0, c->input_handle_shape(0));
+ return Status::OK();
+ })
+ .Doc(R"(
+Reads the value of a variable without any memory model.
+
+The tensor returned by this operation aliases a mutable Tensor, and its value
+can be observed to be different by different ops.
+
+Internal and private to the tensorflow implementation.
+
+resource: handle to the resource in which to store the variable.
+dtype: the dtype of the value.
+)");
+
REGISTER_OP("DestroyResourceOp")
.Input("resource: resource")
.Attr("ignore_lookup_error: bool = true")