imate
C++/CUDA Reference
Loading...
Searching...
No Matches
cuAffineMatrixFunction< DataType > Class Template Referenceabstract

Base class for affine matrix functions of one parameter. More...

#include <cu_affine_matrix_function.h>

Inheritance diagram for cuAffineMatrixFunction< DataType >:
Collaboration diagram for cuAffineMatrixFunction< DataType >:

Public Member Functions

 cuAffineMatrixFunction ()
 Constructor.
 
virtual ~cuAffineMatrixFunction ()
 Virtual destructor.
 
void set_parameters (DataType *t)
 
virtual void set_symmetry (FlagType symmetric)=0
 
DataType get_eigenvalue (const DataType *known_parameters, const DataType known_eigenvalue, const DataType *inquiry_parameters) const
 This function defines an analytic relationship between a given set of parameters and the corresponding eigenvalue of the operator. Namely, given a set of parameters and a known eigenvalue of the operator for that specific set of parameters, this function obtains the eigenvalue of the operator for an other given set of parameters.
 
- Public Member Functions inherited from cuLinearOperator< DataType >
 cuLinearOperator ()
 Default constructor.
 
 cuLinearOperator (const int num_gpu_devices_)
 Constructor with setting num_rows and num_columns.
 
virtual ~cuLinearOperator ()
 Destructor.
 
cublasHandle_t get_cublas_handle () const
 This function returns a reference to the cublasHandle_t object. The object will be created, if it is not created already.
 
void set_parameters (DataType *parameters_)
 Sets the scalar parameter this->parameters. Parameter is initialized to NULL. However, before calling dot or transpose_dot functions, the parameters must be set.
 
virtual void dot (const DataType *vector, DataType *product)=0
 
virtual void transpose_dot (const DataType *vector, DataType *product)=0
 
- Public Member Functions inherited from cLinearOperatorBase
 cLinearOperatorBase ()
 Default constructor.
 
 cLinearOperatorBase (const LongIndexType num_rows_, const LongIndexType num_columns_)
 Constructor with setting num_rows and num_columns.
 
virtual ~cLinearOperatorBase ()
 Destructor.
 
LongIndexType get_num_rows () const
 Returns the number of rows of the matrix.
 
LongIndexType get_num_columns () const
 Returns the number of columns of the matrix.
 
IndexType get_num_parameters () const
 Returns the number of parameters of the linear operator.
 
FlagType is_eigenvalue_relation_known () const
 Returns a flag that determines whether a relation between the parameters of the operator and its eigenvalue(s) is known.
 

Protected Member Functions

void _add_scaled_vector (const DataType *input_vector, const LongIndexType vector_size, const DataType scale, DataType *output_vector) const
 Performs the operation \( \boldsymbol{c} = \boldsymbol{c} + \alpha \boldsymbol{b} \), where \( \boldsymbol{b} \) is an input vector scaled by \( \alpha \) and \( \boldsymbol{c} \) it the output vector.
 
- Protected Member Functions inherited from cuLinearOperator< DataType >
int query_gpu_devices () const
 Before any numerical computation, this method chechs if any gpu device is available on the machine, or notifies the user if nothing was found.
 
void initialize_cublas_handle ()
 Creates a cublasHandle_t object, if not created already.
 
void initialize_cusparse_handle ()
 Creates a cusparseHandle_t object, if not created already.
 

Protected Attributes

bool B_is_identity
 
- Protected Attributes inherited from cuLinearOperator< DataType >
int num_gpu_devices
 
bool copied_host_to_device
 
cublasHandle_t * cublas_handle
 
cusparseHandle_t * cusparse_handle
 
DataType * parameters
 
- Protected Attributes inherited from cLinearOperatorBase
const LongIndexType num_rows
 
const LongIndexType num_columns
 
FlagType eigenvalue_relation_known
 
IndexType num_parameters
 

Detailed Description

template<typename DataType>
class cuAffineMatrixFunction< DataType >

Base class for affine matrix functions of one parameter.

The cuAffineMatrixFunction holds a two two-dimensional dense matrices \( \mathbf{A} \) and \( \mathbf{B} \). The affine matrix function with the parameter \( t \) is defined by:

\[ t \mapsto \mathbf{A} + t \mathbf{B}. \]

This operoator can perofrom matrix-vector product and transposed matrix-vector product.

Note
The prefix c in this class's name (and its derivatves), stands for the cpp code, intrast to the cu prefix, which stands for the cuda code. Most derived classes have a cuda counterpart.
See also
cuMatrix, cuDenseAffineMatricFunction, cuCSRAffineMatrixFunction, cuCSCAffineMatrixFunction, cuLinearOperator, cAffineMatrixFunction

Definition at line 55 of file cu_affine_matrix_function.h.

Constructor & Destructor Documentation

◆ cuAffineMatrixFunction()

template<typename DataType >
cuAffineMatrixFunction< DataType >::cuAffineMatrixFunction ( )

Constructor.

Definition at line 34 of file cu_affine_matrix_function.cu.

34 :
35 B_is_identity(false)
36{
37 // This class has one parameter that is t in A+tB
38 this->num_parameters = 1;
39}

References cLinearOperatorBase::num_parameters.

◆ ~cuAffineMatrixFunction()

template<typename DataType >
cuAffineMatrixFunction< DataType >::~cuAffineMatrixFunction ( )
virtual

Virtual destructor.

Definition at line 50 of file cu_affine_matrix_function.cu.

51{
52}

Member Function Documentation

◆ _add_scaled_vector()

template<typename DataType >
void cuAffineMatrixFunction< DataType >::_add_scaled_vector ( const DataType *  input_vector,
const LongIndexType  vector_size,
const DataType  scale,
DataType *  output_vector 
) const
protected

Performs the operation \( \boldsymbol{c} = \boldsymbol{c} + \alpha \boldsymbol{b} \), where \( \boldsymbol{b} \) is an input vector scaled by \( \alpha \) and \( \boldsymbol{c} \) it the output vector.

Parameters
[in]input_vectorThe input 1D vector of size vector_size.
[in]vector_sizeThe size of both input_vector and output_vector
[in]scaleThe scalar scale at whch the input vector is multiplied by.
[in,out]output_vectorThe output 1D vector of size vector_size. This array will be written in-place.

Definition at line 140 of file cu_affine_matrix_function.cu.

145{
146 // Get device id
147 int device_id = CudaAPI<DataType>::get_device();
148
149 // Negative of scale (negate in double type as some types like
150 // __nv_fp8_exmx does not yet support such operation yet)
151 DataType neg_scale = cu_arithmetics::cast<double, DataType>(
153
154 // Subtracting two vectors with minus scale sign, which is adding.
156 this->cublas_handle[device_id], input_vector, vector_size,
157 neg_scale, output_vector);
158}
static int get_device()
Gets the current device in multi-gpu applications.
Definition cuda_api.cu:209
cublasHandle_t * cublas_handle
static void subtract_scaled_vector(cublasHandle_t cublas_handle, const DataType *RESTRICT input_vector, const LongIndexType vector_size, const DataType scale, DataType *RESTRICT output_vector)
Subtracts the scaled input vector from the output vector.
__host__ __device__ DataType abs(const DataType x)
Absolute value of a floating point number.

References cu_arithmetics::abs(), CudaAPI< ArrayType >::get_device(), and cuVectorOperations< DataType >::subtract_scaled_vector().

Here is the call graph for this function:

◆ get_eigenvalue()

template<typename DataType >
DataType cuAffineMatrixFunction< DataType >::get_eigenvalue ( const DataType *  known_parameters,
const DataType  known_eigenvalue,
const DataType *  inquiry_parameters 
) const
virtual

This function defines an analytic relationship between a given set of parameters and the corresponding eigenvalue of the operator. Namely, given a set of parameters and a known eigenvalue of the operator for that specific set of parameters, this function obtains the eigenvalue of the operator for an other given set of parameters.

A relation between eigenvalue(s) and the set of parameters can be made when the matrix \( \mathbf{B} \) is equal to the identity matrix \( \mathbf{I} \), and corresponding linear operator is as follows:

\[ \mathbf{A}(t) = \mathbf{A} + t \mathbf{I} \]

Then, the eigenvalues \( \lambda \) of the operator is

\[ \lambda(\mathbf{A}(t)) = \lambda(\mathbf{A}) + t. \]

Thus, by knowing the eigenvalue \( \lambda_{t_0} \) at the known parameter \( t_0 \), the eigenvalue \( \lambda_{t} \) at the inquiry parameter \( t \) can be obtained.

Parameters
[in]known_parametersA set of parameters of the operator where the corresponding eigenvalue of the parameter is known for.
[in]known_eigenvalueThe known eigenvalue of the operator for the known parameters.
[in]inquiry_parametersA set of inquiry parameters of the operator where the corresponding eigenvalue of the operator is sought.
Returns
The eigenvalue of the operator corresponding the inquiry parameters.

Implements cuLinearOperator< DataType >.

Definition at line 97 of file cu_affine_matrix_function.cu.

101{
103 "An eigenvalue relation is not known. This function should be "
104 "called only when the matrix B is a scalar multiple of the "
105 "identity matrix");
106
107 // Shift the eigenvalue by the parameter
108 DataType inquiry_eigenvalue = \
109 cu_arithmetics::add<DataType>(
111 known_eigenvalue,
112 known_parameters[0]),
113 inquiry_parameters[0]
114 );
115
116 return inquiry_eigenvalue;
117}
#define ASSERT(condition, message)
Definition debugging.h:20

References cu_arithmetics::abs(), and ASSERT.

Here is the call graph for this function:

◆ set_parameters()

template<typename DataType >
void cuAffineMatrixFunction< DataType >::set_parameters ( DataType *  t)

◆ set_symmetry()

template<typename DataType >
virtual void cuAffineMatrixFunction< DataType >::set_symmetry ( FlagType  symmetric)
pure virtual

Member Data Documentation

◆ B_is_identity


The documentation for this class was generated from the following files: