ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnfw::cker::random::PhiloxRandom Class Reference

#include <PhiloxRandom.h>

Public Types

using ResultType = Array< uint32_t, 4 >
 
using ResultElementType = uint32_t
 
using Key = Array< uint32_t, 2 >
 

Public Member Functions

PHILOX_DEVICE_INLINE PhiloxRandom ()
 
PHILOX_DEVICE_INLINE PhiloxRandom (uint64_t seed)
 
PHILOX_DEVICE_INLINE PhiloxRandom (uint64_t seed_lo, uint64_t seed_hi)
 
PHILOX_DEVICE_INLINE PhiloxRandom (ResultType counter, Key key)
 
PHILOX_DEVICE_INLINE ResultType const & counter () const
 
PHILOX_DEVICE_INLINE Key const & key () const
 
PHILOX_DEVICE_INLINE void Skip (uint64_t count)
 
PHILOX_DEVICE_INLINE ResultType operator() ()
 

Static Public Attributes

static constexpr int kResultElementCount = 4
 
static constexpr int kElementCost = 10
 

Detailed Description

Definition at line 107 of file PhiloxRandom.h.

Member Typedef Documentation

◆ Key

Definition at line 118 of file PhiloxRandom.h.

◆ ResultElementType

Definition at line 111 of file PhiloxRandom.h.

◆ ResultType

Definition at line 110 of file PhiloxRandom.h.

Constructor & Destructor Documentation

◆ PhiloxRandom() [1/4]

PHILOX_DEVICE_INLINE nnfw::cker::random::PhiloxRandom::PhiloxRandom ( )
inline

Definition at line 121 of file PhiloxRandom.h.

121{}

◆ PhiloxRandom() [2/4]

PHILOX_DEVICE_INLINE nnfw::cker::random::PhiloxRandom::PhiloxRandom ( uint64_t  seed)
inlineexplicit

Definition at line 124 of file PhiloxRandom.h.

125 {
126 key_[0] = static_cast<uint32_t>(seed);
127 key_[1] = static_cast<uint32_t>(seed >> 32);
128 }

◆ PhiloxRandom() [3/4]

PHILOX_DEVICE_INLINE nnfw::cker::random::PhiloxRandom::PhiloxRandom ( uint64_t  seed_lo,
uint64_t  seed_hi 
)
inlineexplicit

Definition at line 131 of file PhiloxRandom.h.

132 {
133 key_[0] = static_cast<uint32_t>(seed_lo);
134 key_[1] = static_cast<uint32_t>(seed_lo >> 32);
135 counter_[2] = static_cast<uint32_t>(seed_hi);
136 counter_[3] = static_cast<uint32_t>(seed_hi >> 32);
137 }

◆ PhiloxRandom() [4/4]

PHILOX_DEVICE_INLINE nnfw::cker::random::PhiloxRandom::PhiloxRandom ( ResultType  counter,
Key  key 
)
inline

Definition at line 140 of file PhiloxRandom.h.

140: counter_(counter), key_(key) {}
PHILOX_DEVICE_INLINE Key const & key() const
PHILOX_DEVICE_INLINE ResultType const & counter() const

Member Function Documentation

◆ counter()

PHILOX_DEVICE_INLINE ResultType const & nnfw::cker::random::PhiloxRandom::counter ( ) const
inline

Definition at line 143 of file PhiloxRandom.h.

143{ return counter_; }

Referenced by operator()().

◆ key()

PHILOX_DEVICE_INLINE Key const & nnfw::cker::random::PhiloxRandom::key ( ) const
inline

Definition at line 146 of file PhiloxRandom.h.

146{ return key_; }

Referenced by operator()().

◆ operator()()

PHILOX_DEVICE_INLINE ResultType nnfw::cker::random::PhiloxRandom::operator() ( )
inline

Definition at line 173 of file PhiloxRandom.h.

174 {
175 ResultType counter = counter_;
176 Key key = key_;
177
178 // Run the single rounds for ten times. Manually unrolling the loop
179 // for better performance.
180 counter = ComputeSingleRound(counter, key);
181 RaiseKey(&key);
182 counter = ComputeSingleRound(counter, key);
183 RaiseKey(&key);
184 counter = ComputeSingleRound(counter, key);
185 RaiseKey(&key);
186 counter = ComputeSingleRound(counter, key);
187 RaiseKey(&key);
188 counter = ComputeSingleRound(counter, key);
189 RaiseKey(&key);
190 counter = ComputeSingleRound(counter, key);
191 RaiseKey(&key);
192 counter = ComputeSingleRound(counter, key);
193 RaiseKey(&key);
194 counter = ComputeSingleRound(counter, key);
195 RaiseKey(&key);
196 counter = ComputeSingleRound(counter, key);
197 RaiseKey(&key);
198 counter = ComputeSingleRound(counter, key);
199
200 SkipOne();
201
202 return counter;
203 }
Array< uint32_t, 4 > ResultType

References counter(), and key().

◆ Skip()

PHILOX_DEVICE_INLINE void nnfw::cker::random::PhiloxRandom::Skip ( uint64_t  count)
inline

Definition at line 150 of file PhiloxRandom.h.

151 {
152 const uint32_t count_lo = static_cast<uint32_t>(count);
153 uint32_t count_hi = static_cast<uint32_t>(count >> 32);
154
155 counter_[0] += count_lo;
156 if (counter_[0] < count_lo)
157 {
158 ++count_hi;
159 }
160
161 counter_[1] += count_hi;
162 if (counter_[1] < count_hi)
163 {
164 if (++counter_[2] == 0)
165 {
166 ++counter_[3];
167 }
168 }
169 }

Referenced by nnfw::cker::functor::FillPhiloxRandomTask< Distribution, true >::Run(), and nnfw::cker::functor::FillPhiloxRandomTask< Distribution, false >::Run().

Field Documentation

◆ kElementCost

constexpr int nnfw::cker::random::PhiloxRandom::kElementCost = 10
staticconstexpr

Definition at line 115 of file PhiloxRandom.h.

◆ kResultElementCount

constexpr int nnfw::cker::random::PhiloxRandom::kResultElementCount = 4
staticconstexpr

The documentation for this class was generated from the following file: