CUDA中的半精度浮点数 [英] Half precision floating points in CUDA

查看:1899
本文介绍了CUDA中的半精度浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CUDA中有半精度浮点数吗?

Is there anything as half precision floating points in CUDA?

背景:我想使用glTexSubImage3D操作opengl纹理,使用CUDA生成的PBO数据。纹理存储在GL_INTENSITY16格式(这是一个半精度浮动类型afaik),我不想使用glPixelTransferf(GL_x_SCALE,...)从整数值进行缩放,因为它似乎要快得多,没有缩放。

Background: I want to manipulate an opengl texture using glTexSubImage3D with data from a PBO which I generate using CUDA. The texture is stored in GL_INTENSITY16 format (which is a half precision floating type afaik) and I dont want to use glPixelTransferf(GL_x_SCALE,...) to scale from integer values since it seems to be much faster without the scaling.

任何建议?

推荐答案

CUDA只支持32位和64位浮点精度类型。

CUDA only natively supports 32 and 64 bit floating precision types.

驱动程序和运行时API都支持绑定到半浮动纹理,但是内核中读取的结果将返回提升为32位浮点数的值。 CUDA标准库包括 __ half2float() __ float2half_rn()用于在半精度和单精度浮点类型之间转换的函数半浮点存储在16位整数)。因此,可能可以在使用16位类型进行读取和写入的32位精度内核中进行操作。但是对于原生的16位浮点数,我认为你运气不好。

Both driver and runtime APIs support binding to half float textures, but the resulting read inside the kernel will return the value promoted to a 32 bit floating point number. The CUDA standard libraries include __half2float() and __float2half_rn() functions for converting between half and single precision floating point types (the half float stored in a 16 bit integer). So it might be possible to do the manipulation in 32 bit precision kernels with reads and writes done using 16 bit types. But for native 16 bit floating point, I think you are out of luck.

使用CUDA 7.5工具包通过添加一半 half2 类型和内在函数来处理扩展半精度浮点支持。它还宣布(尚未发布)Pascal架构将支持符合IEE754-2008硬件半精度操作。

EDIT to add that in 2015, NVIDIA extended half precision floating point support with the CUDA 7.5 toolkit by added half and half2 types and intrinsic functions to handle them. It has also been announced that (not yet released) Pascal architecture will support IEE754-2008 compliant half precision operations in hardware.

这篇关于CUDA中的半精度浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆