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

Method AllocateRaw

tensorflow/core/framework/tracking_allocator.cc:32–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30 next_allocation_id_(0) {}
31
32void* TrackingAllocator::AllocateRaw(
33 size_t alignment, size_t num_bytes,
34 const AllocationAttributes& allocation_attr) {
35 void* ptr = allocator_->AllocateRaw(alignment, num_bytes, allocation_attr);
36 // If memory is exhausted AllocateRaw returns nullptr, and we should
37 // pass this through to the caller
38 if (nullptr == ptr) {
39 return ptr;
40 }
41 if (allocator_->TracksAllocationSizes()) {
42 size_t allocated_bytes = allocator_->AllocatedSize(ptr);
43 {
44 mutex_lock lock(mu_);
45 allocated_ += allocated_bytes;
46 high_watermark_ = std::max(high_watermark_, allocated_);
47 total_bytes_ += allocated_bytes;
48 allocations_.emplace_back(allocated_bytes, Env::Default()->NowMicros());
49 ++ref_;
50 }
51 } else if (track_sizes_locally_) {
52 // Call the underlying allocator to try to get the allocated size
53 // whenever possible, even when it might be slow. If this fails,
54 // use the requested size as an approximation.
55 size_t allocated_bytes = allocator_->AllocatedSizeSlow(ptr);
56 allocated_bytes = std::max(num_bytes, allocated_bytes);
57 mutex_lock lock(mu_);
58 next_allocation_id_ += 1;
59 Chunk chunk = {num_bytes, allocated_bytes, next_allocation_id_};
60 in_use_.emplace(std::make_pair(ptr, chunk));
61 allocated_ += allocated_bytes;
62 high_watermark_ = std::max(high_watermark_, allocated_);
63 total_bytes_ += allocated_bytes;
64 allocations_.emplace_back(allocated_bytes, Env::Default()->NowMicros());
65 ++ref_;
66 } else {
67 mutex_lock lock(mu_);
68 total_bytes_ += num_bytes;
69 allocations_.emplace_back(num_bytes, Env::Default()->NowMicros());
70 ++ref_;
71 }
72 return ptr;
73}
74
75size_t TrackingAllocator::BatchAllocateRaw(size_t num, size_t alignment,
76 size_t num_bytes, void** ret) {

Callers

nothing calls this directly

Calls 8

DefaultFunction · 0.85
maxFunction · 0.50
TracksAllocationSizesMethod · 0.45
AllocatedSizeMethod · 0.45
emplace_backMethod · 0.45
NowMicrosMethod · 0.45
AllocatedSizeSlowMethod · 0.45
emplaceMethod · 0.45

Tested by

no test coverage detected