| 430 | } |
| 431 | |
| 432 | Status FileSliceRecvOp::RecvFileSlice(OpKernelContext* ctx, |
| 433 | const FrameAndIter& frame_iter, |
| 434 | const uint64 element_bytes, |
| 435 | const string& file_path) { |
| 436 | // create file |
| 437 | Env* env = Env::Default(); |
| 438 | std::unique_ptr<WritableFile> file_ptr; |
| 439 | TF_RETURN_IF_ERROR(env->NewWritableFile(file_path, &file_ptr)); |
| 440 | |
| 441 | Rendezvous::Args args; |
| 442 | args.device_context = ctx->op_device_context(); |
| 443 | args.alloc_attrs = ctx->output_alloc_attr(0); |
| 444 | if (ctx->is_eager()) { |
| 445 | // NOTE(fishx): Only set cancellation_manager in eager mode. Because in |
| 446 | // Tensorflow 1.x, session (or graph_mgr) will abort the underlying |
| 447 | // rendezvous if it encounters any error. |
| 448 | args.cancellation_manager = ctx->cancellation_manager(); |
| 449 | } |
| 450 | Rendezvous::ParsedKey parsed_key; |
| 451 | |
| 452 | int64 slice_num = element_bytes / slice_size_; |
| 453 | if (element_bytes % slice_size_ != 0) { |
| 454 | slice_num += 1; |
| 455 | } |
| 456 | Tensor data_t; |
| 457 | bool is_dead = false; |
| 458 | for (int64 i = 0; i < slice_num; i++) { |
| 459 | std::string tensor_name_suffix = \ |
| 460 | strings::StrCat("_slice_transfer_data_", std::to_string(0), "_", |
| 461 | std::to_string(i)); |
| 462 | slice_sendrecv::GetSliceRendezvousKey(key_prefix_, tensor_name_suffix, |
| 463 | frame_iter, &parsed_key.buf_); |
| 464 | VLOG(2) << "FileSliceRecv " << parsed_key.buf_; |
| 465 | TF_RETURN_IF_ERROR(Rendezvous::ParseKey(parsed_key.buf_, &parsed_key)); |
| 466 | TF_RETURN_IF_ERROR( |
| 467 | ctx->rendezvous()->FlowControlRecv(tensor_name_, parsed_key, args, |
| 468 | &data_t, &is_dead, timeout_ms_)); |
| 469 | // This shouldn't be a dead tensor. |
| 470 | CHECK_EQ(is_dead, false); |
| 471 | file_ptr->Append(data_t.scalar<tstring>()()); |
| 472 | } |
| 473 | |
| 474 | return Status::OK(); |
| 475 | } |
| 476 | |
| 477 | REGISTER_KERNEL_BUILDER(Name("_FileSliceRecv").Device(DEVICE_CPU), |
| 478 | FileSliceRecvOp); |
nothing calls this directly
no test coverage detected