| 177 | } |
| 178 | |
| 179 | Status FileSliceSendOp::SendFileSlice(OpKernelContext* ctx, |
| 180 | const FrameAndIter& frame_iter, |
| 181 | const Tensor& file_path_t, |
| 182 | const uint64 element_bytes) { |
| 183 | Rendezvous::Args args; |
| 184 | args.device_context = ctx->op_device_context(); |
| 185 | args.alloc_attrs = AllocatorAttributes(); |
| 186 | Rendezvous::ParsedKey parsed_key; |
| 187 | |
| 188 | std::unique_ptr<RandomAccessFile> file; |
| 189 | Env* env = Env::Default(); |
| 190 | const string& file_path = file_path_t.scalar<tstring>()(); |
| 191 | TF_RETURN_IF_ERROR(env->NewRandomAccessFile(file_path, &file)); |
| 192 | |
| 193 | // Slice Send. |
| 194 | int64 slice_num = element_bytes / slice_size_; |
| 195 | if (element_bytes % slice_size_ != 0) { |
| 196 | slice_num += 1; |
| 197 | } |
| 198 | Tensor data_t; |
| 199 | for (int64 i = 0; i < slice_num; i++) { |
| 200 | TF_RETURN_IF_ERROR(ctx->allocate_temp(DT_STRING, TensorShape({}), &data_t)); |
| 201 | uint64 start = i * slice_size_; |
| 202 | uint64 copy_size = slice_size_; |
| 203 | if (start > element_bytes - slice_size_) { |
| 204 | copy_size = element_bytes - start; |
| 205 | } |
| 206 | TF_RETURN_IF_ERROR(ReadFileSlice(file, start, copy_size, data_t)); |
| 207 | std::string tensor_name_suffix = \ |
| 208 | strings::StrCat("_slice_transfer_data_", std::to_string(0), "_", |
| 209 | std::to_string(i)); |
| 210 | slice_sendrecv::GetSliceRendezvousKey(key_prefix_, tensor_name_suffix, |
| 211 | frame_iter, &parsed_key.buf_); |
| 212 | VLOG(2) << "FileSliceSend " << parsed_key.buf_; |
| 213 | TF_RETURN_IF_ERROR(Rendezvous::ParseKey(parsed_key.buf_, &parsed_key)); |
| 214 | TF_RETURN_IF_ERROR( |
| 215 | ctx->rendezvous()->FlowControlSend(tensor_name_, parsed_key, args, data_t, |
| 216 | ctx->is_input_dead())); |
| 217 | } |
| 218 | |
| 219 | |
| 220 | return Status::OK(); |
| 221 | } |
| 222 | |
| 223 | Status FileSliceSendOp::ReadFileSlice( |
| 224 | const std::unique_ptr<RandomAccessFile>& file, |
nothing calls this directly
no test coverage detected