aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported
diff options
context:
space:
mode:
authorGravatar Antonio Sanchez <cantonios@google.com>2021-04-30 08:19:48 -0700
committerGravatar Antonio Sanchez <cantonios@google.com>2021-05-04 13:34:49 -0700
commite3b7f59659689015aa254ed67c48d870831f086f (patch)
tree87a5cc3735f8205393ab8f2b22d89f6d24803cb9 /unsupported
parent1c013be2cc6a999268be2f25575cd6a07bd52c45 (diff)
Simplify TensorRandom and remove time-dependence.
Time-dependence prevents tests from being repeatable. This has long been an issue with debugging the tensor tests. Removing this will allow future tests to be repeatable in the usual way. Also, the recently added macros in !476 are causing headaches across different platforms. For example, checking `_XOPEN_SOURCE` is leading to multiple ambiguous macro errors across Google, and `_DEFAULT_SOURCE`/`_SVID_SOURCE`/`_BSD_SOURCE` are sometimes defined with values, sometimes defined as empty, and sometimes not defined at all when they probably should be. This is leading to multiple build breakages. The simplest approach is to generate a seed via `Eigen::internal::random<uint64_t>()` if on CPU. For GPU, we use a hash based on the current thread ID (since `rand()` isn't supported on GPU). Fixes #1602.
Diffstat (limited to 'unsupported')
-rw-r--r--unsupported/Eigen/CXX11/Tensor8
-rw-r--r--unsupported/Eigen/CXX11/src/Tensor/TensorRandom.h50
2 files changed, 4 insertions, 54 deletions
diff --git a/unsupported/Eigen/CXX11/Tensor b/unsupported/Eigen/CXX11/Tensor
index d73c6008d..0938bb554 100644
--- a/unsupported/Eigen/CXX11/Tensor
+++ b/unsupported/Eigen/CXX11/Tensor
@@ -41,14 +41,6 @@
#include <random>
#include <thread>
-#ifdef _WIN32
-#include <windows.h>
-#elif defined(__APPLE__)
-#include <mach/mach_time.h>
-#else
-#include <time.h>
-#endif
-
#if defined(EIGEN_USE_THREADS) || defined(EIGEN_USE_SYCL)
#include "ThreadPool"
#endif
diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorRandom.h b/unsupported/Eigen/CXX11/src/Tensor/TensorRandom.h
index 9a20b53bb..37c1d1c3d 100644
--- a/unsupported/Eigen/CXX11/src/Tensor/TensorRandom.h
+++ b/unsupported/Eigen/CXX11/src/Tensor/TensorRandom.h
@@ -21,53 +21,11 @@ EIGEN_DEVICE_FUNC uint64_t get_random_seed() {
// We don't support 3d kernels since we currently only use 1 and
// 2d kernels.
gpu_assert(threadIdx.z == 0);
- return clock64() +
- blockIdx.x * blockDim.x + threadIdx.x +
- gridDim.x * blockDim.x * (blockIdx.y * blockDim.y + threadIdx.y);
-
-#elif defined _WIN32
- // Use the current time as a baseline.
- SYSTEMTIME st;
- GetSystemTime(&st);
- int time = st.wSecond + 1000 * st.wMilliseconds;
- // Mix in a random number to make sure that we get different seeds if
- // we try to generate seeds faster than the clock resolution.
- // We need 2 random values since the generator only generate 16 bits at
- // a time (https://msdn.microsoft.com/en-us/library/398ax69y.aspx)
- unsigned rnd1 = static_cast<unsigned>(::rand());
- unsigned rnd2 = static_cast<unsigned>(::rand());
- uint64_t rnd = (rnd1 ^ (rnd2 << 16)) ^ time;
- return rnd;
-
-#elif defined __APPLE__
- // Same approach as for win32, except that the random number generator
- // is better (// https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/random.3.html#//apple_ref/doc/man/3/random).
- uint64_t rnd = ::random() ^ mach_absolute_time();
- return rnd;
-
-#else
- // Augment the current time with pseudo random number generation
- // to ensure that we get different seeds if we try to generate seeds
- // faster than the clock resolution.
- timespec ts;
- clock_gettime(CLOCK_REALTIME, &ts);
-
-
- // Check for BSD random().
-#if EIGEN_COMP_GNUC && (\
- defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 500 \
- || /* Glibc since 2.19: */ (defined(_DEFAULT_SOURCE) && _DEFAULT_SOURCE) \
- || /* Glibc <= 2.19: */ (defined(_SVID_SOURCE) && _SVID_SOURCE) \
- || (defined(_BSD_SOURCE) && _BSD_SOURCE) \
- )
- uint64_t rnd = ::random();
+ return blockIdx.x * blockDim.x + threadIdx.x
+ + gridDim.x * blockDim.x * (blockIdx.y * blockDim.y + threadIdx.y);
#else
- // Build random from rand()
- unsigned rnd1 = static_cast<unsigned>(::rand());
- unsigned rnd2 = static_cast<unsigned>(::rand());
- uint64_t rnd = (rnd1 ^ (rnd2 << 16));
-#endif
- return rnd ^ ts.tv_nsec;
+ // Rely on Eigen's random implementation.
+ return random<uint64_t>();
#endif
}