1.2.6. Bfloat16 Math Functions

[Bfloat16 Precision Intrinsics]

To use these functions, include the header file cuda_bf16.h in your program.

Functions

__device__ ​ __nv_bfloat16 atomicAdd ( const __nv_bfloat16* address, const __nv_bfloat16 val )
Adds val to the value stored at address in global or shared memory, and writes this value back to address. This operation is performed in one atomic operation.
__device__ ​ __nv_bfloat16 hceil ( const __nv_bfloat16 h )
Calculate ceiling of the input argument.
__device__ ​ __nv_bfloat16 hcos ( const __nv_bfloat16 a )
Calculates nv_bfloat16 cosine in round-to-nearest-even mode.
__device__ ​ __nv_bfloat16 hexp ( const __nv_bfloat16 a )
Calculates nv_bfloat16 natural exponential function in round-to-nearest mode.
__device__ ​ __nv_bfloat16 hexp10 ( const __nv_bfloat16 a )
Calculates nv_bfloat16 decimal exponential function in round-to-nearest mode.
__device__ ​ __nv_bfloat16 hexp2 ( const __nv_bfloat16 a )
Calculates nv_bfloat16 binary exponential function in round-to-nearest mode.
__device__ ​ __nv_bfloat16 hfloor ( const __nv_bfloat16 h )
Calculate the largest integer less than or equal to h.
__device__ ​ __nv_bfloat16 hlog ( const __nv_bfloat16 a )
Calculates nv_bfloat16 natural logarithm in round-to-nearest-even mode.
__device__ ​ __nv_bfloat16 hlog10 ( const __nv_bfloat16 a )
Calculates nv_bfloat16 decimal logarithm in round-to-nearest-even mode.
__device__ ​ __nv_bfloat16 hlog2 ( const __nv_bfloat16 a )
Calculates nv_bfloat16 binary logarithm in round-to-nearest-even mode.
__device__ ​ __nv_bfloat16 hrcp ( const __nv_bfloat16 a )
Calculates nv_bfloat16 reciprocal in round-to-nearest-even mode.
__device__ ​ __nv_bfloat16 hrint ( const __nv_bfloat16 h )
Round input to nearest integer value in nv_bfloat16 floating-point number.
__device__ ​ __nv_bfloat16 hrsqrt ( const __nv_bfloat16 a )
Calculates nv_bfloat16 reciprocal square root in round-to-nearest-even mode.
__device__ ​ __nv_bfloat16 hsin ( const __nv_bfloat16 a )
Calculates nv_bfloat16 sine in round-to-nearest-even mode.
__device__ ​ __nv_bfloat16 hsqrt ( const __nv_bfloat16 a )
Calculates nv_bfloat16 square root in round-to-nearest-even mode.
__device__ ​ __nv_bfloat16 htrunc ( const __nv_bfloat16 h )
Truncate input argument to the integral part.

Functions

__device__ ​ __nv_bfloat16 atomicAdd ( const __nv_bfloat16* address, const __nv_bfloat16 val )
Adds val to the value stored at address in global or shared memory, and writes this value back to address. This operation is performed in one atomic operation.
Parameters
address
- __nv_bfloat16*. An address in global or shared memory.
val
- __nv_bfloat16. The value to be added.
Returns

__nv_bfloat16

  • The

    old value read from address.

Description

The location of address must be in global or shared memory. This operation has undefined behavior otherwise. This operation is only supported by devices of compute capability 8.x and higher.

Note:

For more details for this function see the Atomic Functions section in the CUDA C++ Programming Guide.

__device__ ​ __nv_bfloat16 hceil ( const __nv_bfloat16 h )
Calculate ceiling of the input argument.
Parameters
h
- nv_bfloat16. Is only being read.
Returns

nv_bfloat16

  • The

    smallest integer value not less than h.

Description

Compute the smallest integer value not less than h.

__device__ ​ __nv_bfloat16 hcos ( const __nv_bfloat16 a )
Calculates nv_bfloat16 cosine in round-to-nearest-even mode.
Parameters
a
- nv_bfloat16. Is only being read.
Returns

nv_bfloat16

  • The

    cosine of a.

Description

Calculates nv_bfloat16 cosine of input a in round-to-nearest-even mode.

__device__ ​ __nv_bfloat16 hexp ( const __nv_bfloat16 a )
Calculates nv_bfloat16 natural exponential function in round-to-nearest mode.
Parameters
a
- nv_bfloat16. Is only being read.
Returns

nv_bfloat16

  • The

    natural exponential function on a.

Description

Calculates nv_bfloat16 natural exponential function of input a in round-to-nearest-even mode.

__device__ ​ __nv_bfloat16 hexp10 ( const __nv_bfloat16 a )
Calculates nv_bfloat16 decimal exponential function in round-to-nearest mode.
Parameters
a
- nv_bfloat16. Is only being read.
Returns

nv_bfloat16

  • The

    decimal exponential function on a.

Description

Calculates nv_bfloat16 decimal exponential function of input a in round-to-nearest-even mode.

__device__ ​ __nv_bfloat16 hexp2 ( const __nv_bfloat16 a )
Calculates nv_bfloat16 binary exponential function in round-to-nearest mode.
Parameters
a
- nv_bfloat16. Is only being read.
Returns

nv_bfloat16

  • The

    binary exponential function on a.

Description

Calculates nv_bfloat16 binary exponential function of input a in round-to-nearest-even mode.

__device__ ​ __nv_bfloat16 hfloor ( const __nv_bfloat16 h )
Calculate the largest integer less than or equal to h.
Parameters
h
- nv_bfloat16. Is only being read.
Returns

nv_bfloat16

  • The

    largest integer value which is less than or equal to h.

Description

Calculate the largest integer value which is less than or equal to h.

__device__ ​ __nv_bfloat16 hlog ( const __nv_bfloat16 a )
Calculates nv_bfloat16 natural logarithm in round-to-nearest-even mode.
Parameters
a
- nv_bfloat16. Is only being read.
Returns

nv_bfloat16

  • The

    natural logarithm of a.

Description

Calculates nv_bfloat16 natural logarithm of input a in round-to-nearest-even mode.

__device__ ​ __nv_bfloat16 hlog10 ( const __nv_bfloat16 a )
Calculates nv_bfloat16 decimal logarithm in round-to-nearest-even mode.
Parameters
a
- nv_bfloat16. Is only being read.
Returns

nv_bfloat16

  • The

    decimal logarithm of a.

Description

Calculates nv_bfloat16 decimal logarithm of input a in round-to-nearest-even mode.

__device__ ​ __nv_bfloat16 hlog2 ( const __nv_bfloat16 a )
Calculates nv_bfloat16 binary logarithm in round-to-nearest-even mode.
Parameters
a
- nv_bfloat16. Is only being read.
Returns

nv_bfloat16

  • The

    binary logarithm of a.

Description

Calculates nv_bfloat16 binary logarithm of input a in round-to-nearest-even mode.

__device__ ​ __nv_bfloat16 hrcp ( const __nv_bfloat16 a )
Calculates nv_bfloat16 reciprocal in round-to-nearest-even mode.
Parameters
a
- nv_bfloat16. Is only being read.
Returns

nv_bfloat16

  • The

    reciprocal of a.

Description

Calculates nv_bfloat16 reciprocal of input a in round-to-nearest-even mode.

__device__ ​ __nv_bfloat16 hrint ( const __nv_bfloat16 h )
Round input to nearest integer value in nv_bfloat16 floating-point number.
Parameters
h
- nv_bfloat16. Is only being read.
Returns

nv_bfloat16

  • The

    nearest integer to h.

Description

Round h to the nearest integer value in nv_bfloat16 floating-point format, with bfloat16way cases rounded to the nearest even integer value.

__device__ ​ __nv_bfloat16 hrsqrt ( const __nv_bfloat16 a )
Calculates nv_bfloat16 reciprocal square root in round-to-nearest-even mode.
Parameters
a
- nv_bfloat16. Is only being read.
Returns

nv_bfloat16

  • The

    reciprocal square root of a.

Description

Calculates nv_bfloat16 reciprocal square root of input a in round-to-nearest mode.

__device__ ​ __nv_bfloat16 hsin ( const __nv_bfloat16 a )
Calculates nv_bfloat16 sine in round-to-nearest-even mode.
Parameters
a
- nv_bfloat16. Is only being read.
Returns

nv_bfloat16

  • The

    sine of a.

Description

Calculates nv_bfloat16 sine of input a in round-to-nearest-even mode.

__device__ ​ __nv_bfloat16 hsqrt ( const __nv_bfloat16 a )
Calculates nv_bfloat16 square root in round-to-nearest-even mode.
Parameters
a
- nv_bfloat16. Is only being read.
Returns

nv_bfloat16

  • The

    square root of a.

Description

Calculates nv_bfloat16 square root of input a in round-to-nearest-even mode.

__device__ ​ __nv_bfloat16 htrunc ( const __nv_bfloat16 h )
Truncate input argument to the integral part.
Parameters
h
- nv_bfloat16. Is only being read.
Returns

nv_bfloat16

  • The

    truncated integer value.

Description

Round h to the nearest integer value that does not exceed h in magnitude.