alpaka
Abstraction Library for Parallel Kernel Acceleration
Engine.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Axel Huebl, Benjamin Worpitz, Bernhard Manfred Gruber
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
8 
9 #include <cstdint>
10 
12 {
13  //! Implementation of std::UniformRandomBitGenerator for TinyMT32
14  struct TinyMTengine
15  {
16  using result_type = std::uint32_t;
17 
18  static constexpr auto default_seed() -> result_type
19  {
20  return 42u;
21  }
22 
23  void seed(result_type value = default_seed())
24  {
25  // parameters from TinyMT/jump/sample.c
26  prng.mat1 = 0x8f70'11ee;
27  prng.mat2 = 0xfc78'ff1f;
28  prng.tmat = 0x3793'fdff;
29 
30  tinymt32_init(&prng, value);
31  }
32 
33  TinyMTengine(std::uint32_t const& seedValue)
34  {
35  seed(seedValue);
36  }
37 
39  {
40  seed(default_seed());
41  }
42 
44  {
46  }
47 
48  static constexpr auto min() -> result_type
49  {
50  return 0u;
51  }
52 
53  static constexpr auto max() -> result_type
54  {
55  return UINT32_MAX;
56  }
57 
58  void discard(unsigned long long) // z
59  {
60  // not implemented
61  // tinymt32_jump( &prng, z, z );
62  }
63 
65  };
66 } // namespace alpaka::rand::engine::cpu
uint32_t tmat
Definition: tinymt32.h:69
uint32_t mat2
Definition: tinymt32.h:68
uint32_t mat1
Definition: tinymt32.h:67
Implementation of std::UniformRandomBitGenerator for TinyMT32.
Definition: Engine.hpp:15
auto operator()() -> result_type
Definition: Engine.hpp:43
static constexpr auto default_seed() -> result_type
Definition: Engine.hpp:18
void seed(result_type value=default_seed())
Definition: Engine.hpp:23
static constexpr auto max() -> result_type
Definition: Engine.hpp:53
static constexpr auto min() -> result_type
Definition: Engine.hpp:48
TinyMTengine(std::uint32_t const &seedValue)
Definition: Engine.hpp:33
void discard(unsigned long long)
Definition: Engine.hpp:58
Tiny Mersenne Twister only 127 bit internal state.
void tinymt32_init(tinymt32_t *random, uint32_t seed)
Definition: tinymt32.h:331
static uint32_t tinymt32_generate_uint32(tinymt32_t *random)
Definition: tinymt32.h:207
#define UINT32_MAX
Definition: tinymt32.h:30