21 #ifndef ROCRAND_COMMON_H_
22 #define ROCRAND_COMMON_H_
24 #define ROCRAND_2POW16_INV (1.5258789e-05f)
25 #define ROCRAND_2POW16_INV_2PI (1.5258789e-05f * 6.2831855f)
26 #define ROCRAND_2POW32_INV (2.3283064e-10f)
27 #define ROCRAND_2POW32_INV_DOUBLE (2.3283064365386963e-10)
28 #define ROCRAND_2POW64_INV (5.4210109e-20f)
29 #define ROCRAND_2POW64_INV_DOUBLE (5.4210108624275221700372640043497e-20)
30 #define ROCRAND_2POW32_INV_2PI (2.3283064e-10f * 6.2831855f)
31 #define ROCRAND_2POW53_INV_DOUBLE (1.1102230246251565e-16)
32 #define ROCRAND_PI (3.1415926f)
33 #define ROCRAND_PI_DOUBLE (3.1415926535897932)
34 #define ROCRAND_2PI (6.2831855f)
35 #define ROCRAND_SQRT2 (1.4142135f)
36 #define ROCRAND_SQRT2_DOUBLE (1.4142135623730951)
40 #define ROCRAND_KERNEL __global__ static
43 #define FQUALIFIERS __forceinline__ __device__
46 #if __HIP_DEVICE_COMPILE__ \
47 && (defined(__HIP_PLATFORM_AMD__) \
48 || (defined(__HIP_PLATFORM_NVCC__) && (__CUDA_ARCH__ >= 530)))
49 #define ROCRAND_HALF_MATH_SUPPORTED
52 namespace rocrand_device {
55 #if ( defined(__HIP_PLATFORM_NVCC__) || \
56 defined(__gfx801__) || \
57 defined(__gfx802__) || \
58 defined(__gfx803__) || \
59 defined(__gfx810__) || \
60 defined(__gfx900__) || \
61 defined(__gfx902__) || \
62 defined(__gfx904__) || \
63 defined(__gfx906__) || \
64 defined(__gfx908__) || \
65 defined(__gfx909__) || \
66 defined(__gfx1030__) )
67 #if !defined(ROCRAND_ENABLE_INLINE_ASM)
68 #define ROCRAND_ENABLE_INLINE_ASM
71 #if defined(__HIP_DEVICE_COMPILE__) && defined(ROCRAND_ENABLE_INLINE_ASM)
72 #undef ROCRAND_ENABLE_INLINE_ASM
77 unsigned long long mad_u64_u32(
const unsigned int x,
const unsigned int y,
const unsigned long long z)
79 #if defined(__HIP_PLATFORM_AMD__) && defined(__HIP_DEVICE_COMPILE__) \
80 && defined(ROCRAND_ENABLE_INLINE_ASM)
82 #if __AMDGCN_WAVEFRONT_SIZE == 64u
83 using sgpr_t =
unsigned long long;
84 #elif __AMDGCN_WAVEFRONT_SIZE == 32u
85 using sgpr_t =
unsigned int;
94 asm volatile(
"v_mad_u64_u32 %0, %1, %2, %3, %4"
95 :
"=v"(r),
"=s"(c) :
"r"(x),
"v"(y),
"v"(z)
98 #elif defined(__HIP_PLATFORM_NVCC__) && defined(__HIP_DEVICE_COMPILE__) \
99 && defined(ROCRAND_ENABLE_INLINE_ASM)
101 unsigned long long r;
102 asm(
"mad.wide.u32 %0, %1, %2, %3;"
103 :
"=l"(r) :
"r"(x),
"r"(y),
"l"(z)
109 return static_cast<unsigned long long>(x) *
static_cast<unsigned long long>(y) + z;
116 template<
typename Engine>
117 struct engine_boxmuller_helper
120 bool has_float(
const Engine * engine)
122 return engine->m_state.boxmuller_float_state != 0;
126 float get_float(Engine * engine)
128 engine->m_state.boxmuller_float_state = 0;
129 return engine->m_state.boxmuller_float;
133 void save_float(Engine * engine,
float f)
135 engine->m_state.boxmuller_float_state = 1;
136 engine->m_state.boxmuller_float = f;
140 bool has_double(
const Engine * engine)
142 return engine->m_state.boxmuller_double_state != 0;
146 float get_double(Engine * engine)
148 engine->m_state.boxmuller_double_state = 0;
149 return engine->m_state.boxmuller_double;
153 void save_double(Engine * engine,
double d)
155 engine->m_state.boxmuller_double_state = 1;
156 engine->m_state.boxmuller_double = d;
161 FQUALIFIERS void split_ull(T& lo, T& hi,
unsigned long long int val);
164 FQUALIFIERS void split_ull(
unsigned int& lo,
unsigned int& hi,
unsigned long long int val)
166 lo = val & 0xFFFFFFFF;
167 hi = (val >> 32) & 0xFFFFFFFF;
172 split_ull(
unsigned long long int& lo,
unsigned long long int& hi,
unsigned long long int val)
#define FQUALIFIERS
Shorthand for commonly used function qualifiers.
Definition: rocrand_uniform.h:31