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

Function AssignVariableTensor

tensorflow/compiler/tf2xla/xla_op_kernel.cc:536–566  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

534namespace {
535
536Status AssignVariableTensor(const Tensor& tensor, DataType type,
537 const XlaOpKernelContext* ctx, xla::XlaOp handle,
538 xla::XlaBuilder* builder) {
539 const XlaExpression* expression = CastExpressionFromTensor(tensor);
540 XlaResource* variable = expression->resource();
541 TF_RET_CHECK(variable != nullptr);
542 TF_RET_CHECK(variable->kind() == XlaResource::kVariable);
543
544 auto shape_or_status = builder->GetShape(handle);
545 if (!shape_or_status.ok()) {
546 return shape_or_status.status();
547 }
548 TensorShape shape;
549 TF_RETURN_IF_ERROR(
550 XLAShapeToTensorShape(shape_or_status.ValueOrDie(), &shape));
551
552 TF_RETURN_IF_ERROR(variable->SetTypeAndShape(type, shape));
553
554 TF_ASSIGN_OR_RETURN(xla::Shape representation_shape,
555 ctx->compiler()->options().shape_representation_fn(
556 shape, type,
557 /*use_fast_memory=*/false));
558 xla::Shape xla_shape;
559 TF_RETURN_IF_ERROR(TensorShapeToXLAShape(type, shape, &xla_shape));
560 if (!xla::ShapeUtil::Compatible(xla_shape, representation_shape)) {
561 handle = xla::Reshape(handle,
562 xla::AsInt64Slice(representation_shape.dimensions()));
563 }
564 variable->SetRepresentationShape(representation_shape);
565 return variable->SetValue(handle);
566}
567
568} // namespace
569

Callers 1

AssignVariableMethod · 0.85

Calls 15

CastExpressionFromTensorFunction · 0.85
XLAShapeToTensorShapeFunction · 0.85
TensorShapeToXLAShapeFunction · 0.85
CompatibleClass · 0.85
SetTypeAndShapeMethod · 0.80
ReshapeFunction · 0.50
AsInt64SliceFunction · 0.50
resourceMethod · 0.45
kindMethod · 0.45
GetShapeMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected