5.4. Bfloat16 数学函数

要使用这些函数,请在程序中包含头文件 cuda_bf16.h

函数

__device__ __nv_bfloat16 hceil(const __nv_bfloat16 h)

计算输入参数的 ceiling(上限值)。

__device__ __nv_bfloat16 hcos(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 余弦值。

__device__ __nv_bfloat16 hexp(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 自然指数函数。

__device__ __nv_bfloat16 hexp10(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 十进制指数函数。

__device__ __nv_bfloat16 hexp2(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 二进制指数函数。

__device__ __nv_bfloat16 hfloor(const __nv_bfloat16 h)

计算小于或等于 h 的最大整数。

__device__ __nv_bfloat16 hlog(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 自然对数。

__device__ __nv_bfloat16 hlog10(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 十进制对数。

__device__ __nv_bfloat16 hlog2(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 二进制对数。

__device__ __nv_bfloat16 hrcp(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 倒数。

__device__ __nv_bfloat16 hrint(const __nv_bfloat16 h)

将输入舍入为最接近的整数值(nv_bfloat16 浮点数)。

__device__ __nv_bfloat16 hrsqrt(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 倒数平方根。

__device__ __nv_bfloat16 hsin(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 正弦值。

__device__ __nv_bfloat16 hsqrt(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 平方根。

__device__ __nv_bfloat16 htanh(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 双曲正切函数。

__device__ __nv_bfloat16 htanh_approx(const __nv_bfloat16 a)

计算近似的 nv_bfloat16 双曲正切函数。

__device__ __nv_bfloat16 htrunc(const __nv_bfloat16 h)

将输入参数截断为整数部分。

5.4.1. 函数

__device__ __nv_bfloat16 hceil(const __nv_bfloat16 h)

计算输入参数的 ceiling(上限值)。

计算不小于 h 的最小整数值。

参数

h[in] - nv_bfloat16。仅为读取。

返回值

nv_bfloat16

  • 不小于 h 的最小整数值。

__device__ __nv_bfloat16 hcos(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 余弦值。

以 round-to-nearest-even 模式计算输入 anv_bfloat16 余弦值。

注意:此函数的实现调用了 cosf(float) 函数,并会受到编译器优化的影响。具体来说,--use_fast_math 标志会将 cosf(float) 转换为内联函数 __cosf(float),后者的数值行为精度较低。

参数

a[in] - nv_bfloat16。仅为读取。

返回值

nv_bfloat16

  • a 的余弦值。

__device__ __nv_bfloat16 hexp(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 自然指数函数。

以 round-to-nearest-even 模式计算输入 anv_bfloat16 自然指数函数。

参数

a[in] - nv_bfloat16。仅为读取。

返回值

nv_bfloat16

  • a 的自然指数函数。

__device__ __nv_bfloat16 hexp10(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 十进制指数函数。

以 round-to-nearest-even 模式计算输入 anv_bfloat16 十进制指数函数。

参数

a[in] - nv_bfloat16。仅为读取。

返回值

nv_bfloat16

  • a 的十进制指数函数。

__device__ __nv_bfloat16 hexp2(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 二进制指数函数。

以 round-to-nearest-even 模式计算输入 anv_bfloat16 二进制指数函数。

参数

a[in] - nv_bfloat16。仅为读取。

返回值

nv_bfloat16

  • a 的二进制指数函数。

__device__ __nv_bfloat16 hfloor(const __nv_bfloat16 h)

计算小于或等于 h 的最大整数。

计算小于或等于 h 的最大整数值。

参数

h[in] - nv_bfloat16。仅为读取。

返回值

nv_bfloat16

  • 小于或等于 h 的最大整数值。

__device__ __nv_bfloat16 hlog(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 自然对数。

以 round-to-nearest-even 模式计算输入 anv_bfloat16 自然对数。

参数

a[in] - nv_bfloat16。仅为读取。

返回值

nv_bfloat16

  • a 的自然对数。

__device__ __nv_bfloat16 hlog10(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 十进制对数。

以 round-to-nearest-even 模式计算输入 anv_bfloat16 十进制对数。

参数

a[in] - nv_bfloat16。仅为读取。

返回值

nv_bfloat16

  • a 的十进制对数。

__device__ __nv_bfloat16 hlog2(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 二进制对数。

以 round-to-nearest-even 模式计算输入 anv_bfloat16 二进制对数。

参数

a[in] - nv_bfloat16。仅为读取。

返回值

nv_bfloat16

  • a 的二进制对数。

__device__ __nv_bfloat16 hrcp(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 倒数。

以 round-to-nearest-even 模式计算输入 anv_bfloat16 倒数。

参数

a[in] - nv_bfloat16。仅为读取。

返回值

nv_bfloat16

  • a 的倒数。

__device__ __nv_bfloat16 hrint(const __nv_bfloat16 h)

将输入舍入为最接近的整数值(nv_bfloat16 浮点数)。

h 舍入为最接近的整数值(nv_bfloat16 浮点格式),bfloat16way 的情况舍入为最接近的偶数整数值。

参数

h[in] - nv_bfloat16。仅为读取。

返回值

nv_bfloat16

  • h 最接近的整数。

__device__ __nv_bfloat16 hrsqrt(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 倒数平方根。

以 round-to-nearest-even 模式计算输入 anv_bfloat16 倒数平方根。

参数

a[in] - nv_bfloat16。仅为读取。

返回值

nv_bfloat16

  • a 的倒数平方根。

__device__ __nv_bfloat16 hsin(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 正弦值。

以 round-to-nearest-even 模式计算输入 anv_bfloat16 正弦值。

注意:此函数的实现调用了 sinf(float) 函数,并会受到编译器优化的影响。具体来说,--use_fast_math 标志会将 sinf(float) 转换为内联函数 __sinf(float),后者的数值行为精度较低。

参数

a[in] - nv_bfloat16。仅为读取。

返回值

nv_bfloat16

  • a 的正弦值。

__device__ __nv_bfloat16 hsqrt(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 平方根。

以 round-to-nearest-even 模式计算输入 anv_bfloat16 平方根。

参数

a[in] - nv_bfloat16。仅为读取。

返回值

nv_bfloat16

  • a 的平方根。

__device__ __nv_bfloat16 htanh(const __nv_bfloat16 a)

以 round-to-nearest-even 模式计算 nv_bfloat16 双曲正切函数。

以 round-to-nearest-even 模式计算 nv_bfloat16 双曲正切函数:\( \tanh(a)\)

参数

a[in] - nv_bfloat16。仅为读取。

返回值

nv_bfloat16

  • a 的双曲正切函数。

  • htanh \( (\pm 0)\) 返回 \( (\pm 0)\)

  • htanh \( (\pm\infty)\) 返回 \( (\pm 1)\)

  • htanh(NaN) 返回 NaN。

__device__ __nv_bfloat16 htanh_approx(const __nv_bfloat16 a)

计算近似的 nv_bfloat16 双曲正切函数。

计算近似的 nv_bfloat16 双曲正切函数:\( \tanh(a)\)。此操作在计算能力为 9.x 及更高版本的设备上使用硬件加速。

参数

a[in] - nv_bfloat16。仅为读取。

返回值

nv_bfloat16

  • a 的近似双曲正切函数。

  • htanh_approx \( (\pm 0)\) 返回 \( (\pm 0)\)

  • htanh_approx \( (\pm\infty)\) 返回 \( (\pm 1)\)

  • htanh_approx(NaN) 返回 NaN。

__device__ __nv_bfloat16 htrunc(const __nv_bfloat16 h)

将输入参数截断为整数部分。

h 舍入为最接近的整数值,该值在幅度上不超过 h

参数

h[in] - nv_bfloat16。仅为读取。

返回值

nv_bfloat16

  • 截断的整数值。