/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-rocrand/checkouts/docs-6.1.2/library/include/rocrand/rocrand_scrambled_sobol64.h Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-rocrand/checkouts/docs-6.1.2/library/include/rocrand/rocrand_scrambled_sobol64.h Source File#

API library: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-rocrand/checkouts/docs-6.1.2/library/include/rocrand/rocrand_scrambled_sobol64.h Source File
API library
rocrand_scrambled_sobol64.h
1 // Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 
21 #ifndef ROCRAND_SCRAMBLED_SOBOL64_H_
22 #define ROCRAND_SCRAMBLED_SOBOL64_H_
23 
24 #ifndef FQUALIFIERS
25  #define FQUALIFIERS __forceinline__ __device__
26 #endif // FQUALIFIERS_
27 
28 #include "rocrand/rocrand_common.h"
29 #include "rocrand/rocrand_sobol64.h"
30 
31 namespace rocrand_device
32 {
33 
34 template<bool UseSharedVectors>
35 class scrambled_sobol64_engine
36 {
37 public:
39  scrambled_sobol64_engine() : scramble_constant() {}
40 
42  scrambled_sobol64_engine(const unsigned long long int* vectors,
43  const unsigned long long int scramble_constant,
44  const unsigned int offset)
45  : m_engine(vectors, 0), scramble_constant(scramble_constant)
46  {
47  discard(offset);
48  }
49 
52  void discard(unsigned long long int offset)
53  {
54  m_engine.discard(offset);
55  }
56 
58  void discard()
59  {
60  m_engine.discard();
61  }
62 
65  void discard_stride(unsigned long long int stride)
66  {
67  m_engine.discard_stride(stride);
68  }
69 
71  unsigned long long int operator()()
72  {
73  return this->next();
74  }
75 
77  unsigned long long int next()
78  {
79  unsigned long long int p = m_engine.next();
80  return p ^ scramble_constant;
81  }
82 
84  unsigned long long int current()
85  {
86  unsigned long long int p = m_engine.current();
87  return p ^ scramble_constant;
88  }
89 
90 protected:
91  // Underlying sobol64 engine
92  sobol64_engine<UseSharedVectors> m_engine;
93  // scrambling constant
94  unsigned long long int scramble_constant;
95 
96 }; // scrambled_sobol64_engine class
97 
98 } // end namespace rocrand_device
99 
106 typedef rocrand_device::scrambled_sobol64_engine<false> rocrand_state_scrambled_sobol64;
108 
121 void rocrand_init(const unsigned long long int* vectors,
122  const unsigned long long int scramble_constant,
123  const unsigned int offset,
124  rocrand_state_scrambled_sobol64* state)
125 {
126  *state = rocrand_state_scrambled_sobol64(vectors, scramble_constant, offset);
127 }
128 
142 unsigned long long int rocrand(rocrand_state_scrambled_sobol64* state)
143 {
144  return state->next();
145 }
146 
156 void skipahead(unsigned long long offset, rocrand_state_scrambled_sobol64* state)
157 {
158  return state->discard(offset);
159 }
160  // end of group rocranddevice
162 
163 #endif // ROCRAND_SCRAMBLED_SOBOL64_H_
FQUALIFIERS void skipahead(unsigned long long offset, rocrand_state_scrambled_sobol64 *state)
Updates scrambled_sobol64 state to skip ahead by offset elements.
Definition: rocrand_scrambled_sobol64.h:156
FQUALIFIERS unsigned long long int rocrand(rocrand_state_scrambled_sobol64 *state)
Returns uniformly distributed random unsigned int value from [0; 2^64 - 1] range.
Definition: rocrand_scrambled_sobol64.h:142
FQUALIFIERS void rocrand_init(const unsigned long long int *vectors, const unsigned long long int scramble_constant, const unsigned int offset, rocrand_state_scrambled_sobol64 *state)
Initialize scrambled_sobol64 state.
Definition: rocrand_scrambled_sobol64.h:121
#define FQUALIFIERS
Shorthand for commonly used function qualifiers.
Definition: rocrand_uniform.h:31