14 #include <type_traits>
16 #if(defined(ALPAKA_ACC_GPU_CUDA_ENABLED) || defined(ALPAKA_ACC_GPU_HIP_ENABLED)) && !defined(ALPAKA_DISABLE_VENDOR_RNG)
18 # if defined(ALPAKA_ACC_GPU_CUDA_ENABLED)
19 # include <curand_kernel.h>
20 # elif defined(ALPAKA_ACC_GPU_HIP_ENABLED)
22 # pragma clang diagnostic push
23 # pragma clang diagnostic ignored "-Wduplicate-decl-specifier"
26 # if HIP_VERSION >= 50'200'000
27 # include <hiprand/hiprand_kernel.h>
29 # include <hiprand_kernel.h>
33 # pragma clang diagnostic pop
40 template<
typename TApi>
45 # if !defined(ALPAKA_HOST_ONLY)
47 # if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) && !BOOST_LANG_CUDA
48 # error If ALPAKA_ACC_GPU_CUDA_ENABLED is set, the compiler has to support CUDA!
51 # if defined(ALPAKA_ACC_GPU_HIP_ENABLED) && !BOOST_LANG_HIP
52 # error If ALPAKA_ACC_GPU_HIP_ENABLED is set, the compiler has to support HIP!
55 namespace distribution::uniform_cuda_hip
70 namespace engine::uniform_cuda_hip
81 std::uint32_t
const& seed,
82 std::uint32_t
const& subsequence = 0,
83 std::uint32_t
const&
offset = 0)
85 # ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
86 curand_init(seed, subsequence,
offset, &state);
88 hiprand_init(seed, subsequence,
offset, &state);
100 # ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
101 curandStateXORWOW_t state = curandStateXORWOW_t{};
103 hiprandStateXORWOW_t state = hiprandStateXORWOW_t{};
111 # ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
128 # ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
129 return curand(&state);
131 return hiprand(&state);
137 namespace distribution::uniform_cuda_hip
144 template<
typename TEngine>
147 # ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
148 return curand_normal(&engine.state);
150 return hiprand_normal(&engine.state);
160 template<
typename TEngine>
163 # ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
164 return curand_normal_double(&engine.state);
166 return hiprand_normal_double(&engine.state);
176 template<
typename TEngine>
180 # ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
181 float const fUniformRand(curand_uniform(&engine.state));
183 float const fUniformRand(hiprand_uniform(&engine.state));
187 return fUniformRand *
static_cast<float>(fUniformRand != 1.0f);
196 template<
typename TEngine>
200 # ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
201 double const fUniformRand(curand_uniform_double(&engine.state));
203 double const fUniformRand(hiprand_uniform_double(&engine.state));
207 return fUniformRand *
static_cast<double>(fUniformRand != 1.0);
216 template<
typename TEngine>
219 # ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
220 return curand(&engine.state);
222 return hiprand(&engine.state);
228 namespace distribution::trait
231 template<
typename TApi,
typename T>
242 template<
typename TApi,
typename T>
253 template<
typename TApi,
typename T>
264 namespace engine::trait
267 template<
typename TApi>
272 std::uint32_t
const& seed = 0,
273 std::uint32_t
const& subsequence = 0,
276 return {seed, subsequence,
offset};
#define ALPAKA_FN_HOST_ACC
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto max(T const &max_ctx, Tx const &x, Ty const &y)
Returns the larger of two arguments. NaNs are treated as missing data (between a NaN and a numeric va...
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto min(T const &min_ctx, Tx const &x, Ty const &y)
Returns the smaller of two arguments. NaNs are treated as missing data (between a NaN and a numeric v...
Tag used in class inheritance hierarchies that describes that a specific interface (TInterface) is im...
The random number float normal distribution get trait.
The random number default generator engine get trait.