Math wrappers

group NVCV_CPP_CUDATOOLS_MATHWRAPPERS

Defines

NVCV_CUDA_BINARY_SIMD(TYPE_U, INTRINSIC)
NVCV_CUDA_UNARY_SIMD(TYPE_U, INTRINSIC)

Enums

enum class RoundMode : int

Values:

enumerator NEAREST
enumerator DOWN
enumerator UP
enumerator ZERO
enumerator DEFAULT

Functions

template<RoundMode RM, typename T, typename U, class = Require<(!std::is_same_v<T, U>)&&((NumComponents<T> == NumComponents<U>)                                                   || (NumComponents<T> == 0 && HasTypeTraits<U>))>> inline __host__ __device__ auto round (U u)

Metafunction to round all elements of the input.

This function rounds all elements of the input and returns the result with the same type as the input. Optionally, the base type of the result may be specified by the template argument type T. For instance, a float4 can have its 4 elements rounded into a float4 result, or to a different result type, such as T=int or T=int4, where the result will be int4 with the rounded results (see example below). Also optionally, the round mode RM can be specified, as one of RoundMode, e.g. RoundMode::DOWN. It is a requirement of round that the input source type has type traits and the optional result type T is either a regular C type or has the same number of components as the input type.

using FloatType = MakeType<float, 4>;
FloatType res = ...;
FloatType float_rounded = round(res);
ConvertBaseTypeTo<int, FloatType> int_rounded = round<int>(res);
Template Parameters
  • RM – Optional round mode to be used, cf. RoundMode.

  • U – Type of the source value (with 1 to 4 elements) passed as (and inferred from) argument u.

  • T – Optional type that defines the result of the round.

Parameters

u[in] Source value to round all elements with its same type or T.

Returns

The value with all elements rounded.

template<typename T, typename U, class = Require<(!std::is_same_v<T, U>)&&((NumComponents<T> == NumComponents<U>)                                                   || (NumComponents<T> == 0 && HasTypeTraits<U>))>> inline __host__ __device__ auto round (U u)

Overload of round function.

It does specifies target round type T and uses default round mode RoundMode::DEFAULT.

template<RoundMode RM, typename U> inline __host__ __device__ auto round (U u)

Overload of round function.

It does not specify target round type T, using input source type U instead.

template<typename U> inline __host__ __device__ auto round (U u)

Overload of round function.

It does not specify target round type T, using input source type U instead, and uses default round mode RoundMode::DEFAULT.

template<typename U, class = Require<HasTypeTraits<U>>> inline __host__ __device__ U min (U a, U b)

Metafunction to compute the minimum of two inputs per element.

This function finds the minimum of two inputs per element and returns the result with the same type as the input. For instance, two int4 inputs {1, 2, 3, 4} and {4, 3, 2, 1} yield the minimum {1, 2, 2, 1} as int4 as well (see example below). It is a requirement of min that the input source type has type traits.

using IntType = MakeType<int, 4>;
IntType a = {1, 2, 3, 4}, b = {4, 3, 2, 1};
IntType ab_min = min(a, b); // = {1, 2, 2, 1}
Template Parameters

U – Type of the two source arguments and the return type.

Parameters

u[in] Input value to compute \( min(x_a, x_b) \) where \( x_a \) ( \( x_b \)) is each element of \( a \) ( \( b \)).

Returns

The return value with one minimum per element.

template<typename U, class = Require<HasTypeTraits<U>>> inline __host__ __device__ U max (U a, U b)

Metafunction to compute the maximum of two inputs per element.

This function finds the maximum of two inputs per element and returns the result with the same type as the input. For instance, two int4 inputs {1, 2, 3, 4} and {4, 3, 2, 1} yield the maximum {4, 3, 3, 4} as int4 as well (see example below). It is a requirement of max that the input source type has type traits.

using IntType = MakeType<int, 4>;
IntType a = {1, 2, 3, 4}, b = {4, 3, 2, 1};
IntType ab_max = max(a, b); // = {4, 3, 3, 4}
Template Parameters

U – Type of the two source arguments and the return type.

Parameters

u[in] Input value to compute \( max(x_a, x_b) \) where \( x_a \) ( \( x_b \)) is each element of \( a \) ( \( b \)).

Returns

The return value with maximums per element.

template<typename U, typename S, class = Require<(NumComponents<U> == NumComponents<S>) || (HasTypeTraits<U> && NumComponents<S> == 0)>> inline __host__ __device__ U pow (U x, S y)

Metafunction to compute the power of all elements of the input.

This function computes the power of all elements of the input x and returns the result with the same type as the input. It is a requirement of pow that the input x has the same number of components of the power y or y is a scalar (and the type of x has type traits).

Template Parameters
  • U – Type of the source argument x and the return type.

  • S – Type of the source argument y power (use a regular C type for scalar).

Parameters
  • x[in] Input value to compute \( x^y \).

  • y[in] Input power to compute \( x^y \).

Returns

The return value with all elements as the result of the power.

template<typename U, class = Require<HasTypeTraits<U>>> inline __host__ __device__ U exp (U u)

Metafunction to compute the natural (base e) exponential of all elements of the input.

This function computes the natural (base e) exponential of all elements of the input and returns the result with the same type as the input. It is a requirement of exp that the input source type has type traits.

Template Parameters

U – Type of the source argument and the return type.

Parameters

u[in] Input value to compute \( e^x \) where \( x \) is each element of \( u \).

Returns

The return value with all elements as the result of the natural (base e) exponential.

template<typename U, class = Require<HasTypeTraits<U>>> inline __host__ __device__ U sqrt (U u)

Metafunction to compute the square root of all elements of the input.

This function computes the square root of all elements of the input and returns the result with the same type as the input. It is a requirement of sqrt that the input source type has type traits.

Template Parameters

U – Type of the source argument and the return type.

Parameters

u[in] Input value to compute \( \sqrt{x} \) where \( x \) is each element of \( u \).

Returns

The return value with all elements as the result of the square root.

template<typename U, class = Require<HasTypeTraits<U>>> inline __host__ __device__ U abs (U u)

Metafunction to compute the absolute value of all elements of the input.

This function computes the absolute value of all elements of the input and returns the result with the same type as the input. For instance, an int4 input {-1, 2, -3, 4} yields the absolute {1, 2, 3, 4} as int4 as well (see example below). It is a requirement of abs that the input source type has type traits.

using IntType = MakeType<int, 4>;
IntType a = {-1, 2, -3, 4};
IntType a_abs = abs(a); // = {1, 2, 3, 4}
Template Parameters

U – Type of the source argument and the return type.

Parameters

u[in] Input value to compute \( |x| \) where \( x \) is each element of \( u \).

Returns

The return value with the absolute of all elements.

template<typename U, typename S, class = Require<(NumComponents<U> == NumComponents<S>) || (HasTypeTraits<U> && NumComponents<S> == 0)>> inline __host__ __device__ U clamp (U u, S lo, S hi)

Metafunction to clamp all elements of the input.

This function clamps all elements of the input u between lo and hi and returns the result with the same type as the input. It is a requirement of clamp that the input u has the same number of components of the range values lo and hi or both are scalars (and the type of u has type traits).

Template Parameters
  • U – Type of the source argument u and the return type.

  • S – Type of the source argument lo and hi (use a regular C type for scalar).

Parameters
  • u[in] Input value to clamp.

  • lo[in] Input clamp range low value.

  • hi[in] Input clamp range high value.

Returns

The return value with all elements clamped.