Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix ci
  • Loading branch information
liuruyan committed Nov 12, 2025
commit e15aea08e6a190ebf659873978047c450391c1bd
4 changes: 4 additions & 0 deletions test/cpp/fluid/memory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ cc_test(
stats_test
SRCS stats_test.cc
DEPS)
cc_test(
compact_allocator_test
SRCS compact_allocator_test.cc
DEPS)

cc_test(
naive_best_fit_allocator_test
Expand Down
47 changes: 47 additions & 0 deletions test/cpp/fluid/memory/compact_allocator_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "paddle/phi/core/memory/allocation/allocator.h"
#include "paddle/phi/core/memory/allocation/retry_allocator.h"

#include <thread> // NOLINT

#include "gtest/gtest.h"
#include "paddle/phi/core/memory/allocation/best_fit_allocator.h"
#include "paddle/phi/core/memory/allocation/cpu_allocator.h"
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
#include "paddle/phi/core/memory/allocation/cuda_allocator.h"
#endif
namespace paddle {
namespace memory {
namespace allocation {

TEST(RetryAllocator, TestRetryComopact) {
CPUAllocator cpu_allocator;

size_t size = (1 << 20);
auto cpu_allocation = cpu_allocator.Allocate(size);

// Reserve to perform more tests in the future
std::unique_ptr<BestFitAllocator> best_fit_allocator(
new BestFitAllocator(cpu_allocation.get()));
std::shared_ptr<Allocator> allocator = std::make_shared<RetryAllocator>(
std::move(best_fit_allocator), phi::CPUPlace(), 1);

allocator->Compact(phi::CPUPlace());
}

} // namespace allocation
} // namespace memory
} // namespace paddle
3 changes: 2 additions & 1 deletion test/legacy_test/test_vmm_compact.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@


@unittest.skipIf(
not paddle.is_compiled_with_cuda(), 'should compile with cuda.'
(not paddle.is_compiled_with_cuda()) or paddle.is_compiled_with_rocm,
'should compile with cuda.',
)
class TestVmmCompact(unittest.TestCase):
def setUp(self):
Expand Down
Loading