| 43 | } |
| 44 | |
| 45 | void SliceSendOp::Compute(OpKernelContext* ctx) { |
| 46 | OP_REQUIRES( |
| 47 | ctx, ctx->rendezvous() != nullptr, |
| 48 | errors::Internal("Op kernel context needs to provide a rendezvous.")); |
| 49 | |
| 50 | const Tensor& input_t = ctx->input(0); |
| 51 | FrameAndIter frame_iter = \ |
| 52 | slice_sendrecv::GetFrameAndIter(ctx, hostmem_sendrecv_); |
| 53 | |
| 54 | // send total_bytes. |
| 55 | OP_REQUIRES_OK(ctx, SendTotalBytes(ctx, frame_iter, input_t)); |
| 56 | // if input is dead, only send total_bytes dead tensor. |
| 57 | if (ctx->is_input_dead()) { |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | // if total bytes is smaller than slice size, send directly. |
| 62 | if (input_t.TotalBytes() <= slice_size_) { |
| 63 | Rendezvous::Args args; |
| 64 | args.device_context = ctx->op_device_context(); |
| 65 | args.alloc_attrs = ctx->input_alloc_attr(0); |
| 66 | |
| 67 | Rendezvous::ParsedKey parsed_key; |
| 68 | slice_sendrecv::GetSliceRendezvousKey(key_prefix_, "_transfer_data", |
| 69 | frame_iter, &parsed_key.buf_); |
| 70 | VLOG(2) << "SliceSend " << parsed_key.buf_; |
| 71 | OP_REQUIRES_OK(ctx, Rendezvous::ParseKey(parsed_key.buf_, &parsed_key)); |
| 72 | OP_REQUIRES_OK(ctx, ctx->rendezvous()->Send(parsed_key, args, input_t, |
| 73 | ctx->is_input_dead())); |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | // send shape. |
| 78 | OP_REQUIRES_OK(ctx, SendShape(ctx, frame_iter, input_t)); |
| 79 | |
| 80 | // send data. |
| 81 | if (dtype_ == DT_STRING) { |
| 82 | OP_REQUIRES_OK(ctx, SendString(ctx, frame_iter, input_t)); |
| 83 | } else { |
| 84 | OP_REQUIRES_OK(ctx, SendBasicType(ctx, frame_iter, input_t)); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | Status SliceSendOp::SendTotalBytes(OpKernelContext* ctx, |
| 89 | const FrameAndIter& frame_iter, |
nothing calls this directly
no test coverage detected