Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Way to get floating-point special values in CUDA?

Is there any device functions in CUDA to obtain IEEE 754 special values like inf, NaN? I mean the stable way, not by some maths ops that could be optimized-out by compilers.

I only manage to find a device function called nan() that must take some unknown string argument.

like image 626
user0002128 Avatar asked Mar 20 '13 02:03

user0002128


People also ask

Does Cuda support double precision?

The numerical capabilities are encoded in the compute capability number of your GPU. Devices of compute capability 2.0 and later are capable of single and double precision arithmetic following the IEEE 754 standard, and have hardware units for performing fused multiply-add in both single and double precision.

What is GPU double precision?

Many applications require higher-accuracy mathematical calculations. In these applications, data is represented by values that are twice as large (using 64 binary bits instead of 32 bits). These larger values are called double-precision (64-bit). Less accurate values are called single-precision (32-bit).

How do you do Cuda in math?

Available to any CUDA C or CUDA C++ application simply by adding “#include math. h” in your source code, the CUDA Math library ensures that your application benefits from high performance math routines optimized for every NVIDIA GPU architecture.


1 Answers

How about CUDART_NAN (double) and CUDART_NAN_F (float) defined in /usr/local/cuda/include/math_constants.h :

#define CUDART_NAN_F            __int_as_float(0x7fffffff)
#define CUDART_NAN              __longlong_as_double(0xfff8000000000000ULL)

and:

#define CUDART_INF_F            __int_as_float(0x7f800000)
#define CUDART_INF              __longlong_as_double(0x7ff0000000000000ULL)
like image 83
Robert Crovella Avatar answered Sep 27 '22 22:09

Robert Crovella