15.1.__half

struct__half

__half data type

This structure implements the datatype for storing half-precision floating-point numbers. The structure implements assignment, arithmetic and comparison operators, and type conversions. 16 bits are being used in total: 1 sign bit, 5 bits for the exponent, and the significand is being stored in 10 bits. The total precision is 11 bits. There are 15361 representable numbers within the interval [0.0, 1.0], endpoints included. On average we have log10(2**11) ~ 3.311 decimal digits.

The objective here is to provide IEEE754-compliant implementation ofbinary16 type and arithmetic with limitations due to device HW not supporting floating-point exceptions.

Public Functions

__half()=default

Constructor by default.

Emtpy default constructor, result is uninitialized.

__host____device__inlineconstexpr__half(const__half_raw&hr)

Constructor from__half_raw.

__host____device__explicit__half(const__nv_bfloat16f)

Construct__half from__nv_bfloat16 input using default round-to-nearest-even rounding mode.

Need to include the header filecuda_bf16.h

__host____device__inline__half(constdoublef)

Construct__half fromdouble input using default round-to-nearest-even rounding mode.

See also

__double2half(double) for further details.

__host____device__inline__half(constfloatf)

Construct__half fromfloat input using default round-to-nearest-even rounding mode.

See also

__float2half(float) for further details.

__host____device__inline__half(constintval)

Construct__half fromint input using default round-to-nearest-even rounding mode.

__host____device__inline__half(constlonglongval)

Construct__half fromlonglong input using default round-to-nearest-even rounding mode.

__host____device__inline__half(constlongval)

Construct__half fromlong input using default round-to-nearest-even rounding mode.

__host____device__inline__half(constshortval)

Construct__half fromshort integer input using default round-to-nearest-even rounding mode.

__host____device__inline__half(constunsignedintval)

Construct__half fromunsignedint input using default round-to-nearest-even rounding mode.

__host____device__inline__half(constunsignedlonglongval)

Construct__half fromunsignedlonglong input using default round-to-nearest-even rounding mode.

__host____device__inline__half(constunsignedlongval)

Construct__half fromunsignedlong input using default round-to-nearest-even rounding mode.

__host____device__inline__half(constunsignedshortval)

Construct__half fromunsignedshort integer input using default round-to-nearest-even rounding mode.

__host____device__operator__half_raw()const

Type cast to__half_raw operator.

__host____device__operator__half_raw()volatileconst

Type cast to__half_raw operator withvolatile input.

__host____device__inlineconstexproperatorbool()const

Conversion operator tobool data type.

+0 and -0 inputs convert tofalse. Non-zero inputs convert totrue.

__host____device__operatorchar()const

Conversion operator to an implementation definedchar data type.

Using round-toward-zero rounding mode.

Detects signedness of thechar type and proceeds accordingly, see further details in__half2char_rz(__half) and__half2uchar_rz(__half).

__host____device__operatorfloat()const

Type cast tofloat operator.

__host____device__operatorint()const

Conversion operator toint data type.

Using round-toward-zero rounding mode.

See also

__half2int_rz(__half) for further details.

__host____device__operatorlong()const

Conversion operator tolong data type.

Using round-toward-zero rounding mode.

Detects size of thelong type and proceeds accordingly, see further details in__half2int_rz(__half) and__half2ll_rz(__half).

__host____device__operatorlonglong()const

Conversion operator tolonglong data type.

Using round-toward-zero rounding mode.

See also

__half2ll_rz(__half) for further details.

__host____device__operatorshort()const

Conversion operator toshort data type.

Using round-toward-zero rounding mode.

See also

__half2short_rz(__half) for further details.

__host____device__operatorsignedchar()const

Conversion operator tosignedchar data type.

Using round-toward-zero rounding mode.

See also

__half2char_rz(__half) for further details.

__host____device__operatorunsignedchar()const

Conversion operator tounsignedchar data type.

Using round-toward-zero rounding mode.

See also

__half2uchar_rz(__half) for further details.

__host____device__operatorunsignedint()const

Conversion operator tounsignedint data type.

Using round-toward-zero rounding mode.

See also

__half2uint_rz(__half) for further details.

__host____device__operatorunsignedlong()const

Conversion operator tounsignedlong data type.

Using round-toward-zero rounding mode.

Detects size of theunsignedlong type and proceeds accordingly, see further details in__half2uint_rz(__half) and__half2ull_rz(__half).

__host____device__operatorunsignedlonglong()const

Conversion operator tounsignedlonglong data type.

Using round-toward-zero rounding mode.

See also

__half2ull_rz(__half) for further details.

__host____device__operatorunsignedshort()const

Conversion operator tounsignedshort data type.

Using round-toward-zero rounding mode.

See also

__half2ushort_rz(__half) for further details.

__host____device____half&operator=(const__half_raw&hr)

Assignment operator from__half_raw.

__host____device__volatile__half&operator=(const__half_raw&hr)volatile

Assignment operator from__half_raw tovolatile__half.

__host____device____half&operator=(constdoublef)

Type cast to__half assignment operator fromdouble input using default round-to-nearest-even rounding mode.

See also

__double2half(double) for further details.

__host____device____half&operator=(constfloatf)

Type cast to__half assignment operator fromfloat input using default round-to-nearest-even rounding mode.

See also

__float2half(float) for further details.

__host____device____half&operator=(constintval)

Type cast fromint assignment operator, using default round-to-nearest-even rounding mode.

__host____device____half&operator=(constlonglongval)

Type cast fromlonglong assignment operator, using default round-to-nearest-even rounding mode.

__host____device____half&operator=(constshortval)

Type cast fromshort assignment operator, using default round-to-nearest-even rounding mode.

__host____device____half&operator=(constunsignedintval)

Type cast fromunsignedint assignment operator, using default round-to-nearest-even rounding mode.

__host____device____half&operator=(constunsignedlonglongval)

Type cast fromunsignedlonglong assignment operator, using default round-to-nearest-even rounding mode.

__host____device____half&operator=(constunsignedshortval)

Type cast fromunsignedshort assignment operator, using default round-to-nearest-even rounding mode.

__host____device__volatile__half&operator=(volatileconst__half_raw&hr)volatile

Assignment operator fromvolatile__half_raw tovolatile__half.