/build/rocrand-sFFtDi/rocrand-10.0/library/include/rocrand/rocrand_scrambled_sobol64.h Source File

/build/rocrand-sFFtDi/rocrand-10.0/library/include/rocrand/rocrand_scrambled_sobol64.h Source File#

API library: /build/rocrand-sFFtDi/rocrand-10.0/library/include/rocrand/rocrand_scrambled_sobol64.h Source File
rocrand_scrambled_sobol64.h
1// Copyright (c) 2022-2026 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_sobol64.h"
25
26#include <hip/hip_runtime.h>
27
28namespace rocrand_device
29{
30
31template<bool UseSharedVectors>
32class scrambled_sobol64_engine
33{
34public:
35 __forceinline__ __device__ __host__
36 scrambled_sobol64_engine()
37 : scramble_constant()
38 {}
39
40 __forceinline__ __device__ __host__
41 scrambled_sobol64_engine(const unsigned long long int* vectors,
42 const unsigned long long int scramble_constant,
43 const unsigned long long int offset)
44 : m_engine(vectors, 0), scramble_constant(scramble_constant)
45 {
46 discard(offset);
47 }
48
50 __forceinline__ __device__ __host__
51 void discard(unsigned long long int offset)
52 {
53 m_engine.discard(offset);
54 }
55
56 __forceinline__ __device__ __host__
57 void discard()
58 {
59 m_engine.discard();
60 }
61
63 __forceinline__ __device__ __host__
64 void discard_stride(unsigned long long int stride)
65 {
66 m_engine.discard_stride(stride);
67 }
68
69 __forceinline__ __device__ __host__
70 unsigned long long int operator()()
71 {
72 return this->next();
73 }
74
75 __forceinline__ __device__ __host__
76 unsigned long long int next()
77 {
78 unsigned long long int p = m_engine.next();
79 return p ^ scramble_constant;
80 }
81
82 __forceinline__ __device__ __host__
83 unsigned long long int current()
84 {
85 unsigned long long int p = m_engine.current();
86 return p ^ scramble_constant;
87 }
88
89 __forceinline__ __device__ __host__
90 static constexpr bool uses_shared_vectors()
91 {
92 return UseSharedVectors;
93 }
94
95protected:
96 // Underlying sobol64 engine
97 sobol64_engine<UseSharedVectors> m_engine;
98 // scrambling constant
99 unsigned long long int scramble_constant;
100
101}; // scrambled_sobol64_engine class
102
103} // end namespace rocrand_device
104
109
111typedef rocrand_device::scrambled_sobol64_engine<false> rocrand_state_scrambled_sobol64;
113
125__forceinline__ __device__ __host__
126void rocrand_init(const unsigned long long int* vectors,
127 const unsigned long long int scramble_constant,
128 const unsigned long long int offset,
129 rocrand_state_scrambled_sobol64* state)
130{
131 *state = rocrand_state_scrambled_sobol64(vectors, scramble_constant, offset);
132}
133
146__forceinline__ __device__ __host__
147unsigned long long int rocrand(rocrand_state_scrambled_sobol64* state)
148{
149 return state->next();
150}
151
160__forceinline__ __device__ __host__
161void skipahead(unsigned long long offset, rocrand_state_scrambled_sobol64* state)
162{
163 return state->discard(offset);
164}
165 // end of group rocranddevice
167
168#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:147
__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:161
__forceinline__ __device__ __host__ void rocrand_init(const unsigned long long int *vectors, const unsigned long long int scramble_constant, const unsigned long long int offset, rocrand_state_scrambled_sobol64 *state)
Initialize scrambled_sobol64 state.
Definition rocrand_scrambled_sobol64.h:126