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

Method Resize

tensorflow/core/framework/hash_table/tensible_variable.cc:45–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45void TensibleVariable::Resize(
46 int64 size, const std::function<void(Status)>& done) {
47 if (size <= size_) {
48 done(Status::OK());
49 return;
50 }
51 int64_t segment_count = (size - size_ - 1) / segment_size_ + 1;
52 StatusCollector* stc = new StatusCollector(segment_count, [this, done](Status st) {
53 if (st.ok()) {
54 ptrs_ = all_ptr_vec_.back().ptr.get();
55 size_ = tensors_.size() * segment_size_;
56 }
57 done(st);
58 });
59 for (int i = 0; i < segment_count; i++) {
60 generator_->GetNextTensor([this, stc] (Status st, const Tensor& tensor) {
61 auto fn = [&]() -> Status {
62 mutex_lock lock(structure_update_mu_);
63 if (!st.ok()) {
64 return st;
65 }
66 if (tensor.shape() != shape_) {
67 return errors::InvalidArgument(
68 "Tensor Generator generate shape error ",
69 tensor.shape().DebugString(), " vs ", shape_.DebugString());
70 }
71 if (tensor.dtype() != dtype_) {
72 return errors::InvalidArgument(
73 "Tensor Generator generate dtype error ",
74 tensor.dtype(), " vs ", dtype_);
75 }
76 tensors_.push_back(tensor);
77 if (all_ptr_vec_.back().size < tensors_.size()) {
78 all_ptr_vec_.emplace_back();
79 auto&& old_spec = all_ptr_vec_[all_ptr_vec_.size() - 2];
80 auto&& new_spec = all_ptr_vec_[all_ptr_vec_.size() - 1];
81 new_spec.size = old_spec.size * 2;
82 new_spec.ptr.reset(new char*[new_spec.size]);
83 memcpy(new_spec.ptr.get(), old_spec.ptr.get(),
84 old_spec.size * sizeof(char*));
85 }
86 all_ptr_vec_.back().ptr[tensors_.size() - 1] =
87 const_cast<char*>(tensor.tensor_data().data());
88 return Status::OK();
89 };
90 stc->AddStatus(fn());
91 });
92 }
93 stc->Start();
94}
95
96void TensibleVariable::ZeroCostResize(int64 size) {
97 mutex_lock lock(structure_update_mu_);

Callers

nothing calls this directly

Calls 15

InvalidArgumentFunction · 0.85
GetNextTensorMethod · 0.80
tensor_dataMethod · 0.80
AddStatusMethod · 0.80
fnFunction · 0.50
okMethod · 0.45
getMethod · 0.45
backMethod · 0.45
sizeMethod · 0.45
shapeMethod · 0.45
DebugStringMethod · 0.45
dtypeMethod · 0.45

Tested by

no test coverage detected