nccl_gpu_common_test.cc 621 字节
Newer Older
D
Dong Zhihong 已提交
1 2 3 4 5 6 7 8
#include "paddle/operators/nccl/nccl_gpu_common.h"

#include <gtest/gtest.h>

#include <chrono>
#include <thread>
#include <vector>

D
Dong Zhihong 已提交
9 10 11
namespace paddle {
namespace platform {

D
Dong Zhihong 已提交
12 13
TEST(WaitGroup, wait) {
  WaitGroup wg;
D
Dong Zhihong 已提交
14
  auto run_thread = [&wg](int idx) {
D
Dong Zhihong 已提交
15 16 17 18 19 20 21 22 23 24 25
    wg.Add(1);
    std::this_thread::sleep_for(std::chrono::seconds(1));
    wg.Done();
  };

  std::vector<std::thread> ths;
  constexpr const int TNUM = 5;
  for (int i = 0; i < TNUM; ++i) {
    ths.emplace_back(std::thread(run_thread, i));
  }
  wg.Wait();
D
Dong Zhihong 已提交
26 27 28 29

  for (int i = 0; i < TNUM; ++i) {
    ths[i].join();
  }
D
Dong Zhihong 已提交
30
}
D
Dong Zhihong 已提交
31 32 33

}  // namespace platform
}  // namespace paddle