Skip to content

Commit c20db63

Browse files
committed
split PR
test=develop
1 parent c75a880 commit c20db63

22 files changed

+31
-1205
lines changed

paddle/fluid/framework/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ cc_test(cow_ptr_tests SRCS details/cow_ptr_test.cc)
202202

203203
cc_test(tuple_test SRCS tuple_test.cc )
204204

205-
cc_test(inlined_vector_test SRCS inlined_vector_test.cc)
206-
207205
if (NOT WIN32)
208206
cc_test(rw_lock_test SRCS rw_lock_test.cc)
209207
endif (NOT WIN32)

paddle/fluid/framework/inlined_vector.h

Lines changed: 0 additions & 82 deletions
This file was deleted.

paddle/fluid/framework/inlined_vector_test.cc

Lines changed: 0 additions & 53 deletions
This file was deleted.

paddle/fluid/memory/allocation/CMakeLists.txt

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,9 @@ cc_library(cpu_allocator SRCS cpu_allocator.cc DEPS allocator)
33
cc_library(best_fit_allocator SRCS best_fit_allocator.cc DEPS allocator)
44
cc_library(locked_allocator SRCS locked_allocator.cc DEPS allocator)
55
cc_library(buffered_allocator SRCS buffered_allocator.cc DEPS allocator)
6-
cc_library(multi_bin_buffered_allocator SRCS multi_bin_buffered_allocator.cc DEPS allocator gflags)
76
cc_library(legacy_allocator SRCS legacy_allocator.cc DEPS allocator buddy_allocator profiler)
87
cc_library(zero_size_allocator SRCS zero_size_allocator.cc DEPS allocator)
98
cc_test(buffered_allocator_test SRCS buffered_allocator_test.cc DEPS best_fit_allocator locked_allocator buffered_allocator cpu_allocator)
10-
cc_test(multi_bin_buffered_allocator_test SRCS multi_bin_buffered_allocator_test.cc DEPS best_fit_allocator locked_allocator multi_bin_buffered_allocator cpu_allocator)
11-
12-
cc_library(auto_growth_best_fit_allocator SRCS auto_growth_best_fit_allocator.cc DEPS allocator)
13-
cc_test(auto_growth_best_fit_allocator_test SRCS auto_growth_best_fit_allocator_test.cc DEPS cpu_allocator auto_growth_best_fit_allocator)
14-
15-
if (NOT WIN32)
16-
cc_test(test_multi_bin_buffered_allocator_division_plan SRCS test_multi_bin_buffered_allocator_division_plan.cc DEPS multi_bin_buffered_allocator)
17-
endif()
189

1910
if (WITH_GPU)
2011
nv_library(cuda_allocator SRCS cuda_allocator.cc DEPS allocator cuda_device_guard)
@@ -47,7 +38,7 @@ else ()
4738
set(AllocatorFacadeDeps)
4839
endif()
4940

50-
list(APPEND AllocatorFacadeDeps cpu_allocator locked_allocator best_fit_allocator aligned_allocator auto_increment_allocator conditional_allocator retry_allocator buffered_allocator multi_bin_buffered_allocator auto_growth_best_fit_allocator legacy_allocator zero_size_allocator)
41+
list(APPEND AllocatorFacadeDeps cpu_allocator locked_allocator best_fit_allocator aligned_allocator auto_increment_allocator conditional_allocator retry_allocator buffered_allocator legacy_allocator zero_size_allocator)
5142

5243
cc_library(aligned_allocator SRCS aligned_allocator.cc DEPS allocator)
5344
cc_library(auto_increment_allocator SRCS auto_increment_allocator.cc DEPS allocator)
@@ -59,8 +50,8 @@ nv_test(allocation_and_eigen_test SRCS allocation_and_eigen_test.cu DEPS allocat
5950

6051
cc_test(retry_allocator_test SRCS retry_allocator_test.cc DEPS retry_allocator best_fit_allocator locked_allocator cpu_allocator)
6152

62-
cc_test(allocator_facade_test SRCS allocator_facade_test.cc DEPS allocator_facade)
63-
6453
cc_test(naive_best_fit_allocator_facade_test SRCS naive_best_fit_allocator_facade_test.cc DEPS allocator_facade)
6554

66-
cc_test(auto_growth_best_fit_allocator_facade_test SRCS auto_growth_best_fit_allocator_facade_test.cc DEPS allocator_facade)
55+
cc_test(allocator_facade_abs_flags_test SRCS allocator_facade_abs_flags_test.cc DEPS allocator_facade)
56+
57+
cc_test(allocator_facade_frac_flags_test SRCS allocator_facade_frac_flags_test.cc DEPS allocator_facade)

paddle/fluid/memory/allocation/allocator.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <string>
1818
#include <utility>
1919
#include <vector>
20-
#include "paddle/fluid/framework/inlined_vector.h"
2120
#include "paddle/fluid/platform/place.h"
2221

2322
namespace paddle {
@@ -50,7 +49,9 @@ class Allocator;
5049
class Allocation {
5150
public:
5251
Allocation(void* ptr, size_t size, platform::Place place)
53-
: ptr_(ptr), size_(size), place_(place) {}
52+
: ptr_(ptr), size_(size), place_(place) {
53+
decorated_allocators_.reserve(8);
54+
}
5455

5556
Allocation(const Allocation& o) = delete;
5657
Allocation& operator=(const Allocation& o) = delete;
@@ -80,8 +81,8 @@ class Allocation {
8081
virtual ~Allocation();
8182

8283
private:
83-
std::vector<Allocator*> DecoratedAllocators() const {
84-
return static_cast<std::vector<Allocator*>>(decorated_allocators_);
84+
const std::vector<Allocator*>& DecoratedAllocators() const {
85+
return decorated_allocators_;
8586
}
8687

8788
inline void RegisterDecoratedAllocator(Allocator* allocator) {
@@ -98,7 +99,7 @@ class Allocation {
9899
void* ptr_;
99100
size_t size_;
100101
platform::Place place_;
101-
framework::InlinedVector<Allocator*, 8> decorated_allocators_;
102+
std::vector<Allocator*> decorated_allocators_;
102103

103104
friend class Allocator;
104105
friend class AllocationDeleter;

paddle/fluid/memory/allocation/allocator_facade.cc

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@
2222
#include "paddle/fluid/memory/allocation/aligned_allocator.h"
2323
#include "paddle/fluid/memory/allocation/allocator_facade.h"
2424
#include "paddle/fluid/memory/allocation/allocator_strategy.h"
25-
#include "paddle/fluid/memory/allocation/auto_growth_best_fit_allocator.h"
2625
#include "paddle/fluid/memory/allocation/auto_increment_allocator.h"
2726
#include "paddle/fluid/memory/allocation/best_fit_allocator.h"
2827
#include "paddle/fluid/memory/allocation/conditional_allocator.h"
2928
#include "paddle/fluid/memory/allocation/cpu_allocator.h"
3029
#include "paddle/fluid/memory/allocation/legacy_allocator.h"
3130
#include "paddle/fluid/memory/allocation/locked_allocator.h"
32-
#include "paddle/fluid/memory/allocation/multi_bin_buffered_allocator.h"
3331
#include "paddle/fluid/memory/allocation/retry_allocator.h"
3432
#include "paddle/fluid/memory/allocation/zero_size_allocator.h"
3533
#include "paddle/fluid/platform/cpu_info.h"
@@ -47,24 +45,18 @@ DEFINE_int64(
4745
"The retry time (milliseconds) when allocator fails "
4846
"to allocate memory. No retry if this value is not greater than 0");
4947

50-
DEFINE_bool(enable_buffered_allocator, false, "Enable buffered_allocator");
51-
5248
namespace paddle {
5349
namespace memory {
5450
namespace allocation {
5551

56-
static inline std::shared_ptr<Allocator> WrapRetryAndBufferedAllocator(
57-
std::shared_ptr<Allocator> allocator, int64_t retry_time,
58-
bool enable_buffered) {
52+
static inline std::shared_ptr<Allocator> WrapRetryAllocator(
53+
std::shared_ptr<Allocator> allocator, int64_t retry_time) {
5954
if (retry_time > 0) {
6055
auto* retry_allocator =
6156
new RetryAllocator(std::move(allocator), retry_time);
6257
allocator.reset(retry_allocator);
6358
}
6459

65-
if (enable_buffered) {
66-
allocator.reset(new MultiBinBufferedAllocator(allocator));
67-
}
6860
return allocator;
6961
}
7062

@@ -134,8 +126,7 @@ class ChunkedAllocator : public Allocator {
134126
std::shared_ptr<Allocator> allocator(new LockedAllocator(
135127
std::shared_ptr<Allocator>(new BestFitAllocator(allocation))));
136128

137-
allocator = WrapRetryAndBufferedAllocator(allocator, retry_time_,
138-
FLAGS_enable_buffered_allocator);
129+
allocator = WrapRetryAllocator(allocator, retry_time_);
139130

140131
return std::make_shared<AlignedAllocator<4096>>(std::move(allocator));
141132
}
@@ -219,13 +210,6 @@ class AllocatorFacadePrivate {
219210
WrapZeroSizeAllocator();
220211
break;
221212
}
222-
case AllocatorStrategy::kAutoGrowthBestFit: {
223-
InitAutoGrowthCPUAllocator();
224-
InitAutoGrowthCUDAAllocator();
225-
InitAutoGrowthCUDAPinnedAllocator();
226-
WrapZeroSizeAllocator();
227-
break;
228-
}
229213
default: {
230214
PADDLE_THROW("Unsupported allocator strategy: %d",
231215
static_cast<int>(strategy));
@@ -234,39 +218,6 @@ class AllocatorFacadePrivate {
234218
}
235219

236220
private:
237-
void InitAutoGrowthCPUAllocator() {
238-
auto cpu_allocator = std::make_shared<AlignedAllocator<4096>>(
239-
std::make_shared<CPUAllocator>());
240-
allocators_[platform::CPUPlace()] =
241-
std::make_shared<AutoGrowthBestFitAllocator>(
242-
cpu_allocator, platform::CpuMaxChunkSize(), 4096);
243-
}
244-
245-
void InitAutoGrowthCUDAAllocator() {
246-
#ifdef PADDLE_WITH_CUDA
247-
int dev_cnt = platform::GetCUDADeviceCount();
248-
for (int dev_id = 0; dev_id < dev_cnt; ++dev_id) {
249-
auto cuda_allocator = std::make_shared<AlignedAllocator<4096>>(
250-
std::make_shared<CUDAAllocator>(platform::CUDAPlace(dev_id)));
251-
auto allocator = std::make_shared<AutoGrowthBestFitAllocator>(
252-
cuda_allocator, platform::GpuMaxChunkSize(), 4096);
253-
254-
allocators_[platform::CUDAPlace(dev_id)] = WrapRetryAndBufferedAllocator(
255-
allocator, FLAGS_gpu_allocator_retry_time, false);
256-
}
257-
#endif
258-
}
259-
260-
void InitAutoGrowthCUDAPinnedAllocator() {
261-
#ifdef PADDLE_WITH_CUDA
262-
auto cuda_pinned_allocator = std::make_shared<AlignedAllocator<4096>>(
263-
std::make_shared<CPUPinnedAllocator>());
264-
allocators_[platform::CUDAPinnedPlace()] =
265-
std::make_shared<AutoGrowthBestFitAllocator>(
266-
cuda_pinned_allocator, platform::CUDAPinnedMaxChunkSize(), 4096);
267-
#endif
268-
}
269-
270221
void InitLegacyAllocator() {
271222
std::vector<platform::Place> places{platform::CPUPlace()};
272223
#ifdef PADDLE_WITH_CUDA

paddle/fluid/memory/allocation/allocator_strategy.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ DEFINE_string(
2020
allocator_strategy, "legacy",
2121
"The allocation strategy. Legacy means the original allocator of Fluid."
2222
"naive_best_fit means the experimental best fit allocator. "
23-
"auto_growth_best_fit means the experimental auto growth best fit "
24-
"allocator. Enum in [legacy, naive_best_fit, auto_growth_best_fit].");
23+
"allocator. Enum in [legacy, naive_best_fit].");
2524

2625
namespace paddle {
2726
namespace memory {
@@ -32,8 +31,6 @@ static AllocatorStrategy GetStrategyFromFlag() {
3231
return AllocatorStrategy::kLegacy;
3332
} else if (FLAGS_allocator_strategy == "naive_best_fit") {
3433
return AllocatorStrategy::kNaiveBestFit;
35-
} else if (FLAGS_allocator_strategy == "auto_growth_best_fit") {
36-
return AllocatorStrategy::kAutoGrowthBestFit;
3734
} else {
3835
PADDLE_THROW("Unsupported allocator strategy: %s",
3936
FLAGS_allocator_strategy);

paddle/fluid/memory/allocation/allocator_strategy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace paddle {
1818
namespace memory {
1919
namespace allocation {
2020

21-
enum class AllocatorStrategy { kLegacy, kNaiveBestFit, kAutoGrowthBestFit };
21+
enum class AllocatorStrategy { kLegacy, kNaiveBestFit };
2222

2323
extern AllocatorStrategy GetAllocatorStrategy();
2424

0 commit comments

Comments
 (0)