| 534 | namespace { |
| 535 | |
| 536 | Status 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 |
no test coverage detected