/build/rocrand-7S8maf/rocrand-7.1.1/library/include/rocrand/rocrand_scrambled_sobol64.h Source File

/build/rocrand-7S8maf/rocrand-7.1.1/library/include/rocrand/rocrand_scrambled_sobol64.h Source File#

API library: /build/rocrand-7S8maf/rocrand-7.1.1/library/include/rocrand/rocrand_scrambled_sobol64.h Source File
rocrand_scrambled_sobol64.h
1// Copyright (c) 2022-2025 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__ scrambled_sobol64_engine() : scramble_constant() {}
36
37 __forceinline__ __device__ __host__
38 scrambled_sobol64_engine(const unsigned long long int* vectors,
39 const unsigned long long int scramble_constant,
40 const unsigned int offset)
41 : m_engine(vectors, 0), scramble_constant(scramble_constant)
42 {
43 discard(offset);
44 }
45
47 __forceinline__ __device__ __host__ void discard(unsigned long long int offset)
48 {
49 m_engine.discard(offset);
50 }
51
52 __forceinline__ __device__ __host__ void discard()
53 {
54 m_engine.discard();
55 }
56
58 __forceinline__ __device__ __host__ void discard_stride(unsigned long long int stride)
59 {
60 m_engine.discard_stride(stride);
61 }
62
63 __forceinline__ __device__ __host__ unsigned long long int operator()()
64 {
65 return this->next();
66 }
67
68 __forceinline__ __device__ __host__ unsigned long long int next()
69 {
70 unsigned long long int p = m_engine.next();
71 return p ^ scramble_constant;
72 }
73
74 __forceinline__ __device__ __host__ unsigned long long int current()
75 {
76 unsigned long long int p = m_engine.current();
77 return p ^ scramble_constant;
78 }
79
80 __forceinline__ __device__ __host__ static constexpr bool uses_shared_vectors()
81 {
82 return UseSharedVectors;
83 }
84
85protected:
86 // Underlying sobol64 engine
87 sobol64_engine<UseSharedVectors> m_engine;
88 // scrambling constant
89 unsigned long long int scramble_constant;
90
91}; // scrambled_sobol64_engine class
92
93} // end namespace rocrand_device
94
99
101typedef rocrand_device::scrambled_sobol64_engine<false> rocrand_state_scrambled_sobol64;
103
115__forceinline__ __device__ __host__
116void rocrand_init(const unsigned long long int* vectors,
117 const unsigned long long int scramble_constant,
118 const unsigned int offset,
119 rocrand_state_scrambled_sobol64* state)
120{
121 *state = rocrand_state_scrambled_sobol64(vectors, scramble_constant, offset);
122}
123
136__forceinline__ __device__ __host__
137unsigned long long int rocrand(rocrand_state_scrambled_sobol64* state)
138{
139 return state->next();
140}
141
150__forceinline__ __device__ __host__
151void skipahead(unsigned long long offset, rocrand_state_scrambled_sobol64* state)
152{
153 return state->discard(offset);
154}
155 // end of group rocranddevice
157
158#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:137
__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:151
__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:116