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

Method RecvFileSlice

tensorflow/core/kernels/file_slice_sendrecv_ops.cc:432–475  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

430}
431
432Status 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
477REGISTER_KERNEL_BUILDER(Name("_FileSliceRecv").Device(DEVICE_CPU),
478 FileSliceRecvOp);

Callers

nothing calls this directly

Calls 12

DefaultFunction · 0.85
to_stringFunction · 0.85
GetSliceRendezvousKeyFunction · 0.85
output_alloc_attrMethod · 0.80
is_eagerMethod · 0.80
FlowControlRecvMethod · 0.80
rendezvousMethod · 0.80
StrCatFunction · 0.50
NewWritableFileMethod · 0.45
op_device_contextMethod · 0.45
cancellation_managerMethod · 0.45
AppendMethod · 0.45

Tested by

no test coverage detected