cuda - 半浮点数的 FLT_MAX
问题描述
我正在使用带有半浮点数的 CUDA,或者__half
在 CUDA 中调用它们。
半浮点数相当于FLT_MAX
多少?
标cuda_fp16.h
头似乎没有类似的宏。
$ grep MAX /usr/local/cuda-11.1/targets/x86_64-linux/include/cuda_fp16.h
$
解决方案
我以前需要一次类似的宏(虽然不是在 CUDA 中),并在这个 C++ fp16 提案中找到了一些用于short floats的常量。
“S”前缀来自建议的短浮点数“short”。
// 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 库中找到类似的常量。
注意:我不确定 CUDA 编译器在 fp16 文字方面支持什么。因此,您可能需要将这些转换为十六进制,将这些位重新解释为 __half(注意:注意转换/转换)。
这些都不是理想的,如果有人可以将您指向某个cuda_fp16_limits.h
文件,那么请选择这个答案而不是这个答案。
推荐阅读
- python-3.x - 在 Django 模板上显示查询集结果而不使用 django 模型
- javascript - jQuery 选择器和不同类型的 href 链接 - 为链接添加正确的 CSS 类
- c# - 匹配参数的可空性和返回类型的泛型类型参数
- javascript - 如何在下拉列表中填充来自后端的数据并在 Angular 中选择值?
- java - 如何在firestore android studio中获取新添加数据的通知?
- c# - 平铺对象位置与 MonoGame 位置不匹配
- emacs - Emacs 中的“向后相同语法”
- python - OS Mojave 中的 tkinter 8.6 系统崩溃错误是否已在 mac OS Catalina 中修复?
- vue.js - 将 axios 全球化为 vue 项目中的 API 包装器
- angular - 使用指令将参数传递给子组件角度