MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Compute

Method Compute

tensorflow/core/kernels/resource_variable_ops.cc:130–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128} // namespace
129
130void ReadVariableOp::Compute(OpKernelContext* ctx) {
131 core::RefCountPtr<Var> variable;
132 const ResourceHandle& handle = HandleFromInput(ctx, 0);
133 const auto status = LookupResource(ctx, handle, &variable);
134 OP_REQUIRES(ctx, status.ok(),
135 errors::FailedPrecondition(
136 "Error while reading resource variable ", handle.name(),
137 " from Container: ", handle.container(),
138 ". This could mean that the variable was uninitialized. ",
139 status.ToString()));
140
141 {
142 tf_shared_lock ml(*variable->mu());
143 // We're acquiring a reference to the underlying buffer while
144 // holding a shared lock to guarantee ordering of reads and
145 // writes when in copy-on-write mode.
146 if (!variable->copy_on_read_mode.load()) {
147 const Tensor* t = variable->tensor();
148 OP_REQUIRES(
149 ctx, dtype_ == t->dtype(),
150 errors::InvalidArgument(
151 "Trying to read variable with wrong dtype. Expected ",
152 DataTypeString(dtype_), " got ", DataTypeString(t->dtype())));
153 ctx->set_output(0, *t);
154 return;
155 }
156 }
157 // Note: no need to check copy_on_read_mode again here as it only changes from
158 // false to true, never the other way around. We here do the copy under an
159 // exclusive lock to avoid racing writes.
160 mutex_lock ml(*variable->mu());
161 const Tensor* t = variable->tensor();
162 OP_REQUIRES_OK(ctx, CopyVariable(0, ctx, t));
163}
164
165ReadVariablesOp::ReadVariablesOp(OpKernelConstruction* c) : OpKernel(c) {
166 int n;

Callers

nothing calls this directly

Calls 15

HandleFromInputFunction · 0.85
LookupResourceFunction · 0.85
FailedPreconditionFunction · 0.85
InvalidArgumentFunction · 0.85
CopyVariableFunction · 0.85
LookupResourcesFunction · 0.85
set_on_hostMethod · 0.80
nameMethod · 0.65
DataTypeStringFunction · 0.50
TensorShapeClass · 0.50
DeleteResourceFunction · 0.50
okMethod · 0.45

Tested by

no test coverage detected