Skip to main content
`Ctrl`+`K`

# /build/rocrand-D7zBeW/rocrand-7.2.4/library/include/rocrand/rocrand_threefry4x32_20.h Source File

API library: /build/rocrand-D7zBeW/rocrand-7.2.4/library/include/rocrand/rocrand_threefry4x32_20.h Source File
rocrand_threefry4x32_20.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/*
22 Copyright 2010-2011, D. E. Shaw Research.
23 All rights reserved.
24
25 Redistribution and use in source and binary forms, with or without
26 modification, are permitted provided that the following conditions are
27 met:
28
29* Redistributions of source code must retain the above copyright
30 notice, this list of conditions, and the following disclaimer.
31
32* Redistributions in binary form must reproduce the above copyright
33 notice, this list of conditions, and the following disclaimer in the
34 documentation and/or other materials provided with the distribution.
35
36* Neither the name of D. E. Shaw Research nor the names of its
37 contributors may be used to endorse or promote products derived from
38 this software without specific prior written permission.
39
40 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51*/
52
53#ifndef ROCRAND_THREEFRY4X32_20_H_
54#define ROCRAND_THREEFRY4X32_20_H_
55
56#include "rocrand/rocrand_threefry4_impl.h"
57
58#include <hip/hip_runtime.h>
59
60 namespace rocrand_device
61{
62
63 class threefry4x32_20_engine : public threefry_engine4_base<uint4, unsigned int, 20>
64{
65 public:
66 ROCRAND_DEPRECATED("Alias \"threefry4x32_20_state\" is deprecated. Use \"state_type\" instead.")
67 typedef threefry_engine4_base<uint4, unsigned int, 20>::threefry_state_4 threefry4x32_20_state;
68
74 __forceinline__ __device__ __host__ threefry4x32_20_engine(const unsigned long long seed = 0,
75 const unsigned long long subsequence
76 = 0,
77 const unsigned long long offset = 0)
78 {
79 this->seed(seed, subsequence, offset);
80 }
81
87 __forceinline__ __device__ __host__ void seed(const unsigned long long seed = 0,
88 const unsigned long long subsequence = 0,
89 const unsigned long long offset = 0)
90 {
91 m_state.counter = {0U, 0U, 0U, 0U};
92 m_state.result = {0U, 0U, 0U, 0U};
93 m_state.substate = 0;
94
95 m_state.key = {static_cast<unsigned int>(seed),
96 static_cast<unsigned int>(seed >> 16),
97 static_cast<unsigned int>(seed >> 32),
98 static_cast<unsigned int>(seed >> 48)};
99
100 this->discard_subsequence_impl(subsequence);
101 this->discard(offset);
102 m_state.result = this->threefry_rounds(m_state.counter, m_state.key);
103 }
104}; // threefry4x32_20_engine class
105
106} // end namespace rocrand_device
107
108 typedef rocrand_device::threefry4x32_20_engine rocrand_state_threefry4x32_20;
109
121__forceinline__ __device__ __host__
122 void rocrand_init(const unsigned long long seed,
123 const unsigned long long subsequence,
124 const unsigned long long offset,
125 rocrand_state_threefry4x32_20* state)
126{
127 *state = rocrand_state_threefry4x32_20(seed, subsequence, offset);
128}
129
144__forceinline__ __device__ __host__
145 unsigned int rocrand(rocrand_state_threefry4x32_20* state)
146{
147 return state->next();
148}
149
162__forceinline__ __device__ __host__
163uint4 rocrand4(rocrand_state_threefry4x32_20* state)
164{
165 return state->next4();
166}
167
168#endif // ROCRAND_THREEFRY4X32_20_H_
rocrand_init
__forceinline__ __device__ __host__ void rocrand_init(const uint4 seed, const unsigned int subsequence, rocrand_state_lfsr113 *state)
Initializes LFSR113 state.
Definition rocrand_lfsr113.h:239
rocrand4
__forceinline__ __device__ __host__ uint4 rocrand4(rocrand_state_philox4x32_10 *state)
Returns four uniformly distributed random unsigned int values from [0; 2^32 - 1] range.
Definition rocrand_philox4x32_10.h:377
rocrand
__forceinline__ __device__ __host__ unsigned int rocrand(rocrand_state_lfsr113 *state)
Returns uniformly distributed random unsigned int value from [0; 2^32 - 1] range.
Definition rocrand_lfsr113.h:277