alpaka
Abstraction Library for Parallel Kernel Acceleration
PhiloxConstants.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Jiri Vyskocil, Bernhard Manfred Gruber
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
8 
9 #include <cstdint>
10 #include <utility>
11 
12 namespace alpaka::rand::engine
13 {
14  /** Constants used in the Philox algorithm
15  *
16  * The numbers are taken from the reference Philox implementation:
17  *
18  * J. K. Salmon, M. A. Moraes, R. O. Dror and D. E. Shaw, "Parallel random numbers: As easy as 1, 2, 3,"
19  * SC '11: Proceedings of 2011 International Conference for High Performance Computing, Networking,
20  * Storage and Analysis, 2011, pp. 1-12, doi: 10.1145/2063384.2063405.
21  *
22  * @tparam TParams basic Philox algorithm parameters
23  *
24  * static const data members are transformed into functions, because GCC
25  * assumes types with static data members to be not mappable and makes not
26  * exception for constexpr ones. This is a valid interpretation of the
27  * OpenMP <= 4.5 standard. In OpenMP >= 5.0 types with any kind of static
28  * data member are mappable.
29  */
30  template<typename TParams>
32  {
33  public:
34  /// First Weyl sequence parameter: the golden ratio
35  static constexpr std::uint64_t WEYL_64_0()
36  {
37  return 0x9E37'79B9'7F4A'7C15;
38  }
39 
40  /// Second Weyl sequence parameter: \f$ \sqrt{3}-1 \f$
41  static constexpr std::uint64_t WEYL_64_1()
42  {
43  return 0xBB67'AE85'84CA'A73B;
44  }
45 
46  /// 1st Weyl sequence parameter, 32 bits
47  static constexpr std::uint32_t WEYL_32_0()
48  {
49  return high32Bits(WEYL_64_0());
50  }
51 
52  /// 2nd Weyl sequence parameter, 32 bits
53  static constexpr std::uint32_t WEYL_32_1()
54  {
55  return high32Bits(WEYL_64_1());
56  }
57 
58  /// First Philox S-box multiplier
59  static constexpr std::uint32_t MULTIPLITER_4x32_0()
60  {
61  return 0xCD9E'8D57;
62  }
63 
64  /// Second Philox S-box multiplier
65  static constexpr std::uint32_t MULTIPLITER_4x32_1()
66  {
67  return 0xD251'1F53;
68  }
69  };
70 } // namespace alpaka::rand::engine
static constexpr std::uint32_t WEYL_32_0()
1st Weyl sequence parameter, 32 bits
static constexpr std::uint64_t WEYL_64_0()
First Weyl sequence parameter: the golden ratio.
static constexpr std::uint64_t WEYL_64_1()
Second Weyl sequence parameter: .
static constexpr std::uint32_t MULTIPLITER_4x32_1()
Second Philox S-box multiplier.
static constexpr std::uint32_t WEYL_32_1()
2nd Weyl sequence parameter, 32 bits
static constexpr std::uint32_t MULTIPLITER_4x32_0()
First Philox S-box multiplier.
The random number generator engine specifics.
constexpr ALPAKA_FN_HOST_ACC auto high32Bits(std::uint64_t const x) -> std::uint32_t
Get high 32 bits of a 64-bit number.