aboutsummaryrefslogtreecommitdiff
path: root/util/random.cuh
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2021-11-29 10:09:43 +0800
committerKunoiSayami <[email protected]>2021-11-29 10:09:43 +0800
commit8126602f094fa6644ee109d7f8b49fa0a02b5451 (patch)
treec6d67ce671bb10f89f9e4ba9681731500584f86a /util/random.cuh
parent0e18a4800b0737dc8f1d3720bc79bf000529ddef (diff)
dump: 20211129
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'util/random.cuh')
-rw-r--r--util/random.cuh10
1 files changed, 5 insertions, 5 deletions
diff --git a/util/random.cuh b/util/random.cuh
index 95845f1..64eaadf 100644
--- a/util/random.cuh
+++ b/util/random.cuh
@@ -17,13 +17,13 @@ class Random {
uint32_t seed_;
public:
- __device__ explicit Random(uint32_t s) : seed_(s & 0x7fffffffu) {
+ __host__ __device__ explicit Random(uint32_t s) : seed_(s & 0x7fffffffu) {
// Avoid bad seeds.
if (seed_ == 0 || seed_ == 2147483647L) {
seed_ = 1;
}
}
- __device__ uint32_t Next() {
+ __host__ __device__ uint32_t Next() {
static const uint32_t M = 2147483647L; // 2^31-1
static const uint64_t A = 16807; // bits 14, 8, 7, 5, 2, 1, 0
// We are computing
@@ -46,16 +46,16 @@ class Random {
}
// Returns a uniformly distributed value in the range [0..n-1]
// REQUIRES: n > 0
- __device__ uint32_t Uniform(int n) { return Next() % n; }
+ __host__ __device__ uint32_t Uniform(int n) { return Next() % n; }
// Randomly returns true ~"1/n" of the time, and false otherwise.
// REQUIRES: n > 0
- __device__ bool OneIn(int n) { return (Next() % n) == 0; }
+ __host__ __device__ bool OneIn(int n) { return (Next() % n) == 0; }
// Skewed: pick "base" uniformly from range [0,max_log] and then
// return "base" random bits. The effect is to pick a number in the
// range [0,2^max_log-1] with exponential bias towards smaller numbers.
- __device__ uint32_t Skewed(int max_log) { return Uniform(1 << Uniform(max_log + 1)); }
+ __host__ __device__ uint32_t Skewed(int max_log) { return Uniform(1 << Uniform(max_log + 1)); }
};
} // namespace leveldb