Kokkos Core Kernels Package
Version of the Day
|
Traits class for inner product space operations on type T. More...
#include <Kokkos_InnerProductSpaceTraits.hpp>
Public Types | |
typedef T | val_type |
The type T itself. More... | |
typedef ArithTraits< T >::mag_type | mag_type |
The type returned by norm(x) for a value x of type T. More... | |
typedef T | dot_type |
The type returned by dot(x,y) for values x and y of type T. More... | |
Static Public Member Functions | |
static KOKKOS_FORCEINLINE_FUNCTION mag_type | norm (const T &x) |
The "norm" (absolute value or magnitude) of a value x of type T. More... | |
static KOKKOS_FORCEINLINE_FUNCTION dot_type | dot (const T &x, const T &y) |
The "dot product" of two values x and y of type T. More... | |
Traits class for inner product space operations on type T.
T | "Scalar" type of interest |
This class defines typedefs and functions necessary for implementing inner product space operations on finite-dimensional vector spaces over T. A <t>finite-dimensional vector space over T of dimension N is , supplied with vector space operations. An example would be the space of length N vectors of double
; a more interesting (and motivating) example would be the space of length N vectors of one of Sacado's automatic differentiation (AD) types.
An inner product space is a vector space that has an inner product. For example, we can define a "Euclidean" inner product on as follows: [ dot(x,y) := dot(x_k, y_k). ] If T is a real-valued type, then is just the ordinary product of real numbers . However, we do not require this. For example, if T is one of Sacado's AD types, we may wish to define to return a single scalar value, rather than an AD value. This is one way to use vectors of AD values in a Krylov solver, for example. (This is also why we put "Euclidean" in quotes above.)
Inner product spaces have a norm induced by their inner product. For example, given the above inner product definition, we can define a "Euclidean" norm ("two-norm") on as follows: [ norm(x) := norm(dot(x_k, x_k)). ] The result has the type of the absolute value of the product of two T values. We can express this as InnerProductSpaceTraits<InnerProductSpaceTraits<T>::dot_type>::mag_type
. For example, if InnerProductSpaceTraits<T>::dot_type
is complex, then its mag_type
is real. The "norm" of a single complex value here is just its absolute value (i.e., its magnitude).
One could also define other kinds of norms using this class. For example, a "one-norm" analogue would look like this: [ norm(x,1) := norm(x_k). ] Note the use of the "norm" of a single element of the vector, that is, a single value of type T. That could be a different function than the "norm" that takes dot_type
, which the above example uses.
All class methods must be suitable for parallel kernels, if the type T itself is suitable for parallel kernels. In particular, specializations for types T that make sense to use on a CUDA device must mark all class methods as device (and host) functions, using the KOKKOS_FORCEINLINE_FUNCTION macro. All class methods must be callable both inside and outside a parallel kernel (for CUDA, this means they must be marked as both device and host functions).
CUDA does not support long double or std::complex<T> in device functions. This class does have specializations for these types, but the class methods therein are not marked as device functions.
You must first add a specialization of ArithTraits<T>. Please note that if CUDA does not support using T in device functions, then you must not</t> mark norm() or dot() as device functions in your specialization. (Simply omit the KOKKOS_FORCEINLINE_FUNCTION macro.) If CUDA does support using T in device functions, you must mark norm() and dot() as device functions in order to use them in device functions.
Definition at line 145 of file Kokkos_InnerProductSpaceTraits.hpp.
typedef T Kokkos::Details::InnerProductSpaceTraits< T >::val_type |
The type T itself.
Definition at line 148 of file Kokkos_InnerProductSpaceTraits.hpp.
typedef ArithTraits<T>::mag_type Kokkos::Details::InnerProductSpaceTraits< T >::mag_type |
The type returned by norm(x) for a value x of type T.
Definition at line 151 of file Kokkos_InnerProductSpaceTraits.hpp.
typedef T Kokkos::Details::InnerProductSpaceTraits< T >::dot_type |
The type returned by dot(x,y) for values x and y of type T.
Definition at line 154 of file Kokkos_InnerProductSpaceTraits.hpp.
|
inlinestatic |
The "norm" (absolute value or magnitude) of a value x of type T.
Definition at line 157 of file Kokkos_InnerProductSpaceTraits.hpp.
|
inlinestatic |
The "dot product" of two values x and y of type T.
Definition at line 161 of file Kokkos_InnerProductSpaceTraits.hpp.