Skip to content

Commit 51c49ac

Browse files
committed
handle merge conflict.
1 parent 3c87d9e commit 51c49ac

File tree

10 files changed

+16
-854
lines changed

10 files changed

+16
-854
lines changed

paddle/fluid/memory/allocation/naive_best_fit_allocator.cc

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ void Free(const Place &place, void *p, size_t size);
6363
template <typename Place>
6464
uint64_t Release(const Place &place);
6565

66-
template <typename Place>
67-
void *BasePtr(const Place &place, void *p);
68-
6966
template <typename Place>
7067
size_t Used(const Place &place);
7168

@@ -117,11 +114,6 @@ uint64_t Release<platform::CPUPlace>(const platform::CPUPlace &place) {
117114
return GetCPUBuddyAllocator()->Release();
118115
}
119116

120-
template <>
121-
void *BasePtr<platform::CPUPlace>(const platform::CPUPlace &place, void *p) {
122-
return GetCPUBuddyAllocator()->BasePtr(p);
123-
}
124-
125117
template <>
126118
size_t Used<platform::CPUPlace>(const platform::CPUPlace &place) {
127119
return GetCPUBuddyAllocator()->Used();
@@ -140,24 +132,16 @@ void *Alloc<platform::IPUPlace>(const platform::IPUPlace &place, size_t size) {
140132
VLOG(10) << " pointer=" << p;
141133
return p;
142134
}
143-
144135
template <>
145136
void Free<platform::IPUPlace>(const platform::IPUPlace &place, void *p,
146137
size_t size) {
147138
VLOG(10) << "Free pointer=" << p << " on " << platform::Place(place);
148139
GetCPUBuddyAllocator()->Free(p);
149140
}
150-
151141
template <>
152142
uint64_t Release<platform::IPUPlace>(const platform::IPUPlace &place) {
153143
return GetCPUBuddyAllocator()->Release();
154144
}
155-
156-
template <>
157-
void *BasePtr<platform::IPUPlace>(const platform::IPUPlace &place, void *p) {
158-
return GetCPUBuddyAllocator()->BasePtr(p);
159-
}
160-
161145
template <>
162146
size_t Used<platform::IPUPlace>(const platform::IPUPlace &place) {
163147
return GetCPUBuddyAllocator()->Used();
@@ -262,11 +246,6 @@ uint64_t Release<platform::XPUPlace>(const platform::XPUPlace &place) {
262246
return -1;
263247
}
264248

265-
template <>
266-
void *BasePtr<platform::XPUPlace>(const platform::XPUPlace &place, void *p) {
267-
return p;
268-
}
269-
270249
template <>
271250
size_t Used<platform::XPUPlace>(const platform::XPUPlace &place) {
272251
#ifdef PADDLE_WITH_XPU
@@ -423,16 +402,6 @@ uint64_t Release<platform::NPUPlace>(const platform::NPUPlace &place) {
423402
#endif
424403
}
425404

426-
template <>
427-
void *BasePtr<platform::NPUPlace>(const platform::NPUPlace &place, void *p) {
428-
#ifdef PADDLE_WITH_ASCEND_CL
429-
return GetNPUBuddyAllocator(place.device)->BasePtr(p);
430-
#else
431-
PADDLE_THROW(platform::errors::PermissionDenied(
432-
"'NPUPlace' is not supported in CPU only device."));
433-
#endif
434-
}
435-
436405
template <>
437406
size_t Used<platform::NPUPinnedPlace>(const platform::NPUPinnedPlace &place) {
438407
#ifdef PADDLE_WITH_ASCEND_CL
@@ -485,17 +454,6 @@ uint64_t Release<platform::NPUPinnedPlace>(
485454
#endif
486455
}
487456

488-
template <>
489-
void *BasePtr<platform::NPUPinnedPlace>(const platform::NPUPinnedPlace &place,
490-
void *p) {
491-
#ifdef PADDLE_WITH_ASCEND_CL
492-
return GetNPUPinnedBuddyAllocator()->BasePtr(p);
493-
#else
494-
PADDLE_THROW(platform::errors::PermissionDenied(
495-
"'NPUPPinnedPlace' is not supported in CPU only device."));
496-
#endif
497-
}
498-
499457
// For CUDA
500458
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
501459
class GPUBuddyAllocatorList {
@@ -627,16 +585,6 @@ uint64_t Release<platform::CUDAPlace>(const platform::CUDAPlace &place) {
627585
#endif
628586
}
629587

630-
template <>
631-
void *BasePtr<platform::CUDAPlace>(const platform::CUDAPlace &place, void *p) {
632-
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
633-
return GetGPUBuddyAllocator(place.device)->BasePtr(p);
634-
#else
635-
PADDLE_THROW(platform::errors::PermissionDenied(
636-
"'CUDAPlace' is not supported in CPU only device."));
637-
#endif
638-
}
639-
640588
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
641589
BuddyAllocator *GetCUDAPinnedBuddyAllocator() {
642590
static std::once_flag init_flag;
@@ -867,18 +815,6 @@ struct ReleaseVisitor : public boost::static_visitor<uint64_t> {
867815
}
868816
};
869817

870-
struct BasePtrVisitor : public boost::static_visitor<void *> {
871-
inline explicit BasePtrVisitor(void *ptr) : ptr_(ptr) {}
872-
873-
template <typename Place>
874-
inline void *operator()(const Place &place) const {
875-
return BasePtr<Place>(place, ptr_);
876-
}
877-
878-
private:
879-
void *ptr_;
880-
};
881-
882818
size_t Usage::operator()(const platform::CPUPlace &cpu) const {
883819
return Used(cpu);
884820
}
@@ -906,8 +842,7 @@ namespace allocation {
906842

907843
Allocation *NaiveBestFitAllocator::AllocateImpl(size_t size) {
908844
void *ptr = boost::apply_visitor(legacy::AllocVisitor(size), place_);
909-
void *base_ptr = boost::apply_visitor(legacy::BasePtrVisitor(ptr), place_);
910-
auto *tmp_alloc = new Allocation(ptr, base_ptr, size, place_);
845+
auto *tmp_alloc = new Allocation(ptr, size, place_);
911846
platform::MemEvenRecorder::Instance().PushMemRecord(
912847
static_cast<void *>(tmp_alloc), place_, size);
913848
return tmp_alloc;

paddle/fluid/memory/allocation/thread_local_allocator.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ ThreadLocalCUDAAllocatorPool::ThreadLocalCUDAAllocatorPool()
6161
ThreadLocalAllocation* ThreadLocalAllocatorImpl::AllocateImpl(size_t size) {
6262
VLOG(10) << "ThreadLocalAllocatorImpl::AllocateImpl " << size;
6363
void* ptr = buddy_allocator_->Alloc(size);
64-
void* base_ptr = buddy_allocator_->BasePtr(ptr);
65-
auto* tl_allocation = new ThreadLocalAllocation(ptr, base_ptr, size, place_);
64+
auto* tl_allocation = new ThreadLocalAllocation(ptr, size, place_);
6665
tl_allocation->SetThreadLocalAllocatorImpl(shared_from_this());
6766
return tl_allocation;
6867
}

paddle/fluid/memory/allocation/thread_local_allocator.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ class ThreadLocalAllocatorImpl;
3030

3131
class ThreadLocalAllocation : public Allocation {
3232
public:
33-
ThreadLocalAllocation(void* ptr, void* base_ptr, size_t size,
34-
platform::Place place)
35-
: Allocation(ptr, base_ptr, size, place) {}
33+
ThreadLocalAllocation(void* ptr, size_t size, platform::Place place)
34+
: Allocation(ptr, size, place) {}
3635

3736
void SetThreadLocalAllocatorImpl(
3837
std::shared_ptr<ThreadLocalAllocatorImpl> allocator) {

paddle/fluid/memory/detail/buddy_allocator.cc

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,6 @@ uint64_t BuddyAllocator::Release() {
210210
return bytes;
211211
}
212212

213-
void* BuddyAllocator::BasePtr(void* ptr) {
214-
MemoryBlock* block = static_cast<MemoryBlock*>(ptr)->Metadata();
215-
216-
std::lock_guard<std::mutex> lock(mutex_);
217-
return block->BasePtr(&cache_);
218-
}
219-
220213
size_t BuddyAllocator::Used() { return total_used_; }
221214
size_t BuddyAllocator::GetMinChunkSize() { return min_chunk_size_; }
222215
size_t BuddyAllocator::GetMaxChunkSize() { return max_chunk_size_; }
@@ -230,7 +223,7 @@ void* BuddyAllocator::SystemAlloc(size_t size) {
230223
if (p == nullptr) return nullptr;
231224

232225
static_cast<MemoryBlock*>(p)->Init(&cache_, MemoryBlock::HUGE_CHUNK, index,
233-
size, p, nullptr, nullptr);
226+
size, nullptr, nullptr);
234227

235228
return static_cast<MemoryBlock*>(p)->Data();
236229
}
@@ -295,7 +288,7 @@ BuddyAllocator::PoolSet::iterator BuddyAllocator::RefillPool(
295288
<< " from system allocator";
296289

297290
static_cast<MemoryBlock*>(p)->Init(&cache_, MemoryBlock::FREE_CHUNK, index,
298-
allocate_bytes, p, nullptr, nullptr);
291+
allocate_bytes, nullptr, nullptr);
299292

300293
total_free_ += allocate_bytes;
301294

paddle/fluid/memory/detail/buddy_allocator.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class BuddyAllocator {
4545
void Free(void* ptr);
4646
// Release the unused memory pool, a real free operation for the OS.
4747
uint64_t Release();
48-
void* BasePtr(void* ptr);
4948
size_t Used();
5049
size_t GetMinChunkSize();
5150
size_t GetMaxChunkSize();

paddle/fluid/memory/detail/memory_block.cc

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ namespace memory {
2121
namespace detail {
2222

2323
void MemoryBlock::Init(MetadataCache* cache, Type t, size_t index, size_t size,
24-
void* base_ptr, void* left_buddy, void* right_buddy) {
24+
void* left_buddy, void* right_buddy) {
2525
cache->Save(
2626
this, MemoryBlock::Desc(t, index, size - sizeof(MemoryBlock::Desc), size,
27-
base_ptr, static_cast<MemoryBlock*>(left_buddy),
27+
static_cast<MemoryBlock*>(left_buddy),
2828
static_cast<MemoryBlock*>(right_buddy)));
2929
}
3030

@@ -58,13 +58,11 @@ void MemoryBlock::Split(MetadataCache* cache, size_t size) {
5858
// Add the new block as a buddy
5959
// Write the metadata for the new block
6060
auto new_block_right_buddy = desc->right_buddy;
61-
void* new_block_base_ptr = desc->base_ptr;
6261

6362
cache->Save(static_cast<MemoryBlock*>(right_partition),
6463
MemoryBlock::Desc(FREE_CHUNK, desc->index,
6564
remaining_size - sizeof(MemoryBlock::Desc),
66-
remaining_size, new_block_base_ptr, this,
67-
new_block_right_buddy));
65+
remaining_size, this, new_block_right_buddy));
6866

6967
desc->right_buddy = static_cast<MemoryBlock*>(right_partition);
7068
desc->size = size - sizeof(MemoryBlock::Desc);
@@ -98,6 +96,7 @@ void MemoryBlock::Merge(MetadataCache* cache, MemoryBlock* right_buddy) {
9896
// link buddy's buddy -> this
9997
if (desc->right_buddy != nullptr) {
10098
auto buddy_metadata = cache->LoadDesc(desc->right_buddy);
99+
101100
buddy_metadata->left_buddy = this;
102101
buddy_metadata->UpdateGuards();
103102
}
@@ -107,8 +106,8 @@ void MemoryBlock::Merge(MetadataCache* cache, MemoryBlock* right_buddy) {
107106

108107
desc->UpdateGuards();
109108

110-
cache->Save(right_buddy, MemoryBlock::Desc(INVALID_CHUNK, 0, 0, 0, nullptr,
111-
nullptr, nullptr));
109+
cache->Save(right_buddy,
110+
MemoryBlock::Desc(INVALID_CHUNK, 0, 0, 0, nullptr, nullptr));
112111
}
113112

114113
void MemoryBlock::MarkAsFree(MetadataCache* cache) {
@@ -124,10 +123,6 @@ void MemoryBlock::MarkAsFree(MetadataCache* cache) {
124123
desc->UpdateGuards();
125124
}
126125

127-
void* MemoryBlock::BasePtr(MetadataCache* cache) {
128-
return cache->LoadDesc(this)->base_ptr;
129-
}
130-
131126
void* MemoryBlock::Data() const {
132127
return const_cast<MemoryBlock::Desc*>(
133128
reinterpret_cast<const MemoryBlock::Desc*>(this)) +

paddle/fluid/memory/detail/memory_block.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct MemoryBlock {
3939
// block, the MetadataCache writes the Meatadata to a std::map in
4040
// the CPU.
4141
void Init(MetadataCache* cache, Type t, size_t index, size_t size,
42-
void* base_ptr, void* left_buddy, void* right_buddy);
42+
void* left_buddy, void* right_buddy);
4343

4444
MemoryBlock* GetLeftBuddy(MetadataCache* cache);
4545
MemoryBlock* GetRightBuddy(MetadataCache* cache);
@@ -53,15 +53,13 @@ struct MemoryBlock {
5353
// Mark the allocation as free.
5454
void MarkAsFree(MetadataCache* cache);
5555

56-
void* BasePtr(MetadataCache* cache);
57-
5856
void* Data() const;
5957
MemoryBlock* Metadata() const;
6058

6159
// MemoryBlock::Desc describes a MemoryBlock.
6260
struct Desc {
63-
Desc(MemoryBlock::Type t, size_t i, size_t s, size_t ts, void* bp,
64-
MemoryBlock* l, MemoryBlock* r);
61+
Desc(MemoryBlock::Type t, size_t i, size_t s, size_t ts, MemoryBlock* l,
62+
MemoryBlock* r);
6563
Desc();
6664

6765
// mutator for type
@@ -82,9 +80,6 @@ struct MemoryBlock {
8280
// accessor for total_size
8381
inline const size_t& get_total_size() const { return this->total_size; }
8482

85-
// accessor for bast_ptr
86-
inline const void* get_base_ptr() const { return this->base_ptr; }
87-
8883
// Updates guard_begin and guard_end by hashes of the Metadata object.
8984
void UpdateGuards();
9085

@@ -97,7 +92,6 @@ struct MemoryBlock {
9792
size_t index = 0;
9893
size_t size = 0;
9994
size_t total_size = 0;
100-
void* base_ptr = nullptr;
10195
MemoryBlock* left_buddy = nullptr;
10296
MemoryBlock* right_buddy = nullptr;
10397
size_t guard_end = 0;

paddle/fluid/memory/detail/memory_block_desc.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ namespace memory {
2222
namespace detail {
2323

2424
MemoryBlock::Desc::Desc(MemoryBlock::Type t, size_t i, size_t s, size_t ts,
25-
void* bp, MemoryBlock* l, MemoryBlock* r)
25+
MemoryBlock* l, MemoryBlock* r)
2626
: type(t),
2727
index(i),
2828
size(s),
2929
total_size(ts),
30-
base_ptr(bp),
3130
left_buddy(l),
3231
right_buddy(r) {}
3332

@@ -36,7 +35,6 @@ MemoryBlock::Desc::Desc()
3635
index(0),
3736
size(0),
3837
total_size(0),
39-
base_ptr(nullptr),
4038
left_buddy(nullptr),
4139
right_buddy(nullptr) {}
4240

paddle/fluid/platform/device/gpu/gpu_info.cc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,18 +244,6 @@ class RecordedGpuMallocHelper {
244244
#endif
245245
}
246246

247-
#ifdef PADDLE_WITH_TESTING
248-
void *GetBasePtr(void *ptr) {
249-
auto it = gpu_ptrs.upper_bound(ptr);
250-
251-
if (it == gpu_ptrs.begin()) {
252-
return nullptr;
253-
}
254-
255-
return *(--it);
256-
}
257-
#endif
258-
259247
#ifdef PADDLE_WITH_TESTING
260248
void *GetBasePtr(void *ptr) {
261249
auto it = gpu_ptrs.upper_bound(ptr);

0 commit comments

Comments
 (0)