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

Method Append

tensorflow/core/util/tensor_bundle/tensor_bundle.cc:1380–1408  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1378FileOutputBuffer::~FileOutputBuffer() { delete file_; }
1379
1380Status FileOutputBuffer::Append(StringPiece data) {
1381 // In the below, it is critical to calculate the checksum on the actually
1382 // copied bytes, not the source bytes. This is because "data" typically
1383 // points to tensor buffers, which may be concurrently written.
1384 if (data.size() + position_ <= buffer_size_) {
1385 // Can fit into the current buffer.
1386 memcpy(&buffer_[position_], data.data(), data.size());
1387 crc32c_ = crc32c::Extend(crc32c_, &buffer_[position_], data.size());
1388 } else if (data.size() <= buffer_size_) {
1389 // Cannot fit, but can fit after flushing.
1390 TF_RETURN_IF_ERROR(FlushBuffer());
1391 memcpy(&buffer_[0], data.data(), data.size());
1392 crc32c_ = crc32c::Extend(crc32c_, &buffer_[0], data.size());
1393 } else {
1394 // Cannot fit even after flushing. So we break down "data" by chunk, and
1395 // flush/checksum each chunk.
1396 TF_RETURN_IF_ERROR(FlushBuffer());
1397 for (size_t i = 0; i < data.size(); i += buffer_size_) {
1398 const size_t nbytes = std::min(data.size() - i, buffer_size_);
1399 memcpy(&buffer_[0], data.data() + i, nbytes);
1400 crc32c_ = crc32c::Extend(crc32c_, &buffer_[0], nbytes);
1401 position_ = nbytes;
1402 TF_RETURN_IF_ERROR(FlushBuffer());
1403 }
1404 return Status::OK();
1405 }
1406 position_ += data.size();
1407 return Status::OK();
1408}
1409
1410Status FileOutputBuffer::AppendSegment(StringPiece data) {
1411 TF_RETURN_IF_ERROR(FlushBuffer());

Callers 6

WriteTensorFunction · 0.45
WriteStringTensorFunction · 0.45
WriteVariantTensorFunction · 0.45
PadAlignmentFunction · 0.45
AddCompeleteDataMethod · 0.45
FlushBufferMethod · 0.45

Calls 4

ExtendFunction · 0.85
minFunction · 0.50
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected