From 4537ba23855c63ac1f0127d5364b8b26b481a40f Mon Sep 17 00:00:00 2001 From: Weilong Wu Date: Thu, 22 Dec 2022 16:33:17 +0800 Subject: [PATCH] [eager] use CPUAllocator directly (#47125) * [eager] use CPUAllocator directly * modify pstring sizeof 48 default * rm CPU test for NaiveBestFitAllocator * fix Mac ci compile errors * use UNUSED to state unused_obj * mv UNUSED statement to allocator_facade.cc * fix roi_align * fix yolov3 test case * recover original code * recover original code * fix trt roi_align test Co-authored-by: jerrywgz --- paddle/fluid/memory/allocation/allocator_facade.cc | 9 +++++++-- paddle/phi/common/data_type.h | 2 +- .../tests/unittests/dygraph_to_static/test_yolov3.py | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/paddle/fluid/memory/allocation/allocator_facade.cc b/paddle/fluid/memory/allocation/allocator_facade.cc index 99e6af20bd8..c59e5508a46 100644 --- a/paddle/fluid/memory/allocation/allocator_facade.cc +++ b/paddle/fluid/memory/allocation/allocator_facade.cc @@ -25,6 +25,7 @@ #include "paddle/fluid/memory/allocation/stat_allocator.h" #include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/place.h" +#include "paddle/phi/core/macros.h" #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) #include @@ -493,8 +494,8 @@ class AllocatorFacadePrivate { const AllocatorMap& GetAllocatorMap() { return allocators_; } void InitNaiveBestFitCPUAllocator() { - allocators_[platform::CPUPlace()] = - std::make_shared(platform::CPUPlace()); + // It is more efficient to use CPUAllocator directly. + allocators_[platform::CPUPlace()] = std::make_shared(); } #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) @@ -1197,6 +1198,10 @@ void AllocatorFacade::RemoveMemoryPoolOfCUDAGraph(int64_t id) { } #endif #endif + +UNUSED static std::shared_ptr unused_obj = + std::make_shared(platform::CPUPlace()); + } // namespace allocation } // namespace memory } // namespace paddle diff --git a/paddle/phi/common/data_type.h b/paddle/phi/common/data_type.h index d66c6d89fe6..6cbf0f50d8f 100644 --- a/paddle/phi/common/data_type.h +++ b/paddle/phi/common/data_type.h @@ -98,7 +98,7 @@ inline size_t SizeOf(DataType data_type) { case DataType::COMPLEX128: return 16; case DataType::PSTRING: - return 24; + return 48; case DataType::UNDEFINED: return 0; case DataType::NUM_DATA_TYPES: diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_yolov3.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_yolov3.py index 0da45601ea4..d8e76683916 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_yolov3.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_yolov3.py @@ -56,8 +56,8 @@ class FakeDataReader: img = np.random.normal( 0.485, 0.229, [3, cfg.input_size, cfg.input_size] ) - point1 = cfg.input_size / 4 - point2 = cfg.input_size / 2 + point1 = 1 / 4 + point2 = 1 / 2 gt_boxes = np.array([[point1, point1, point2, point2]]) gt_labels = np.random.randint( low=0, high=cfg.class_num, size=[1] -- GitLab