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

Method DeallocateRawAsync

tensorflow/core/framework/tracking_allocator.cc:159–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157}
158
159void TrackingAllocator::DeallocateRawAsync(void* ptr) {
160 // freeing a null ptr is a no-op
161 if (nullptr == ptr) {
162 return;
163 }
164 bool should_delete;
165 // fetch the following outside the lock in case the call to
166 // AllocatedSize is slow
167 bool tracks_allocation_sizes = allocator_->TracksAllocationSizes();
168 size_t allocated_bytes = 0;
169 if (tracks_allocation_sizes) {
170 allocated_bytes = allocator_->AllocatedSize(ptr);
171 } else if (track_sizes_locally_) {
172 mutex_lock lock(mu_);
173 auto itr = in_use_.find(ptr);
174 if (itr != in_use_.end()) {
175 tracks_allocation_sizes = true;
176 allocated_bytes = (*itr).second.allocated_size;
177 in_use_.erase(itr);
178 }
179 }
180 Allocator* allocator = allocator_;
181 {
182 mutex_lock lock(mu_);
183 if (tracks_allocation_sizes) {
184 CHECK_GE(allocated_, allocated_bytes);
185 allocated_ -= allocated_bytes;
186 allocations_.emplace_back(-allocated_bytes, Env::Default()->NowMicros());
187 }
188 should_delete = UnRef();
189 }
190 allocator->DeallocateRawAsync(ptr);
191 if (should_delete) {
192 delete this;
193 }
194}
195
196bool TrackingAllocator::TracksAllocationSizes() const {
197 return track_sizes_locally_ || allocator_->TracksAllocationSizes();

Callers

nothing calls this directly

Calls 8

DefaultFunction · 0.85
TracksAllocationSizesMethod · 0.45
AllocatedSizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45
emplace_backMethod · 0.45
NowMicrosMethod · 0.45

Tested by

no test coverage detected