15 #ifdef ETL_CURAND_MODE 26 template <
typename T =
double>
45 normal_generator_op(T mean, T stddev) : mean(mean), stddev(stddev), rand_engine(std::time(nullptr)), distribution(mean, stddev) {}
55 #ifdef ETL_CURAND_MODE 65 auto t1 = etl::force_temporary_gpu_dim_only_t<T>(y);
67 curandGenerator_t gen;
70 curand_call(curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_DEFAULT));
73 std::uniform_int_distribution<long> seed_dist;
74 curand_call(curandSetPseudoRandomGeneratorSeed(gen, seed_dist(rand_engine)));
80 curand_call(curandDestroyGenerator(gen));
92 Y& gpu_compute(Y& y) noexcept {
93 y.ensure_gpu_allocated();
95 curandGenerator_t gen;
98 curand_call(curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_DEFAULT));
101 std::uniform_int_distribution<long> seed_dist;
102 curand_call(curandSetPseudoRandomGeneratorSeed(gen, seed_dist(rand_engine)));
108 curand_call(curandDestroyGenerator(gen));
125 return os <<
"N(0,1)";
132 template <
typename G,
typename T =
double>
151 normal_generator_g_op(G& g, T mean, T stddev) : mean(mean), stddev(stddev), rand_engine(g), distribution(mean, stddev) {}
161 #ifdef ETL_CURAND_MODE 169 template <
typename Y>
171 auto t1 = etl::force_temporary_gpu_dim_only_t<T>(y);
173 curandGenerator_t gen;
176 curand_call(curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_DEFAULT));
179 std::uniform_int_distribution<long> seed_dist;
180 curand_call(curandSetPseudoRandomGeneratorSeed(gen, seed_dist(rand_engine)));
194 template <
typename Y>
195 Y& gpu_compute(Y& y) noexcept {
196 y.ensure_gpu_allocated();
198 curandGenerator_t gen;
201 curand_call(curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_DEFAULT));
204 std::uniform_int_distribution<long> seed_dist;
205 curand_call(curandSetPseudoRandomGeneratorSeed(gen, seed_dist(rand_engine)));
225 return os <<
"N(0,1)";
Generator from a normal distribution using a custom random engine.
Definition: normal.hpp:133
std::normal_distribution< value_type > distribution
The used distribution.
Definition: normal.hpp:139
auto s(T &&value)
Force the evaluation of the given expression.
Definition: stop.hpp:18
value_type operator()()
Generate a new value.
Definition: normal.hpp:51
T value_type
The value type.
Definition: normal.hpp:28
const T stddev
The standard deviation.
Definition: normal.hpp:31
normal_generator_op(T mean, T stddev)
Construct a new generator with the given mean and standard deviation.
Definition: normal.hpp:45
constexpr bool curand_enabled
Indicates if the NVIDIA CURAND library is available for ETL.
Definition: config.hpp:109
Root namespace for the ETL library.
Definition: adapter.hpp:15
static constexpr bool gpu_computable
Indicates if the operator can be computed on GPU.
Definition: normal.hpp:38
friend std::ostream & operator<<(std::ostream &os, [[maybe_unused]] const normal_generator_g_op &s)
Outputs the given generator to the given stream.
Definition: normal.hpp:224
random_engine rand_engine
The random engine.
Definition: normal.hpp:32
G & rand_engine
The random engine.
Definition: normal.hpp:138
const T stddev
The standard deviation.
Definition: normal.hpp:137
friend std::ostream & operator<<(std::ostream &os, [[maybe_unused]] const normal_generator_op &s)
Outputs the given generator to the given stream.
Definition: normal.hpp:124
value_type operator()()
Generate a new value.
Definition: normal.hpp:157
constexpr size_t size(const E &expr) noexcept
Returns the size of the given ETL expression.
Definition: helpers.hpp:108
T value_type
The value type.
Definition: normal.hpp:134
normal_generator_g_op(G &g, T mean, T stddev)
Construct a new generator with the given mean and standard deviation.
Definition: normal.hpp:151
const T mean
The mean.
Definition: normal.hpp:136
std::mt19937_64 random_engine
The random engine used by the library.
Definition: random.hpp:22
Utility functions for curand.
const auto & gpu_compute_hint([[maybe_unused]] Y &y) const
Return a GPU computed version of this expression.
Definition: sub_view.hpp:653
Generator from a normal distribution.
Definition: normal.hpp:27
const T mean
The mean.
Definition: normal.hpp:30
std::normal_distribution< value_type > distribution
The used distribution.
Definition: normal.hpp:33