Skip to content

Commit 1c48d61

Browse files
authored
Merge pull request #14599 from sneaxiy/fix_mac_unittest_bug
Fix Mac unittest bug
2 parents b651306 + f3522a1 commit 1c48d61

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

paddle/fluid/memory/allocation/best_fit_allocator_test.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ TEST(BestFitAllocator, test_concurrent_cpu_allocation) {
9999

100100
LockedAllocator locked_allocator(std::move(best_fit_allocator));
101101

102-
auto th_main = [&] {
103-
std::random_device dev;
104-
std::default_random_engine engine(dev());
102+
auto th_main = [&](std::random_device::result_type seed) {
103+
std::default_random_engine engine(seed);
105104
std::uniform_int_distribution<size_t> dist(1U, 1024U);
106105

107106
for (size_t i = 0; i < 128; ++i) {
@@ -125,7 +124,8 @@ TEST(BestFitAllocator, test_concurrent_cpu_allocation) {
125124
{
126125
std::vector<std::thread> threads;
127126
for (size_t i = 0; i < 1024; ++i) {
128-
threads.emplace_back(th_main);
127+
std::random_device dev;
128+
threads.emplace_back(th_main, dev());
129129
}
130130
for (auto& th : threads) {
131131
th.join();

paddle/fluid/memory/allocation/best_fit_allocator_test.cu

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ TEST(BestFitAllocator, concurrent_cuda) {
4141
LockedAllocator concurrent_allocator(
4242
std::unique_ptr<Allocator>(new BestFitAllocator(cuda_allocation.get())));
4343

44-
auto th_main = [&] {
45-
std::random_device dev;
46-
std::default_random_engine engine(dev());
44+
auto th_main = [&](std::random_device::result_type seed) {
45+
std::default_random_engine engine(seed);
4746
std::uniform_int_distribution<size_t> dist(1U, 1024U);
4847
platform::CUDAPlace gpu(0);
4948
platform::CUDADeviceContext dev_ctx(gpu);
@@ -75,7 +74,8 @@ TEST(BestFitAllocator, concurrent_cuda) {
7574
{
7675
std::vector<std::thread> threads;
7776
for (size_t i = 0; i < 1024; ++i) {
78-
threads.emplace_back(th_main);
77+
std::random_device dev;
78+
threads.emplace_back(th_main, dev());
7979
}
8080
for (auto& th : threads) {
8181
th.join();

0 commit comments

Comments
 (0)