imate
C++/CUDA Reference
Loading...
Searching...
No Matches
cu_arithmetics Namespace Reference

Cast from float to __half and __nv_bfloat16 types and vice-versa, and float to double and vice-versa. More...

Functions

template<typename DataType >
__host__ __device__ DataType abs (const DataType x)
 Absolute value of a floating point number.
 
template<>
__host__ __device__ float abs< float > (const float x)
 Absolute value of a floating point number in __nv_fp8_e5m2 type.
 
template<>
__host__ __device__ double abs< double > (const double x)
 Absolute value of a floating point number in double type.
 
template<typename DataType >
__host__ __device__ DataType add (const DataType x, const DataType y)
 Add two floating point numbers in round-to-nearest-even mode.
 
template<>
__host__ __device__ float add< float > (const float x, const float y)
 Add two __nv_fp8_e5m2 type numbers in round-to-nearest-even mode.
 
template<>
__host__ __device__ double add< double > (const double x, const double y)
 Add two double type float numbers.
 
template<typename DataType >
__host__ __device__ DataType add (const DataType x, const DataType y, const DataType z)
 Add three floating point numbers in round-to-nearest-even mode.
 
template<>
__host__ __device__ float add< float > (const float x, const float y, const float z)
 Add three __half type numbers in round-to-nearest-even mode.
 
template<>
__host__ __device__ double add< double > (const double x, const double y, const double z)
 Add three double type numbers in round-to-nearest-even mode.
 
template<typename InputDataType , typename OutputDataType >
__host__ __device__ OutputDataType cast (const InputDataType x)
 Cast a floating point type to another floating point type.
 
template<>
__host__ __device__ float cast< float, float > (const float x)
 Cast __nv_fp8_e5m2 type to float type.
 
template<>
__host__ __device__ double cast< float, double > (const float x)
 Cast float type to double type.
 
template<>
__host__ __device__ double cast< double, double > (const double x)
 Cast double type to double type (no action needed)
 
template<>
__host__ __device__ float cast< double, float > (const double x)
 Cast double type to float type.
 
template<>
__host__ __device__ float cast< int, float > (const int x)
 Cast int type to __nv_fp8_e5m2 type in round-to-nearest-even mode.
 
template<>
__host__ __device__ int cast< float, int > (const float x)
 Cast float type to int type in round-to-nearest-even mode.
 
template<>
__host__ __device__ double cast< int, double > (const int x)
 Cast int type to double type in round-to-nearest-even mode.
 
template<>
__host__ __device__ int cast< double, int > (const double x)
 Cast double type to int type in round-to-nearest-even mode.
 
template<>
__host__ __device__ float cast< unsigned int, float > (const unsigned int x)
 Cast unsigned int type to __nv_fp8_e5m2 type in round-to-nearest-even mode.
 
template<>
__host__ __device__ unsigned int cast< float, unsigned int > (const float x)
 Cast float type to unsigned int type in round-to-nearest-even mode.
 
template<>
__host__ __device__ double cast< unsigned int, double > (const unsigned int x)
 Cast unsigned int type to double type in round-to-nearest-even mode.
 
template<>
__host__ __device__ unsigned int cast< double, unsigned int > (const double x)
 Cast double type to unsigned int type in round-to-nearest-even mode.
 
template<>
__host__ __device__ float cast< long long int, float > (const long long int x)
 Cast long long int type to __nv_fp8_e5m2 type in round-to-nearest-even mode.
 
template<>
__host__ __device__ long long int cast< float, long long int > (const float x)
 Cast float type to long long int type in round-to-nearest-even mode.
 
template<>
__host__ __device__ double cast< long long int, double > (const long long int x)
 Cast long long int type to double type in round-to-nearest-even mode.
 
template<>
__host__ __device__ long long int cast< double, long long int > (const double x)
 Cast double type to long long int type in round-to-nearest-even mode.
 
template<>
__host__ __device__ float cast< unsigned long long int, float > (const unsigned long long int x)
 Cast unsigned long long int type to __nv_fp8_e5m2 type in round-to-nearest-even mode.
 
template<>
__host__ __device__ unsigned long long int cast< float, unsigned long long int > (const float x)
 Cast float type to unsigned long long int type in round-to-nearest-even mode.
 
template<>
__host__ __device__ double cast< unsigned long long int, double > (const unsigned long long int x)
 Cast unsigned long long int type to double type in round-to-nearest-even mode.
 
template<>
__host__ __device__ unsigned long long int cast< double, unsigned long long int > (const double x)
 Cast double type to unsigned long long int type in round-to-nearest-even mode.
 
template<typename DataType >
__host__ __device__ DataType div (const DataType x, const DataType y)
 Divide two floating point numbers in round-to-nearest-even mode.
 
template<>
__host__ __device__ float div< float > (const float x, const float y)
 Divide two __nv_fp8_e5m2 type numbers in round-to-nearest-even mode.
 
template<>
__host__ __device__ double div< double > (const double x, const double y)
 Divide two double type numbers in round-to-nearest-even mode.
 
template<typename DataType >
__host__ __device__ DataType epsilon ()
 epsilon for various floating point precisions.
 
template<>
__host__ __device__ float epsilon< float > ()
 epsilon for __nv_fp8_e5m2 type, which is equal to \( 2^{-2} \) since __nv_fp8_e5m2 has 2 bits for fraction (mantissa).
 
template<>
__host__ __device__ double epsilon< double > ()
 epsilon for float type, which is equal to \( 2^{-52} \) since float has 52 bits for fraction (mantissa).
 
template<typename DataType >
bool is_equal (DataType x, DataType y)
 Check if two floating point numbers are equal within a tolerance.
 
template<>
bool is_equal (float x, float y)
 Check if two floating point numbers are equal within a tolerance for __nv_fp8_e5m2 type.
 
template<>
bool is_equal (double x, double y)
 Check if two floating point numbers are equal within a tolerance for double type.
 
template<typename DataType >
__host__ __device__ DataType mul (const DataType x, const DataType y)
 Multiply two floating point numbers in round-to-nearest-even mode.
 
template<>
__host__ __device__ float mul< float > (const float x, const float y)
 Multiply two __nv_fp8_e5m2 type numbers in round-to-nearest-even mode.
 
template<>
__host__ __device__ double mul< double > (const double x, const double y)
 Multiply two double type numbers in round-to-nearest-even mode.
 
template<typename DataType >
__host__ __device__ DataType mul (const DataType x, const DataType y, const DataType z)
 Multiply three floating point numbers in round-to-nearest-even mode.
 
template<>
__host__ __device__ float mul< float > (const float x, const float y, const float z)
 Multiply three __half numbers in round-to-nearest-even mode.
 
template<>
__host__ __device__ double mul< double > (const double x, const double y, const double z)
 Multiply three double numbers in round-to-nearest-even mode.
 
template<typename DataType >
__host__ __device__ DataType sub (const DataType x, const DataType y)
 Subtract two floating point numbers in round-to-nearest-even mode.
 
template<>
__host__ __device__ float sub< float > (const float x, const float y)
 Subtract two __nv_fp8_e5m2 type numbers in round-to-nearest-even mode.
 
template<>
__host__ __device__ double sub< double > (const double x, const double y)
 Subtract two double type float numbers.
 

Detailed Description

Cast from float to __half and __nv_bfloat16 types and vice-versa, and float to double and vice-versa.

This namespace declares arithmetic functions in CUDA.

This namespace is a templated unifying API casting CUDA's types, including __half and __nv_bfloat16 types to float and vice-versa and float to double and vice-versa.

See also
cu_arithmetics::add, cu_arithmetics::mul, cu_arithmetics::is_equal
cu_arithmetics::add, cu_arithmetics::mul, cu_arithmetics::cast

Function Documentation

◆ abs()

template<typename DataType >
__host__ __device__ DataType cu_arithmetics::abs ( const DataType  x)
inline

Absolute value of a floating point number.

Parameters
[in]xOperand.
Returns
y Absolute value of x
See also
cu_arithmetics::is_equal

Referenced by cuAffineMatrixFunction< DataType >::_add_scaled_vector(), cuTraceEstimator< DataType >::_cu_stochastic_lanczos_quadrature(), abs< double >(), abs< float >(), add< double >(), add< double >(), add< float >(), add< float >(), cast< double, double >(), cast< double, float >(), cast< double, int >(), cast< double, long long int >(), cast< double, unsigned int >(), cast< double, unsigned long long int >(), cast< float, double >(), cast< float, float >(), cast< float, int >(), cast< float, long long int >(), cast< float, unsigned int >(), cast< float, unsigned long long int >(), cast< int, double >(), cast< int, float >(), cast< long long int, double >(), cast< long long int, float >(), cast< unsigned int, double >(), cast< unsigned int, float >(), cast< unsigned long long int, double >(), cast< unsigned long long int, float >(), cu_golub_kahn_bidiagonalization(), cu_lanczos_tridiagonalization(), cublas_impl_kernels::cublasTaxpy_kernel(), cublas_impl::cublasTdot(), cublas_impl_kernels::cublasTdot_kernel(), cublas_impl_kernels::cublasTgemv_kernel(), cublas_impl::cublasTnrm2(), cublas_impl_kernels::cublasTnrm2_kernel(), cublas_impl_kernels::cublasTscal_kernel(), cuMatrixOperations< DataType >::dense_matvec(), cuMatrixOperations< DataType >::dense_matvec_plus(), cuMatrixOperations< DataType >::dense_transposed_matvec(), cuMatrixOperations< DataType >::dense_transposed_matvec_plus(), div< double >(), div< float >(), cuCSCMatrix< DataType >::dot(), cuCSRMatrix< DataType >::dot(), cuCSCMatrix< DataType >::dot_plus(), cuCSRMatrix< DataType >::dot_plus(), cuAffineMatrixFunction< DataType >::get_eigenvalue(), cuOrthogonalization< DataType >::gram_schmidt_process(), is_equal(), is_equal(), mul< double >(), mul< double >(), mul< float >(), mul< float >(), cuVectorOperations< DataType >::normalize_vector_and_copy(), cuVectorOperations< DataType >::normalize_vector_in_place(), cuOrthogonalization< DataType >::orthogonalize_vectors(), sub< double >(), sub< float >(), cuCSCMatrix< DataType >::transpose_dot(), cuCSRMatrix< DataType >::transpose_dot(), cuCSCMatrix< DataType >::transpose_dot_plus(), and cuCSRMatrix< DataType >::transpose_dot_plus().

◆ abs< double >()

Absolute value of a floating point number in double type.

Parameters
[in]xOperand.
Returns
y Absolute value of x
See also
cu_arithmetics::is_equal

Definition at line 198 of file _cu_abs.h.

199 {
200 return std::abs(x);
201 }

References abs().

Here is the call graph for this function:

◆ abs< float >()

Absolute value of a floating point number in __nv_fp8_e5m2 type.

Parameters
[in]xOperand.
Returns
y Absolute value of x
See also
cu_arithmetics::is_equal

Absolute value of a floating point number in __nv_fp8_e4m3 type.

Parameters
[in]xOperand.
Returns
y Absolute value of x
See also
cu_arithmetics::is_equal

Absolute value of a floating point number in __half type.

Parameters
[in]xOperand.
Returns
y Absolute value of x
See also
cu_arithmetics::is_equal

Absolute value of a floating point number in __nv_bfloat16 type.

Parameters
[in]xOperand.
Returns
y Absolute value of x
See also
cu_arithmetics::is_equal

Absolute value of a floating point number in float type.

Parameters
[in]xOperand.
Returns
y Absolute value of x
See also
cu_arithmetics::is_equal

Definition at line 176 of file _cu_abs.h.

177 {
178 return std::abs(x);
179 }

References abs().

Here is the call graph for this function:

◆ add() [1/2]

template<typename DataType >
__host__ __device__ DataType cu_arithmetics::add ( const DataType  x,
const DataType  y 
)
inline

Add two floating point numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Sum of x and y
See also
cu_arithmetics::sub

◆ add() [2/2]

template<typename DataType >
__host__ __device__ DataType cu_arithmetics::add ( const DataType  x,
const DataType  y,
const DataType  z 
)
inline

Add three floating point numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
[in]zThird operand.
Returns
w Sum of x, y, and z.
See also
cu_arithmetics::sub

◆ add< double >() [1/2]

Add two double type float numbers.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Sum of x and y
See also
cu_arithmetics::sub

Definition at line 221 of file _cu_add.h.

224 {
225 return x + y;
226 }

References abs().

Here is the call graph for this function:

◆ add< double >() [2/2]

Add three double type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
[in]zThird operand.
Returns
w Sum of x, y, and z.
See also
cu_arithmetics::sub

Definition at line 365 of file _cu_add.h.

369 {
370 return x + y + z;
371 }

References abs().

Here is the call graph for this function:

◆ add< float >() [1/2]

template<>
__host__ __device__ float cu_arithmetics::add< float > ( const float  x,
const float  y 
)
inline

Add two __nv_fp8_e5m2 type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Sum of x and y
See also
cu_arithmetics::sub

Add two __nv_fp8_e4m3 type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Sum of x and y
See also
cu_arithmetics::sub

Add two __half type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Sum of x and y
See also
cu_arithmetics::sub

Add two __nv_bfloat16 type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Sum of x and y
See also
cu_arithmetics::sub

Add two float type numbers.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Sum of x and y
See also
cu_arithmetics::sub

Definition at line 195 of file _cu_add.h.

198 {
199 return x + y;
200 }

References abs().

Here is the call graph for this function:

◆ add< float >() [2/2]

template<>
__host__ __device__ float cu_arithmetics::add< float > ( const float  x,
const float  y,
const float  z 
)
inline

Add three __half type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
[in]zThird operand.
Returns
w Sum of x, y, and z.
See also
cu_arithmetics::sub

Add three __nv_bfloat16 type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
[in]zThird operand.
Returns
w Sum of x, y, and z.
See also
cu_arithmetics::sub

Add three float type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
[in]zThird operand.
Returns
w Sum of x, y, and z.
See also
cu_arithmetics::sub

Definition at line 335 of file _cu_add.h.

339 {
340 return x + y + z;
341 }

References abs().

Here is the call graph for this function:

◆ cast()

Cast a floating point type to another floating point type.

Parameters
[in]xInput
Returns
x Output
See also
cu_arithmetic::add, cu_arithmetic::mul

◆ cast< double, double >()

Cast double type to double type (no action needed)

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 506 of file _cu_cast.h.

508 {
509 return x;
510 }

References abs().

Here is the call graph for this function:

◆ cast< double, float >()

Cast double type to float type.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 528 of file _cu_cast.h.

530 {
531 return static_cast<float>(x);
532 }

References abs().

Here is the call graph for this function:

◆ cast< double, int >()

Cast double type to int type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 719 of file _cu_cast.h.

721 {
722 return static_cast<int>(x);
723 }

References abs().

Here is the call graph for this function:

◆ cast< double, long long int >()

Cast double type to long long int type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 1106 of file _cu_cast.h.

1108 {
1109 return static_cast<long long int>(x);
1110 }

References abs().

Here is the call graph for this function:

◆ cast< double, unsigned int >()

Cast double type to unsigned int type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 911 of file _cu_cast.h.

913 {
914 return static_cast<unsigned int>(x);
915 }

References abs().

Here is the call graph for this function:

◆ cast< double, unsigned long long int >()

Cast double type to unsigned long long int type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 1302 of file _cu_cast.h.

1305 {
1306 return static_cast<unsigned long long int>(x);
1307 }

References abs().

Here is the call graph for this function:

◆ cast< float, double >()

Cast float type to double type.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 484 of file _cu_cast.h.

486 {
487 return static_cast<double>(x);
488 }

References abs().

Here is the call graph for this function:

◆ cast< float, float >()

Cast __nv_fp8_e5m2 type to float type.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast float type to __nv_fp8_e5m2 type.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast __nv_fp8_e5m2 type to double type.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast double type to __nv_fp8_e5m2 type.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast __nv_fp8_e4m3 type to float type.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast float type to __nv_fp8_e4m3 type.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast __nv_fp8_e4m3 type to double type.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast double type to __nv_fp8_e4m3 type.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast __half type to float type.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast float type to __half type.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast __half type to double type.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast double type to __half type.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast __nv_bfloat16 type to float type.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast float type to __nv_bfloat16 type.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast __nv_bfloat16 type to double type.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast double type to __nv_bfloat16 type.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast float type to float type (no action needed)

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 462 of file _cu_cast.h.

464 {
465 return x;
466 }

References abs().

Here is the call graph for this function:

◆ cast< float, int >()

Cast float type to int type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 673 of file _cu_cast.h.

675 {
676 return static_cast<int>(x);
677 }

References abs().

Here is the call graph for this function:

◆ cast< float, long long int >()

Cast float type to long long int type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 1060 of file _cu_cast.h.

1062 {
1063 return static_cast<long long int>(x);
1064 }

References abs().

Here is the call graph for this function:

◆ cast< float, unsigned int >()

Cast float type to unsigned int type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 865 of file _cu_cast.h.

867 {
868 return static_cast<unsigned int>(x);
869 }

References abs().

Here is the call graph for this function:

◆ cast< float, unsigned long long int >()

Cast float type to unsigned long long int type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 1255 of file _cu_cast.h.

1258 {
1259 return static_cast<unsigned long long int>(x);
1260 }

References abs().

Here is the call graph for this function:

◆ cast< int, double >()

Cast int type to double type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 696 of file _cu_cast.h.

698 {
699 return static_cast<double>(x);
700 }

References abs().

Here is the call graph for this function:

◆ cast< int, float >()

Cast int type to __nv_fp8_e5m2 type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast int type to __nv_fp8_e4m3 type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast int type to __half type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast int type to __nv_bfloat16 type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast int type to float type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 650 of file _cu_cast.h.

652 {
653 return static_cast<float>(x);
654 }

References abs().

Here is the call graph for this function:

◆ cast< long long int, double >()

Cast long long int type to double type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 1083 of file _cu_cast.h.

1085 {
1086 return static_cast<double>(x);
1087 }

References abs().

Here is the call graph for this function:

◆ cast< long long int, float >()

Cast long long int type to __nv_fp8_e5m2 type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast long long int type to __nv_fp8_e4m3 type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast long long int type to __half type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast long long int type to __nv_bfloat16 type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast long long int type to float type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 1037 of file _cu_cast.h.

1039 {
1040 return static_cast<float>(x);
1041 }

References abs().

Here is the call graph for this function:

◆ cast< unsigned int, double >()

Cast unsigned int type to double type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 888 of file _cu_cast.h.

890 {
891 return static_cast<double>(x);
892 }

References abs().

Here is the call graph for this function:

◆ cast< unsigned int, float >()

Cast unsigned int type to __nv_fp8_e5m2 type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast unsigned int type to __nv_fp8_e4m3 type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast unsigned int type to __half type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast unsigned
int type to __nv_bfloat16 type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast unsigned int type to float type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 842 of file _cu_cast.h.

844 {
845 return static_cast<float>(x);
846 }

References abs().

Here is the call graph for this function:

◆ cast< unsigned long long int, double >()

Cast unsigned long long int type to double type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 1279 of file _cu_cast.h.

1281 {
1282 return static_cast<double>(x);
1283 }

References abs().

Here is the call graph for this function:

◆ cast< unsigned long long int, float >()

Cast unsigned long long int type to __nv_fp8_e5m2 type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast unsigned long long int type to __nv_fp8_e4m3 type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast unsigned long long int type to __half type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast unsigned
long long int type to __nv_bfloat16 type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Cast unsigned long long int type to float type in round-to-nearest-even mode.

Parameters
[in]xInput
Returns
y Output
See also
cu_arithmetic::add, cu_arithmetic::mul

Definition at line 1232 of file _cu_cast.h.

1234 {
1235 return static_cast<float>(x);
1236 }

References abs().

Here is the call graph for this function:

◆ div()

template<typename DataType >
__host__ __device__ DataType cu_arithmetics::div ( const DataType  x,
const DataType  y 
)
inline

Divide two floating point numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Product of x and y
See also
cu_arithmetics::div

Referenced by cuOrthogonalization< DataType >::gram_schmidt_process(), cuVectorOperations< DataType >::normalize_vector_and_copy(), cuVectorOperations< DataType >::normalize_vector_in_place(), and cuOrthogonalization< DataType >::orthogonalize_vectors().

Here is the caller graph for this function:

◆ div< double >()

Divide two double type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Product of x and y
See also
cu_arithmetics::div

Definition at line 223 of file _cu_div.h.

226 {
227 return x / y;
228 }

References abs().

Here is the call graph for this function:

◆ div< float >()

template<>
__host__ __device__ float cu_arithmetics::div< float > ( const float  x,
const float  y 
)
inline

Divide two __nv_fp8_e5m2 type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Product of x and y
See also
cu_arithmetics::div

Divide two __nv_fp8_e4m3 type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Product of x and y
See also
cu_arithmetics::div

Divide two __half type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Product of x and y
See also
cu_arithmetics::div

Divide two __nv_bfloat16 type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Product of x and y
See also
cu_arithmetics::div

Divide two float type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Product of x and y
See also
cu_arithmetics::div

Definition at line 196 of file _cu_div.h.

199 {
200 return x / y;
201 }

References abs().

Here is the call graph for this function:

◆ epsilon()

template<typename DataType >
__host__ __device__ DataType cu_arithmetics::epsilon ( )
inline

epsilon for various floating point precisions.

Note
This is a __host__ function only, since std::numeric_limits cannot be called from a __device__ code.
Returns
eps Epsilon
See also
cu_arithmetics::is_equal

◆ epsilon< double >()

epsilon for float type, which is equal to \( 2^{-52} \) since float has 52 bits for fraction (mantissa).

Returns
eps Epsilon
See also
cu_arithmetics::is_equal

Definition at line 190 of file _cu_epsilon.h.

191 {
192 // Instead of the hard-coded number below, one may use
193 // the std::numeric_limits::epsilon(), but, then this function cannot
194 // be called as a __device__ code. Hence, the value of 2^(-52) is hard
195 // coded below.
196 return 2.220446049250313e-16;
197 }

◆ epsilon< float >()

epsilon for __nv_fp8_e5m2 type, which is equal to \( 2^{-2} \) since __nv_fp8_e5m2 has 2 bits for fraction (mantissa).

Returns
eps Epsilon
See also
cu_arithmetics::is_equal

epsilon for __nv_fp8_e4m3 type, which is equal to \( 2^{-3} \) since __nv_fp8_e4m3 has 3 bits for fraction (mantissa).

Returns
eps Epsilon
See also
cu_arithmetics::is_equal

epsilon for __half type, which is equal to \( 2^{-10} \) since __half has 10 bits for fraction (mantissa).

Returns
eps Epsilon
See also
cu_arithmetics::is_equal

epsilon for __nv_bfloat16 type, which is equal to \( 2^{-7} \) since __nv_bfloat16 has 7 bits for fraction (mantissa).

Returns
eps Epsilon
See also
cu_arithmetics::is_equal

epsilon for float type, which is equal to \( 2^{-23} \) since float has 23 bits for fraction (mantissa).

Returns
eps Epsilon
See also
cu_arithmetics::is_equal

Definition at line 165 of file _cu_epsilon.h.

166 {
167 // Instead of the hard-coded number below, one may use
168 // the std::numeric_limits::epsilon(), but, then this function cannot
169 // be called as a __device__ code. Hence, the value of 2^(-23) is hard
170 // coded below.
171 return 1.1920929e-7f;
172 }

◆ is_equal() [1/3]

template<typename DataType >
bool cu_arithmetics::is_equal ( DataType  x,
DataType  y 
)
inline

Check if two floating point numbers are equal within a tolerance.

Parameters
[in]xA floating point number
[in]yA floating point number
Returns
true or false .

Referenced by cuMatrixOperations< DataType >::dense_matvec_plus(), cuMatrixOperations< DataType >::dense_transposed_matvec_plus(), cuCSCMatrix< DataType >::is_identity_matrix(), cuCSRMatrix< DataType >::is_identity_matrix(), cuDenseMatrix< DataType >::is_identity_matrix(), and cuVectorOperations< DataType >::subtract_scaled_vector().

Here is the caller graph for this function:

◆ is_equal() [2/3]

template<>
bool cu_arithmetics::is_equal ( double  x,
double  y 
)
inline

Check if two floating point numbers are equal within a tolerance for double type.

Parameters
[in]xA floating point number
[in]yA floating point number
Returns
true or false .

Definition at line 196 of file _cu_is_equal.h.

197 {
198 if (std::fabs(x - y) <= 2.0 * std::numeric_limits<double>::epsilon())
199 {
200 return true;
201 }
202 else
203 {
204 return false;
205 }
206 }

References abs().

Here is the call graph for this function:

◆ is_equal() [3/3]

template<>
bool cu_arithmetics::is_equal ( float  x,
float  y 
)
inline

Check if two floating point numbers are equal within a tolerance for __nv_fp8_e5m2 type.

Parameters
[in]xA floating point number
[in]yA floating point number
Returns
true or false .

Check if two floating point numbers are equal within a tolerance for __nv_fp8_e4m3 type.

Parameters
[in]xA floating point number
[in]yA floating point number
Returns
true or false .

Check if two floating point numbers are equal within a tolerance for __half type.

Parameters
[in]xA floating point number
[in]yA floating point number
Returns
true or false .

Check if two floating point numbers are equal within a tolerance for __nv_bfloat16 type.

Parameters
[in]xA floating point number
[in]yA floating point number
Returns
true or false .

Check if two floating point numbers are equal within a tolerance for float type.

Parameters
[in]xA floating point number
[in]yA floating point number
Returns
true or false .

Definition at line 167 of file _cu_is_equal.h.

168 {
169 if (std::fabs(x - y) <= 2.0 * std::numeric_limits<float>::epsilon())
170 {
171 return true;
172 }
173 else
174 {
175 return false;
176 }
177 }

References abs().

Here is the call graph for this function:

◆ mul() [1/2]

template<typename DataType >
__host__ __device__ DataType cu_arithmetics::mul ( const DataType  x,
const DataType  y 
)
inline

Multiply two floating point numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Product of x and y
See also
cu_arithmetics::div

Referenced by cuTraceEstimator< DataType >::_cu_stochastic_lanczos_quadrature(), cu_golub_kahn_bidiagonalization(), cu_lanczos_tridiagonalization(), cuOrthogonalization< DataType >::gram_schmidt_process(), and cuOrthogonalization< DataType >::orthogonalize_vectors().

Here is the caller graph for this function:

◆ mul() [2/2]

template<typename DataType >
__host__ __device__ DataType cu_arithmetics::mul ( const DataType  x,
const DataType  y,
const DataType  z 
)
inline

Multiply three floating point numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
[in]zThird operand.
Returns
w Product of x, y, and z.
See also
cu_arithmetics::div

◆ mul< double >() [1/2]

Multiply two double type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Product of x and y
See also
cu_arithmetics::div

Definition at line 223 of file _cu_mul.h.

226 {
227 return x * y;
228 }

References abs().

Here is the call graph for this function:

◆ mul< double >() [2/2]

Multiply three double numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
[in]zThird operand.
Returns
w Product of x, y, and z.
See also
cu_arithmetics::div

Definition at line 367 of file _cu_mul.h.

371 {
372 return x * y * z;
373 }

References abs().

Here is the call graph for this function:

◆ mul< float >() [1/2]

template<>
__host__ __device__ float cu_arithmetics::mul< float > ( const float  x,
const float  y 
)
inline

Multiply two __nv_fp8_e5m2 type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Product of x and y
See also
cu_arithmetics::div

Multiply two __nv_fp8_e4m3 type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Product of x and y
See also
cu_arithmetics::div

Multiply two __half type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Product of x and y
See also
cu_arithmetics::div

Multiply two __nv_bfloat16 type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Product of x and y
See also
cu_arithmetics::div

Multiply two float type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Product of x and y
See also
cu_arithmetics::div

Definition at line 196 of file _cu_mul.h.

199 {
200 return x * y;
201 }

References abs().

Here is the call graph for this function:

◆ mul< float >() [2/2]

template<>
__host__ __device__ float cu_arithmetics::mul< float > ( const float  x,
const float  y,
const float  z 
)
inline

Multiply three __half numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
[in]zThird operand.
Returns
w Product of x, y, and z.
See also
cu_arithmetics::div

Multiply three __nv_bfloat16 numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
[in]zThird operand.
Returns
w Product of x, y, and z.
See also
cu_arithmetics::div

Multiply three float numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
[in]zThird operand.
Returns
w Product of x, y, and z.
See also
cu_arithmetics::div

Definition at line 337 of file _cu_mul.h.

341 {
342 return x * y * z;
343 }

References abs().

Here is the call graph for this function:

◆ sub()

template<typename DataType >
__host__ __device__ DataType cu_arithmetics::sub ( const DataType  x,
const DataType  y 
)
inline

Subtract two floating point numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Sum of x and y
See also
cu_arithmetics::add

Referenced by cuOrthogonalization< DataType >::gram_schmidt_process().

Here is the caller graph for this function:

◆ sub< double >()

Subtract two double type float numbers.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Sum of x and y
See also
cu_arithmetics::add

Definition at line 221 of file _cu_sub.h.

224 {
225 return x - y;
226 }

References abs().

Here is the call graph for this function:

◆ sub< float >()

template<>
__host__ __device__ float cu_arithmetics::sub< float > ( const float  x,
const float  y 
)
inline

Subtract two __nv_fp8_e5m2 type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Sum of x and y
See also
cu_arithmetics::add

Subtract two __nv_fp8_e4m3 type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Sum of x and y
See also
cu_arithmetics::add

Subtract two __half type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Sum of x and y
See also
cu_arithmetics::add

Subtract two __nv_bfloat16 type numbers in round-to-nearest-even mode.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Sum of x and y
See also
cu_arithmetics::add

Subtract two float type numbers.

Parameters
[in]xFirst operand.
[in]ySecond operand.
Returns
z Sum of x and y
See also
cu_arithmetics::add

Definition at line 195 of file _cu_sub.h.

198 {
199 return x - y;
200 }

References abs().

Here is the call graph for this function: