11 #ifndef EIGEN_CXX11_TENSOR_TENSOR_RANDOM_H
12 #define EIGEN_CXX11_TENSOR_TENSOR_RANDOM_H
20 #if defined(EIGEN_GPU_COMPILE_PHASE)
24 return blockIdx.x * blockDim.x + threadIdx.x
25 + gridDim.x * blockDim.x * (blockIdx.y * blockDim.y + threadIdx.y);
28 return random<uint64_t>();
36 *state = current * 6364136223846793005ULL + (stream << 1 | 1);
38 return static_cast<unsigned>((current ^ (current >> 22)) >> (22 + (current >> 61)));
43 return seed * 6364136223846793005ULL + 0xda3e39cb94b95bdbULL;
49 return static_cast<T>(rnd);
58 Eigen::half result = Eigen::numext::bit_cast<Eigen::half>(half_bits);
69 Eigen::bfloat16 result = Eigen::numext::bit_cast<Eigen::bfloat16>(half_bits);
83 result.raw = rnd & 0x7fffffu;
85 result.raw |= (
static_cast<uint32_t>(127) << 23);
87 return result.fp - 1.0f;
103 result.raw = (
static_cast<uint64_t>(rnd1) << 32) | rnd2;
105 result.raw |= (
static_cast<uint64_t>(1023) << 52);
107 return result.dp - 1.0;
111 std::complex<float> RandomToTypeUniform<std::complex<float> >(
uint64_t* state,
uint64_t stream) {
116 std::complex<double> RandomToTypeUniform<std::complex<double> >(
uint64_t* state,
uint64_t stream) {
121 template <
typename T>
class UniformRandomGenerator {
123 static constexpr
bool PacketAccess =
true;
129 #ifdef EIGEN_USE_SYCL
147 const UniformRandomGenerator& other) {
148 m_state = other.m_state;
149 #ifdef EIGEN_USE_SYCL
150 m_exec_once =other.m_exec_once;
156 #ifdef EIGEN_USE_SYCL
160 m_state += (
i * 6364136223846793005ULL);
164 T result = RandomToTypeUniform<T>(&m_state, i);
169 Packet packetOp(
Index i)
const {
170 const int packetSize = internal::unpacket_traits<Packet>::size;
172 #ifdef EIGEN_USE_SYCL
175 m_state += (
i * 6364136223846793005ULL);
180 for (
int j = 0;
j < packetSize; ++
j) {
181 values[
j] = RandomToTypeUniform<T>(&m_state, i);
183 return internal::pload<Packet>(values);
188 #ifdef EIGEN_USE_SYCL
189 mutable bool m_exec_once;
193 template <
typename Scalar>
194 struct functor_traits<UniformRandomGenerator<Scalar> > {
198 ((
sizeof(Scalar) +
sizeof(
float) - 1) /
sizeof(
float)),
199 PacketAccess = UniformRandomGenerator<Scalar>::PacketAccess
212 u = RandomToTypeUniform<T>(state, stream);
213 v =
T(1.7156) * (RandomToTypeUniform<T>(state, stream) -
T(0.5));
214 const T x = u -
T(0.449871);
216 q =
x*
x +
y * (
T(0.196)*
y -
T(0.25472)*
x);
217 }
while (
q >
T(0.27597) &&
224 std::complex<float> RandomToTypeNormal<std::complex<float> >(
uint64_t* state,
uint64_t stream) {
225 return std::complex<float>(RandomToTypeNormal<float>(state, stream),
226 RandomToTypeNormal<float>(state, stream));
229 std::complex<double> RandomToTypeNormal<std::complex<double> >(
uint64_t* state,
uint64_t stream) {
230 return std::complex<double>(RandomToTypeNormal<double>(state, stream),
231 RandomToTypeNormal<double>(state, stream));
235 template <
typename T>
class NormalRandomGenerator {
237 static constexpr
bool PacketAccess =
true;
242 #ifdef EIGEN_USE_SYCL
257 const NormalRandomGenerator& other) {
258 m_state = other.m_state;
259 #ifdef EIGEN_USE_SYCL
260 m_exec_once=other.m_exec_once;
266 #ifdef EIGEN_USE_SYCL
269 m_state += (
i * 6364136223846793005ULL);
273 T result = RandomToTypeNormal<T>(&m_state, i);
278 Packet packetOp(
Index i)
const {
279 const int packetSize = internal::unpacket_traits<Packet>::size;
281 #ifdef EIGEN_USE_SYCL
284 m_state += (
i * 6364136223846793005ULL);
289 for (
int j = 0;
j < packetSize; ++
j) {
290 values[
j] = RandomToTypeNormal<T>(&m_state, i);
292 return internal::pload<Packet>(values);
297 #ifdef EIGEN_USE_SYCL
298 mutable bool m_exec_once;
303 template <
typename Scalar>
304 struct functor_traits<NormalRandomGenerator<Scalar> > {
308 Cost = 3 * functor_traits<UniformRandomGenerator<Scalar> >::Cost +
310 3 * functor_traits<scalar_log_op<Scalar> >::Cost / 2,
311 PacketAccess = NormalRandomGenerator<Scalar>::PacketAccess
Array< int, Dynamic, 1 > v
IndexedView_or_VectorBlock operator()(const Indices &indices)
#define EIGEN_UNROLL_LOOP
#define EIGEN_DEVICE_FUNC
T RandomToTypeUniform(uint64_t *state, uint64_t stream)
unsigned PCG_XSH_RS_generator(uint64_t *state, uint64_t stream)
double RandomToTypeUniform< double >(uint64_t *state, uint64_t stream)
T RandomToTypeNormal(uint64_t *state, uint64_t stream)
float RandomToTypeUniform< float >(uint64_t *state, uint64_t stream)
uint64_t get_random_seed()
uint64_t PCG_XSH_RS_state(uint64_t seed)
EIGEN_ALWAYS_INLINE std::enable_if_t< NumTraits< T >::IsSigned||NumTraits< T >::IsComplex, typename NumTraits< T >::Real > abs(const T &x)
EIGEN_ALWAYS_INLINE T log(const T &x)
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index