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

Method BundleReader

tensorflow/core/util/tensor_bundle/tensor_bundle.cc:891–933  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

889// Interface for reading a tensor bundle.
890
891BundleReader::BundleReader(Env* env, StringPiece prefix)
892 : env_(env),
893 prefix_(prefix),
894 metadata_(nullptr),
895 table_(nullptr),
896 iter_(nullptr),
897 need_to_swap_bytes_(false) {
898 const string filename = MetaFilename(prefix_);
899 uint64 file_size;
900 status_ = env_->GetFileSize(filename, &file_size);
901 if (!status_.ok()) return;
902
903 // Opens the metadata table.
904 std::unique_ptr<RandomAccessFile> wrapper;
905 status_ = env_->NewRandomAccessFile(filename, &wrapper);
906 if (!status_.ok()) return;
907 metadata_ = wrapper.release();
908 status_ = table::Table::Open(table::Options(), metadata_, file_size, &table_);
909 if (!status_.ok()) return;
910 iter_ = table_->NewIterator();
911
912 // Reads "num_shards_" from the first entry.
913 iter_->Seek(kHeaderEntryKey);
914 if (!iter_->Valid()) {
915 status_ = CorruptFileError(iter_->status(), filename,
916 "failed to seek to header entry");
917 return;
918 }
919 BundleHeaderProto header;
920 status_ = ParseEntryProto(iter_->key(), iter_->value(), &header);
921 if (!status_.ok()) {
922 status_ = CorruptFileError(status_, filename, "unable to parse header");
923 return;
924 }
925 num_shards_ = header.num_shards();
926 if ((header.endianness() == BundleHeaderProto::BIG && port::kLittleEndian) ||
927 (header.endianness() == BundleHeaderProto::LITTLE &&
928 !port::kLittleEndian)) {
929 need_to_swap_bytes_ = true;
930 }
931 status_ = CheckVersions(header.version(), kTensorBundleVersion,
932 kTensorBundleMinProducer, "Checkpoint", "checkpoint");
933}
934
935BundleReader::~BundleReader() {
936 delete metadata_;

Callers

nothing calls this directly

Calls 15

MetaFilenameFunction · 0.85
CorruptFileErrorFunction · 0.85
ParseEntryProtoFunction · 0.85
CheckVersionsFunction · 0.85
OptionsClass · 0.70
GetFileSizeMethod · 0.45
okMethod · 0.45
NewRandomAccessFileMethod · 0.45
releaseMethod · 0.45
NewIteratorMethod · 0.45
SeekMethod · 0.45
ValidMethod · 0.45

Tested by

no test coverage detected