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__ inline constexpr __half(const __half_raw &hr)
-
Constructor from
__half_raw.
-
__host__ __device__ explicit __half(const __nv_bfloat16 f)
-
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(const double f)
-
Construct
__halffromdoubleinput using default round-to-nearest-even rounding mode.See also
__double2half(double) for further details.
-
__host__ __device__ inline __half(const float f)
-
Construct
__halffromfloatinput using default round-to-nearest-even rounding mode.See also
__float2half(float) for further details.
-
__host__ __device__ inline __half(const int val)
-
Construct
__halffromintinput using default round-to-nearest-even rounding mode.
-
__host__ __device__ inline __half(const long long val)
-
Construct
__halffromlonglonginput using default round-to-nearest-even rounding mode.
-
__host__ __device__ inline __half(const long val)
-
Construct
__halffromlonginput using default round-to-nearest-even rounding mode.
-
__host__ __device__ inline __half(const short val)
-
Construct
__halffromshortinteger input using default round-to-nearest-even rounding mode.
-
__host__ __device__ inline __half(const unsigned int val)
-
Construct
__halffromunsignedintinput using default round-to-nearest-even rounding mode.
-
__host__ __device__ inline __half(const unsigned long long val)
-
Construct
__halffromunsignedlonglonginput using default round-to-nearest-even rounding mode.
-
__host__ __device__ inline __half(const unsigned long val)
-
Construct
__halffromunsignedlonginput using default round-to-nearest-even rounding mode.
-
__host__ __device__ inline __half(const unsigned short val)
-
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() volatile const
-
Type cast to
__half_rawoperator withvolatileinput.
-
__host__ __device__ inline constexpr operator bool() const
-
Conversion operator to
booldata type.+0 and -0 inputs convert to
false. Non-zero inputs convert totrue.
-
__host__ __device__ operator char() 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__ operator float() const
-
Type cast to
floatoperator.
-
__host__ __device__ operator int() const
-
Conversion operator to
intdata type.Using round-toward-zero rounding mode.
See also
__half2int_rz(__half) for further details.
-
__host__ __device__ operator long() 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__ operator long long() const
-
Conversion operator to
longlongdata type.Using round-toward-zero rounding mode.
See also
__half2ll_rz(__half) for further details.
-
__host__ __device__ operator short() const
-
Conversion operator to
shortdata type.Using round-toward-zero rounding mode.
See also
__half2short_rz(__half) for further details.
-
__host__ __device__ operator signed char() const
-
Conversion operator to
signedchardata type.Using round-toward-zero rounding mode.
See also
__half2char_rz(__half) for further details.
-
__host__ __device__ operator unsigned char() const
-
Conversion operator to
unsignedchardata type.Using round-toward-zero rounding mode.
See also
__half2uchar_rz(__half) for further details.
-
__host__ __device__ operator unsigned int() const
-
Conversion operator to
unsignedintdata type.Using round-toward-zero rounding mode.
See also
__half2uint_rz(__half) for further details.
-
__host__ __device__ operator unsigned long() 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__ operator unsigned long long() const
-
Conversion operator to
unsignedlonglongdata type.Using round-toward-zero rounding mode.
See also
__half2ull_rz(__half) for further details.
-
__host__ __device__ operator unsigned short() 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=(const double f)
-
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=(const float f)
-
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=(const int val)
-
Type cast from
intassignment operator, using default round-to-nearest-even rounding mode.
-
__host__ __device__ __half &operator=(const long long val)
-
Type cast from
longlongassignment operator, using default round-to-nearest-even rounding mode.
-
__host__ __device__ __half &operator=(const short val)
-
Type cast from
shortassignment operator, using default round-to-nearest-even rounding mode.
-
__host__ __device__ __half &operator=(const unsigned int val)
-
Type cast from
unsignedintassignment operator, using default round-to-nearest-even rounding mode.
-
__host__ __device__ __half &operator=(const unsigned long long val)
-
Type cast from
unsignedlonglongassignment operator, using default round-to-nearest-even rounding mode.
-
__host__ __device__ __half &operator=(const unsigned short val)
-
Type cast from
unsignedshortassignment operator, using default round-to-nearest-even rounding mode.
-
__host__ __device__ volatile __half &operator=(volatile const __half_raw &hr) volatile
-
Assignment operator from
volatile__half_rawtovolatile__half.
-
__half() = default