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 of
binary16type 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
__halffrom__nv_bfloat16input using default round-to-nearest-even rounding mode.Need to include the header file
cuda_bf16.h
- __host____device__inline__half(constdoublef)
Construct
__halffromdoubleinput using default round-to-nearest-even rounding mode.See also
__double2half(double) for further details.
- __host____device__inline__half(constfloatf)
Construct
__halffromfloatinput using default round-to-nearest-even rounding mode.See also
__float2half(float) for further details.
- __host____device__inline__half(constintval)
Construct
__halffromintinput using default round-to-nearest-even rounding mode.
- __host____device__inline__half(constlonglongval)
Construct
__halffromlonglonginput using default round-to-nearest-even rounding mode.
- __host____device__inline__half(constlongval)
Construct
__halffromlonginput using default round-to-nearest-even rounding mode.
- __host____device__inline__half(constshortval)
Construct
__halffromshortinteger input using default round-to-nearest-even rounding mode.
- __host____device__inline__half(constunsignedintval)
Construct
__halffromunsignedintinput using default round-to-nearest-even rounding mode.
- __host____device__inline__half(constunsignedlonglongval)
Construct
__halffromunsignedlonglonginput using default round-to-nearest-even rounding mode.
- __host____device__inline__half(constunsignedlongval)
Construct
__halffromunsignedlonginput using default round-to-nearest-even rounding mode.
- __host____device__inline__half(constunsignedshortval)
Construct
__halffromunsignedshortinteger input using default round-to-nearest-even rounding mode.
- __host____device__operator__half_raw()const
Type cast to
__half_rawoperator.
- __host____device__operator__half_raw()volatileconst
Type cast to
__half_rawoperator withvolatileinput.
- __host____device__inlineconstexproperatorbool()const
Conversion operator to
booldata type.+0 and -0 inputs convert to
false. Non-zero inputs convert totrue.
- __host____device__operatorchar()const
Conversion operator to an implementation defined
chardata type.Using round-toward-zero rounding mode.
Detects signedness of the
chartype and proceeds accordingly, see further details in__half2char_rz(__half) and__half2uchar_rz(__half).
- __host____device__operatorfloat()const
Type cast to
floatoperator.
- __host____device__operatorint()const
Conversion operator to
intdata type.Using round-toward-zero rounding mode.
See also
__half2int_rz(__half) for further details.
- __host____device__operatorlong()const
Conversion operator to
longdata type.Using round-toward-zero rounding mode.
Detects size of the
longtype and proceeds accordingly, see further details in__half2int_rz(__half) and__half2ll_rz(__half).
- __host____device__operatorlonglong()const
Conversion operator to
longlongdata type.Using round-toward-zero rounding mode.
See also
__half2ll_rz(__half) for further details.
- __host____device__operatorshort()const
Conversion operator to
shortdata type.Using round-toward-zero rounding mode.
See also
__half2short_rz(__half) for further details.
- __host____device__operatorsignedchar()const
Conversion operator to
signedchardata type.Using round-toward-zero rounding mode.
See also
__half2char_rz(__half) for further details.
- __host____device__operatorunsignedchar()const
Conversion operator to
unsignedchardata type.Using round-toward-zero rounding mode.
See also
__half2uchar_rz(__half) for further details.
- __host____device__operatorunsignedint()const
Conversion operator to
unsignedintdata type.Using round-toward-zero rounding mode.
See also
__half2uint_rz(__half) for further details.
- __host____device__operatorunsignedlong()const
Conversion operator to
unsignedlongdata type.Using round-toward-zero rounding mode.
Detects size of the
unsignedlongtype and proceeds accordingly, see further details in__half2uint_rz(__half) and__half2ull_rz(__half).
- __host____device__operatorunsignedlonglong()const
Conversion operator to
unsignedlonglongdata type.Using round-toward-zero rounding mode.
See also
__half2ull_rz(__half) for further details.
- __host____device__operatorunsignedshort()const
Conversion operator to
unsignedshortdata 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_rawtovolatile__half.
- __host____device____half&operator=(constdoublef)
Type cast to
__halfassignment operator fromdoubleinput using default round-to-nearest-even rounding mode.See also
__double2half(double) for further details.
- __host____device____half&operator=(constfloatf)
Type cast to
__halfassignment operator fromfloatinput using default round-to-nearest-even rounding mode.See also
__float2half(float) for further details.
- __host____device____half&operator=(constintval)
Type cast from
intassignment operator, using default round-to-nearest-even rounding mode.
- __host____device____half&operator=(constlonglongval)
Type cast from
longlongassignment operator, using default round-to-nearest-even rounding mode.
- __host____device____half&operator=(constshortval)
Type cast from
shortassignment operator, using default round-to-nearest-even rounding mode.
- __host____device____half&operator=(constunsignedintval)
Type cast from
unsignedintassignment operator, using default round-to-nearest-even rounding mode.
- __host____device____half&operator=(constunsignedlonglongval)
Type cast from
unsignedlonglongassignment operator, using default round-to-nearest-even rounding mode.
- __host____device____half&operator=(constunsignedshortval)
Type cast from
unsignedshortassignment operator, using default round-to-nearest-even rounding mode.
- __host____device__volatile__half&operator=(volatileconst__half_raw&hr)volatile
Assignment operator from
volatile__half_rawtovolatile__half.
- __half()=default