1 #include <gtest/gtest.h> 4 #include <ATen/cuda/CUDAContext.h> 6 #include <cuda_runtime.h> 9 void makeRandomNumber() {
10 cudaSetDevice(std::rand() % 2);
11 auto x = at::randn({1000});
14 void testCudaRNGMultithread() {
15 auto threads = std::vector<std::thread>();
16 for (
auto i = 0; i < 1000; i++) {
17 threads.emplace_back(makeRandomNumber);
19 for (
auto& t : threads) {
24 TEST(Cuda_RNGTest, MultithreadRNGTest) {
25 if (!at::cuda::is_available())
return;
26 testCudaRNGMultithread();