Half precision (fp16) min and max limits in CUDA 9


I am trying to port Facebook’s FAISS to CUDA 9, and the biggest stumbling block seems to be the changes made to fp16 handling. One of the first problems is that it needs limits for each data type. For all conventional data types (int, fp32, etc), C++ numeric_limits max and min has sufficed. What is the recommended method to get limits for fp16? From within a device function call?


I had a similar problem.

I made my own class ‘NumericLimits’. For all data types except FP16, it takes for CPU code the respective limits from std::numeric_limits class, and for CUDA code it takes the respective limits from the pre-defined constants in the NPP library (NPP_MIN_8U, …).

For FP16, for the CPU you might take for CPU code the respective limits from the ‘half_float’ library (http://half.sourceforge.net/structstd_1_1numeric__limits_3_01half__float_1_1half_01_4.html), and for CUDA code you might need to define your own constants. I suppose you can use the same values as defined in the ‘half_float’ library, as the half data type is IEEE compliant.