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

Function ReadVariableInputTensor

tensorflow/compiler/tf2xla/xla_op_kernel.cc:396–429  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

394namespace {
395
396Status ReadVariableInputTensor(const Tensor& tensor, DataType type,
397 const XlaOpKernelContext* ctx,
398 TensorShape* shape, xla::XlaOp* value) {
399 const XlaExpression* expression = CastExpressionFromTensor(tensor);
400 XlaResource* variable = expression->resource();
401 TF_RET_CHECK(variable != nullptr);
402 TF_RET_CHECK(variable->kind() == XlaResource::kVariable);
403 if (!variable->initialized()) {
404 return errors::FailedPrecondition("Read of uninitialized variable ",
405 variable->name());
406 }
407 if (variable->type() != type) {
408 return errors::InvalidArgument(
409 "Type mismatch for read of variable ", variable->name(), ". Expected ",
410 DataTypeString(type), "; got ", DataTypeString(variable->type()));
411 }
412 if (shape) {
413 *shape = variable->shape();
414 }
415
416 TF_ASSIGN_OR_RETURN(xla::Shape representation_shape,
417 ctx->compiler()->options().shape_representation_fn(
418 variable->shape(), variable->type(),
419 /*use_fast_memory=*/false));
420 xla::Shape xla_shape;
421 TF_RETURN_IF_ERROR(
422 TensorShapeToXLAShape(variable->type(), variable->shape(), &xla_shape));
423 if (xla::ShapeUtil::Compatible(xla_shape, representation_shape)) {
424 *value = variable->value();
425 } else {
426 *value = xla::Reshape(variable->value(), variable->shape().dim_sizes());
427 }
428 return Status::OK();
429}
430
431} // namespace
432

Callers 1

ReadVariableInputMethod · 0.85

Calls 15

CastExpressionFromTensorFunction · 0.85
FailedPreconditionFunction · 0.85
InvalidArgumentFunction · 0.85
TensorShapeToXLAShapeFunction · 0.85
CompatibleClass · 0.85
nameMethod · 0.65
typeMethod · 0.65
DataTypeStringFunction · 0.50
ReshapeFunction · 0.50
resourceMethod · 0.45
kindMethod · 0.45
initializedMethod · 0.45

Tested by

no test coverage detected