cuda - 半 float 的 FLT_MAX

标签 cuda math.h half-precision-float

我正在使用 CUDA with half floats ,或 __half,因为它们在 CUDA 中被调用。

FLT_MAX 的半 float 是多少?

cuda_fp16.h header 似乎没有类似于此的宏。

$ grep MAX /usr/local/cuda-11.1/targets/x86_64-linux/include/cuda_fp16.h
$

最佳答案

我以前需要类似的宏(虽然不在 CUDA 中)并在 this C++ fp16 proposal for short floats 中找到了一些常量.

“S”前缀来自提议的“short” in short float。

// Smallest positive short float
#define SFLT_MIN 5.96046448e-08
// Smallest positive
// normalized short float
#define SFLT_NRM_MIN 6.10351562e-05
// Largest positive short float
#define SFLT_MAX 65504.0
// Smallest positive e
// for which (1.0 + e) != (1.0)
#define SFLT_EPSILON 0.00097656
// Number of digits in mantissa
// (significand + hidden leading 1)
#define SFLT_MANT_DIG 11
// Number of base 10 digits that
// can be represented without change
#define SFLT_DIG 2
// Base of the exponent
#define SFLT_RADIX 2
// Minimum negative integer such that
// HALF_RADIX raised to the power of
// one less than that integer is a
// normalized short float
#define SFLT_MIN_EXP -13
// Maximum positive integer such that
// HALF_RADIX raised to the power of
// one less than that integer is a
// normalized short float
#define SFLT_MAX_EXP 16
// Minimum positive integer such
// that 10 raised to that power is
// a normalized short float
#define SFLT_MIN_10_EXP -4
// Maximum positive integer such
// that 10 raised to that power is
// a normalized short float
#define SFLT_MAX_10_EXP 4

您还可以从 half.hpp library 中找到类似的常量.

注意:关于 fp16 文字,我不确定 CUDA 编译器支持什么。因此,您可能需要将这些转换为十六进制,将这些位重新解释为 __half(注意:注意转换/转换)。

这些都不是理想的,如果有人可以为您指出一些 cuda_fp16_limits.h 文件,那么支持这个答案而不是这个。

关于cuda - 半 float 的 FLT_MAX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64865685/

相关文章:

cuda - 原子 Add() 调用在 GTX 560 Ti 上安全吗?

c - 错误函数 erf(x),在 visual studio 2005 的 math.h 中找不到

tensorflow - 如何为您训练的模型选择半精度(BFLOAT16 与 FLOAT16)?

c++ - GNU ARM C++ 中未定义 __fp16 类型

swift - 用 16 位 float 填充 MTLBuffer

c++ - 当数据在设备中时,有什么方法可以将 thrust 与 cufftComplex 数据类型一起使用?

cuda - CUDA 在哪里为内核分配堆栈帧?

multithreading - 具有多(CPU)线程的多GPU编程

c - 如何在 C 中计算 pow()?

c - 在这种情况下 pow 函数如何工作?