| 486 | } |
| 487 | |
| 488 | Status InsertTable( |
| 489 | BundleReader* reader, HashTable* table, |
| 490 | const std::vector<TensibleVariable*>& tensibles, |
| 491 | const string& table_name, const std::vector<string>& tensibles_name, |
| 492 | const std::vector<TensorSliceProto>& table_slices, |
| 493 | const std::vector<std::vector<TensorSliceProto>>& tensible_slices, |
| 494 | const RestoreHashTableSlice& slice, mutex* mu, |
| 495 | int64 slice_beg, int64 slice_length, int64 slice_size, |
| 496 | const std::function<void(int64*,size_t)>& revise_fn = nullptr) { |
| 497 | std::unique_ptr<SegmentBundleReader> table_bundle_reader; |
| 498 | std::vector<std::unique_ptr<SegmentBundleReader>> tensible_bundle_readers; |
| 499 | { |
| 500 | mutex_lock lock(*mu); |
| 501 | string xname = checkpoint::EncodeTensorNameSlice( |
| 502 | table_name, TensorSlice(table_slices[slice.slice_id])); |
| 503 | table_bundle_reader.reset(new SegmentBundleReader( |
| 504 | reader, xname, slice.beg, slice.len)); |
| 505 | TF_RETURN_IF_ERROR(table_bundle_reader->Begin()); |
| 506 | |
| 507 | for (size_t j = 0; j < tensibles.size(); j++) { |
| 508 | if (tensible_slices[j].empty()) { |
| 509 | tensible_bundle_readers.emplace_back(nullptr); |
| 510 | continue; |
| 511 | } |
| 512 | string xname = checkpoint::EncodeTensorNameSlice( |
| 513 | tensibles_name[j], TensorSlice(tensible_slices[j][slice.slice_id])); |
| 514 | tensible_bundle_readers.emplace_back(new SegmentBundleReader( |
| 515 | reader, xname, slice.beg, slice.len)); |
| 516 | TF_RETURN_IF_ERROR(tensible_bundle_readers.back()->Begin()); |
| 517 | } |
| 518 | } |
| 519 | int64 id_size = slice.len; |
| 520 | constexpr int64 kSlice = 1 << 15; |
| 521 | int64 slice_end = slice_beg + slice_length; |
| 522 | while (id_size > 0) { |
| 523 | int64 xid = std::min(id_size, kSlice); |
| 524 | id_size -= xid; |
| 525 | int64 key[kSlice]; |
| 526 | TF_RETURN_IF_ERROR(table_bundle_reader->Read(key, xid * sizeof(int64))); |
| 527 | if (revise_fn) { |
| 528 | revise_fn(key, xid); |
| 529 | } |
| 530 | std::vector<int64> real_key, real_id, real_offset; |
| 531 | for (int j = 0; j < xid; j++) { |
| 532 | int64 slice_idx = (uint64_t)(key[j]) % (uint64_t)(slice_size); |
| 533 | if (slice_beg <= slice_idx && slice_idx < slice_end) { |
| 534 | real_key.push_back(key[j]); |
| 535 | real_offset.push_back(j); |
| 536 | } |
| 537 | } |
| 538 | real_id.resize(real_key.size()); |
| 539 | int64 size = table->GetIdsWithoutResize( |
| 540 | &real_key[0], &real_id[0], real_key.size()); |
| 541 | for (size_t j = 0; j < tensibles.size(); j++) { |
| 542 | tensibles[j]->ZeroCostResize(size); |
| 543 | } |
| 544 | real_offset.push_back(-1); |
| 545 | int64 idx = 0; |
nothing calls this directly
no test coverage detected