21 #ifndef ROCRAND_COMMON_H_ 
   22 #define ROCRAND_COMMON_H_ 
   24 #define ROCRAND_2POW16_INV (1.5258789e-05f) 
   25 #define ROCRAND_2POW16_INV_2PI (9.58738e-05f) 
   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 (1.46291807e-09f) 
   31 #define ROCRAND_2POW53_INV_DOUBLE (1.1102230246251565e-16) 
   32 #define ROCRAND_PI (3.141592653f) 
   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) 
   38 #include <hip/hip_runtime.h> 
   41 #define ROCRAND_KERNEL __global__ static 
   43 #if __HIP_DEVICE_COMPILE__            \ 
   44     && (defined(__HIP_PLATFORM_AMD__) \ 
   45         || (defined(__HIP_PLATFORM_NVCC__) && (__CUDA_ARCH__ >= 530))) 
   46     #define ROCRAND_HALF_MATH_SUPPORTED 
   57 #define ROCRAND_STRINGIZE(X) ROCRAND_DO_STRINGIZE(X) 
   58 #define ROCRAND_DO_STRINGIZE(X) #X 
   69 #if defined(__INTEL_COMPILER) 
   70     #define ROCRAND_PRAGMA_MESSAGE(x) \ 
   71         __pragma(message(__FILE__ "(" ROCRAND_STRINGIZE(__LINE__) "): note: " x))
 
   72 #elif defined(__GNUC__) 
   73     #define ROCRAND_PRAGMA_MESSAGE(x) _Pragma(ROCRAND_STRINGIZE(message(x))) 
   74 #elif defined(_MSC_VER) 
   75     #define ROCRAND_PRAGMA_MESSAGE(x) \ 
   76         __pragma(message(__FILE__ "(" ROCRAND_STRINGIZE(__LINE__) "): note: " x))
 
   78     #define ROCRAND_PRAGMA_MESSAGE(x) 
   81 #if __cplusplus >= 201402L 
   82     #define ROCRAND_DEPRECATED(msg) [[deprecated(msg)]] 
   83 #elif defined(_MSC_VER) && !defined(__clang__) 
   84     #define ROCRAND_DEPRECATED(msg) __declspec(deprecated(msg)) 
   85 #elif defined(__clang__) || defined(__GNUC__) 
   86     #define ROCRAND_DEPRECATED(msg) __attribute__((deprecated(msg))) 
   88     #define ROCRAND_DEPRECATED(msg) 
  109 #if defined(__HIP_PLATFORM_AMD__) 
  110     #if HIP_VERSION_MAJOR < 7 
  111         #define ROCRAND_HIPVEC_ACCESS(x) x.data 
  113         #define ROCRAND_HIPVEC_ACCESS(x) x 
  117 namespace rocrand_device {
 
  120 __forceinline__ __device__ __host__
 
  122     mad_u64_u32(
const unsigned int x, 
const unsigned int y, 
const unsigned long long z)
 
  124     return static_cast<unsigned long long>(x) * 
static_cast<unsigned long long>(y) + z;
 
  127 __forceinline__ __device__ __host__
 
  128 unsigned long long mul_u64_u32(
const unsigned int x, 
const unsigned int y)
 
  130     return static_cast<unsigned long long>(x) * 
static_cast<unsigned long long>(y);
 
  135 template<
typename Engine>
 
  136 struct engine_boxmuller_helper
 
  138     static __forceinline__ __device__ __host__ 
bool has_float(
const Engine* engine)
 
  140         return engine->m_state.boxmuller_float_state != 0;
 
  143     static __forceinline__ __device__ __host__ 
float get_float(Engine* engine)
 
  145         engine->m_state.boxmuller_float_state = 0;
 
  146         return engine->m_state.boxmuller_float;
 
  149     static __forceinline__ __device__ __host__ 
void save_float(Engine* engine, 
float f)
 
  151         engine->m_state.boxmuller_float_state = 1;
 
  152         engine->m_state.boxmuller_float = f;
 
  155     static __forceinline__ __device__ __host__ 
bool has_double(
const Engine* engine)
 
  157         return engine->m_state.boxmuller_double_state != 0;
 
  160     static __forceinline__ __device__ __host__ 
float get_double(Engine* engine)
 
  162         engine->m_state.boxmuller_double_state = 0;
 
  163         return engine->m_state.boxmuller_double;
 
  166     static __forceinline__ __device__ __host__ 
void save_double(Engine* engine, 
double d)
 
  168         engine->m_state.boxmuller_double_state = 1;
 
  169         engine->m_state.boxmuller_double = d;
 
  174 __forceinline__ __device__ __host__ 
void split_ull(T& lo, T& hi, 
unsigned long long int val);
 
  177 __forceinline__ __device__ __host__ 
void 
  178     split_ull(
unsigned int& lo, 
unsigned int& hi, 
unsigned long long int val)
 
  180     lo = val & 0xFFFFFFFF;
 
  181     hi = (val >> 32) & 0xFFFFFFFF;
 
  185 __forceinline__ __device__ __host__ 
void 
  186     split_ull(
unsigned long long int& lo, 
unsigned long long int& hi, 
unsigned long long int val)