14namespace alpaka::rand::engine::internal
22 template<
unsigned TCounterSize,
unsigned TW
idth,
unsigned TRounds>
25 static constexpr unsigned counterSize = TCounterSize;
26 static constexpr unsigned width = TWidth;
27 static constexpr unsigned rounds = TRounds;
37 template<
typename T_Params>
40 static constexpr unsigned numRounds()
42 return T_Params::rounds;
45 static constexpr unsigned vectorSize()
47 return T_Params::counterSize;
50 static constexpr unsigned numberWidth()
52 return T_Params::width;
55 static_assert(numRounds() > 0,
"Number of Philox rounds must be > 0.");
56 static_assert(vectorSize() % 2 == 0,
"Philox counter size must be an even number.");
57 static_assert(vectorSize() <= 16,
"Philox SP network is not specified for sizes > 16.");
58 static_assert(numberWidth() % 8 == 0,
"Philox number width in bits must be a multiple of 8.");
60 static_assert(numberWidth() == 32,
"Philox implemented only for 32 bit numbers.");
63 using Counter = alpaka::Vec<std::uint32_t, T_Params::counterSize>;
64 using Key =
alpaka::Vec<std::uint32_t, T_Params::counterSize / 2>;
73 static constexpr auto singleRound(Counter
const& counter, Key
const& key)
75 std::uint32_t H0, L0, H1, L1;
76 multiplyAndSplit64to32(counter[0], PhiloxConstants::MULTIPLITER_4x32_0(), H0, L0);
77 multiplyAndSplit64to32(counter[2], PhiloxConstants::MULTIPLITER_4x32_1(), H1, L1);
78 return Counter{H1 ^ counter[1] ^ key[0], L1, H0 ^ counter[3] ^ key[1], L0};
86 static constexpr auto bumpKey(Key
const& key)
88 return Key{key[0] + PhiloxConstants::WEYL_32_0(), key[1] + PhiloxConstants::WEYL_32_1()};
97 static constexpr auto nRounds(Counter
const& counter_in, Key
const& key_in) -> Counter
100 Counter counter = singleRound(counter_in, key);
103 constexpr unsigned rounds = numRounds();
105 for(
unsigned int n = 0; n < rounds; ++n)
108 counter = singleRound(counter, key);
121 static constexpr auto generate(Counter
const& counter, Key
const& key) -> Counter
123 return nRounds(counter, key);
ALPAKA_FN_HOST_ACC Vec(T_1, T_Args...) -> Vec< T_1, uint32_t(sizeof...(T_Args)+1u), ArrayStorage< T_1, uint32_t(sizeof...(T_Args)+1u)> >