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

Class SeriesWriter

tensorflow/core/summary/summary_db_writer.cc:626–818  ·  view source on GitHub ↗

\brief Tensor writer for a single series, e.g. Tag. This class is thread safe.

Source from the content-addressed store, hash-verified

624///
625/// This class is thread safe.
626class SeriesWriter {
627 public:
628 SeriesWriter(int64 series, RunMetadata* meta) : series_{series}, meta_{meta} {
629 DCHECK(series_ > 0);
630 }
631
632 Status Append(Sqlite* db, int64 step, uint64 now, double computed_time,
633 const Tensor& t) SQLITE_TRANSACTIONS_EXCLUDED(*db)
634 LOCKS_EXCLUDED(mu_) {
635 mutex_lock lock(mu_);
636 if (rowids_.empty()) {
637 Status s = Reserve(db, t);
638 if (!s.ok()) {
639 rowids_.clear();
640 return s;
641 }
642 }
643 int64 rowid = rowids_.front();
644 Status s = Write(db, rowid, step, computed_time, t);
645 if (s.ok()) {
646 ++count_;
647 }
648 rowids_.pop_front();
649 return s;
650 }
651
652 Status Finish(Sqlite* db) SQLITE_TRANSACTIONS_EXCLUDED(*db)
653 LOCKS_EXCLUDED(mu_) {
654 mutex_lock lock(mu_);
655 // Delete unused pre-allocated Tensors.
656 if (!rowids_.empty()) {
657 SqliteTransaction txn(*db);
658 const char* sql = R"sql(
659 DELETE FROM Tensors WHERE rowid = ?
660 )sql";
661 SqliteStatement deleter;
662 TF_RETURN_IF_ERROR(db->Prepare(sql, &deleter));
663 for (size_t i = count_; i < rowids_.size(); ++i) {
664 deleter.BindInt(1, rowids_.front());
665 TF_RETURN_IF_ERROR(deleter.StepAndReset());
666 rowids_.pop_front();
667 }
668 TF_RETURN_IF_ERROR(txn.Commit());
669 rowids_.clear();
670 }
671 return Status::OK();
672 }
673
674 private:
675 Status Write(Sqlite* db, int64 rowid, int64 step, double computed_time,
676 const Tensor& t) SQLITE_TRANSACTIONS_EXCLUDED(*db) {
677 if (t.dtype() == DT_STRING) {
678 if (t.dims() == 0) {
679 return Update(db, step, computed_time, t, t.scalar<tstring>()(), rowid);
680 } else {
681 SqliteTransaction txn(*db);
682 TF_RETURN_IF_ERROR(
683 Update(db, step, computed_time, t, StringPiece(), rowid));

Callers

nothing calls this directly

Calls 10

UpdateFunction · 0.85
tensor_dataMethod · 0.80
BindIntMethod · 0.80
StepAndResetMethod · 0.80
BindBlobUnsafeMethod · 0.80
dtypeMethod · 0.45
dimsMethod · 0.45
CommitMethod · 0.45
PrepareMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected