12 #if defined(ALPAKA_ACC_SYCL_ENABLED) && !defined(ALPAKA_DISABLE_VENDOR_RNG)
15 # include <sycl/sycl.hpp>
17 # pragma clang diagnostic push
18 # pragma clang diagnostic ignored "-Wcast-align"
19 # pragma clang diagnostic ignored "-Wcast-qual"
20 # pragma clang diagnostic ignored "-Wextra-semi"
21 # pragma clang diagnostic ignored "-Wfloat-equal"
22 # pragma clang diagnostic ignored "-Wold-style-cast"
23 # pragma clang diagnostic ignored "-Wreserved-identifier"
24 # pragma clang diagnostic ignored "-Wreserved-macro-identifier"
25 # pragma clang diagnostic ignored "-Wsign-compare"
26 # pragma clang diagnostic ignored "-Wundef"
28 # include <oneapi/dpl/random>
30 # pragma clang diagnostic pop
33 # include <type_traits>
38 template<
typename TDim>
39 struct RandGenericSycl : interface::Implements<ConceptRand, RandGenericSycl<TDim>>
41 explicit RandGenericSycl(sycl::nd_item<TDim::value> my_item) : m_item_rand{my_item}
45 sycl::nd_item<TDim::value> m_item_rand;
48 # if !defined(ALPAKA_HOST_ONLY)
49 namespace distribution::sycl_rand
60 namespace engine::sycl_rand
63 template<
typename TDim>
71 Minstd(RandGenericSycl<TDim> rand, std::uint32_t
const& seed)
73 oneapi::dpl::minstd_rand engine(seed, rand.m_item_rand.get_global_linear_id());
79 friend struct distribution::sycl_rand::NormalReal;
81 friend struct distribution::sycl_rand::Uniform;
83 oneapi::dpl::minstd_rand rng_engine;
86 using result_type = float;
98 result_type operator()()
100 oneapi::dpl::uniform_real_distribution<float> distr;
101 return distr(rng_engine);
106 namespace distribution::sycl_rand
113 static_assert(std::is_floating_point_v<F>);
115 template<
typename TEngine>
116 auto operator()(TEngine& engine) -> F
118 oneapi::dpl::normal_distribution<F> distr;
119 return distr(engine.rng_engine);
127 static_assert(std::is_floating_point_v<T> || std::is_unsigned_v<T>);
129 template<
typename TEngine>
130 auto operator()(TEngine& engine) -> T
132 if constexpr(std::is_floating_point_v<T>)
134 oneapi::dpl::uniform_real_distribution<T> distr;
135 return distr(engine.rng_engine);
139 oneapi::dpl::uniform_int_distribution<T> distr;
140 return distr(engine.rng_engine);
146 namespace distribution::trait
149 template<
typename TDim,
typename T>
150 struct CreateNormalReal<RandGenericSycl<TDim>, T, std::enable_if_t<std::is_floating_point_v<T>>>
152 static auto createNormalReal(RandGenericSycl<TDim>
const& ) -> sycl_rand::NormalReal<T>
159 template<
typename TDim,
typename T>
160 struct CreateUniformReal<RandGenericSycl<TDim>, T, std::enable_if_t<std::is_floating_point_v<T>>>
162 static auto createUniformReal(RandGenericSycl<TDim>
const& ) -> sycl_rand::Uniform<T>
169 template<
typename TDim,
typename T>
170 struct CreateUniformUint<RandGenericSycl<TDim>, T, std::enable_if_t<std::is_integral_v<T>>>
172 static auto createUniformUint(RandGenericSycl<TDim>
const& ) -> sycl_rand::Uniform<T>
179 namespace engine::trait
182 template<
typename TDim>
183 struct CreateDefault<RandGenericSycl<TDim>>
186 RandGenericSycl<TDim>
const& rand,
187 std::uint32_t
const& seed = 0,
188 std::uint32_t
const& = 0,
189 std::uint32_t
const& = 0) -> sycl_rand::Minstd<TDim>
#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...
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto createNormalReal(TRand const &rand)
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto createUniformUint(TRand const &rand)
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto createUniformReal(TRand const &rand)
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto createDefault(TRand const &rand, std::uint32_t const &seed=0, std::uint32_t const &subsequence=0, std::uint32_t const &offset=0)