Skip to content

Commit

Permalink
Replace shared_ptr with unique_ptr in base_ptr_test (#38530)
Browse files Browse the repository at this point in the history
  • Loading branch information
From00 committed Dec 30, 2021
1 parent b1e7334 commit 3f6229c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions paddle/fluid/memory/allocation/base_ptr_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CUDAAllocatoionBasePtrTest : public ::testing::Test {
void OneByOneAllocTest() {
for (size_t i = 0; i < alloc_times_; ++i) {
size_t size = dis_(random_engine_);
std::shared_ptr<Allocation> allocation = AllocShared(place_, size);
AllocationPtr allocation = Alloc(place_, size);

void* base_ptr = allocation->base_ptr();
void* system_ptr =
Expand All @@ -47,21 +47,21 @@ class CUDAAllocatoionBasePtrTest : public ::testing::Test {
}

void BatchByBatchAllocTest() {
std::vector<std::shared_ptr<Allocation>> allocations;
std::vector<AllocationPtr> allocations;
allocations.reserve(batch_size_);
size_t batch_num = alloc_times_ / batch_size_;

for (size_t i = 0; i < batch_num; ++i) {
for (size_t j = 0; j < batch_size_; ++j) {
size_t size = dis_(random_engine_);
std::shared_ptr<Allocation> allocation = AllocShared(place_, size);
AllocationPtr allocation = Alloc(place_, size);

void* base_ptr = allocation->base_ptr();
void* system_ptr =
platform::GetGpuBasePtr(allocation->ptr(), place_.GetDeviceId());
EXPECT_EQ(base_ptr, system_ptr);

allocations.emplace_back(allocation);
allocations.emplace_back(std::move(allocation));
}
allocations.clear();
}
Expand All @@ -70,27 +70,27 @@ class CUDAAllocatoionBasePtrTest : public ::testing::Test {
}

void ContinuousAllocTest() {
std::vector<std::shared_ptr<Allocation>> allocations;
std::vector<AllocationPtr> allocations;
allocations.reserve(alloc_times_);

for (size_t i = 0; i < alloc_times_; ++i) {
size_t size = dis_(random_engine_);
std::shared_ptr<Allocation> allocation = AllocShared(place_, size);
AllocationPtr allocation = Alloc(place_, size);

void* base_ptr = allocation->base_ptr();
void* system_ptr =
platform::GetGpuBasePtr(allocation->ptr(), place_.GetDeviceId());
EXPECT_EQ(base_ptr, system_ptr);

allocations.emplace_back(allocation);
allocations.emplace_back(std::move(allocation));
}

allocations.clear();
Release(place_);
}

void ZeroSizeAllocTest() {
std::shared_ptr<Allocation> allocation = AllocShared(place_, 0);
AllocationPtr allocation = Alloc(place_, 0);
void* base_ptr = allocation->base_ptr();
void* system_ptr =
platform::GetGpuBasePtr(allocation->ptr(), place_.GetDeviceId());
Expand Down

0 comments on commit 3f6229c

Please sign in to comment.