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

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-rocrand/checkouts/docs-6.2.1/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.2.1/library/include/rocrand/rocrand_scrambled_sobol64.h Source File
API library
rocrand_scrambled_sobol64.h
1 // Copyright (c) 2022-2024 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 #include "rocrand/rocrand_common.h"
25 #include "rocrand/rocrand_sobol64.h"
26 
27 namespace rocrand_device
28 {
29 
30 template<bool UseSharedVectors>
31 class scrambled_sobol64_engine
32 {
33 public:
34  __forceinline__ __device__ __host__ scrambled_sobol64_engine() : scramble_constant() {}
35 
36  __forceinline__ __device__ __host__
37  scrambled_sobol64_engine(const unsigned long long int* vectors,
38  const unsigned long long int scramble_constant,
39  const unsigned int offset)
40  : m_engine(vectors, 0), scramble_constant(scramble_constant)
41  {
42  discard(offset);
43  }
44 
46  __forceinline__ __device__ __host__ void discard(unsigned long long int offset)
47  {
48  m_engine.discard(offset);
49  }
50 
51  __forceinline__ __device__ __host__ void discard()
52  {
53  m_engine.discard();
54  }
55 
57  __forceinline__ __device__ __host__ void discard_stride(unsigned long long int stride)
58  {
59  m_engine.discard_stride(stride);
60  }
61 
62  __forceinline__ __device__ __host__ unsigned long long int operator()()
63  {
64  return this->next();
65  }
66 
67  __forceinline__ __device__ __host__ unsigned long long int next()
68  {
69  unsigned long long int p = m_engine.next();
70  return p ^ scramble_constant;
71  }
72 
73  __forceinline__ __device__ __host__ unsigned long long int current()
74  {
75  unsigned long long int p = m_engine.current();
76  return p ^ scramble_constant;
77  }
78 
79  __forceinline__ __device__ __host__ static constexpr bool uses_shared_vectors()
80  {
81  return UseSharedVectors;
82  }
83 
84 protected:
85  // Underlying sobol64 engine
86  sobol64_engine<UseSharedVectors> m_engine;
87  // scrambling constant
88  unsigned long long int scramble_constant;
89 
90 }; // scrambled_sobol64_engine class
91 
92 } // end namespace rocrand_device
93 
100 typedef rocrand_device::scrambled_sobol64_engine<false> rocrand_state_scrambled_sobol64;
102 
114 __forceinline__ __device__ __host__ void
115  rocrand_init(const unsigned long long int* vectors,
116  const unsigned long long int scramble_constant,
117  const unsigned int offset,
118  rocrand_state_scrambled_sobol64* state)
119 {
120  *state = rocrand_state_scrambled_sobol64(vectors, scramble_constant, offset);
121 }
122 
135 __forceinline__ __device__ __host__ unsigned long long int
136  rocrand(rocrand_state_scrambled_sobol64* state)
137 {
138  return state->next();
139 }
140 
149 __forceinline__ __device__ __host__ void skipahead(unsigned long long offset,
150  rocrand_state_scrambled_sobol64* state)
151 {
152  return state->discard(offset);
153 }
154  // end of group rocranddevice
156 
157 #endif // ROCRAND_SCRAMBLED_SOBOL64_H_
__forceinline__ __device__ __host__ unsigned long long int rocrand(rocrand_state_scrambled_sobol64 *state)
Returns uniformly distributed random unsigned long long int value from [0; 2^64 - 1] range.
Definition: rocrand_scrambled_sobol64.h:136
__forceinline__ __device__ __host__ 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:149
__forceinline__ __device__ __host__ 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:115