imate
C++/CUDA Reference
cuAffineMatrixFunction< DataType > Class Template Reference

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. More...
 
virtual ~cuAffineMatrixFunction ()
 Virtual destructor. More...
 
void set_parameters (DataType *t)
 
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. More...
 
- Public Member Functions inherited from cuLinearOperator< DataType >
 cuLinearOperator ()
 
 cuLinearOperator (int num_gpu_devices_)
 Constructor with setting num_rows and num_columns. More...
 
virtual ~cuLinearOperator ()
 
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. More...
 
- Public Member Functions inherited from cLinearOperator< DataType >
 cLinearOperator ()
 Default constructor. More...
 
 cLinearOperator (const LongIndexType num_rows_, const LongIndexType num_columns_)
 Constructor with setting num_rows and num_columns. More...
 
virtual ~cLinearOperator ()
 
LongIndexType get_num_rows () const
 
LongIndexType get_num_columns () const
 
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. More...
 
IndexType get_num_parameters () const
 
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. More...
 
virtual void dot (const DataType *vector, DataType *product)=0
 
virtual void transpose_dot (const DataType *vector, DataType *product)=0
 

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. More...
 
- 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. More...
 
void initialize_cublas_handle ()
 Creates a cublasHandle_t object, if not created already. More...
 
void initialize_cusparse_handle ()
 Creates a cusparseHandle_t object, if not created already. More...
 

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
 
- Protected Attributes inherited from cLinearOperator< DataType >
const LongIndexType num_rows
 
const LongIndexType num_columns
 
FlagType eigenvalue_relation_known
 
DataType * parameters
 
IndexType num_parameters
 

Detailed Description

template<typename DataType>
class cuAffineMatrixFunction< DataType >

Base class for affine matrix functions of one parameter.

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

Definition at line 40 of file cu_affine_matrix_function.h.

Constructor & Destructor Documentation

◆ cuAffineMatrixFunction()

template<typename DataType >
cuAffineMatrixFunction< DataType >::cuAffineMatrixFunction

Constructor.

Definition at line 31 of file cu_affine_matrix_function.cu.

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

References cLinearOperator< DataType >::num_parameters.

◆ ~cuAffineMatrixFunction()

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

Virtual destructor.

Definition at line 46 of file cu_affine_matrix_function.cu.

47 {
48 }

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 131 of file cu_affine_matrix_function.cu.

136 {
137  // Get device id
138  int device_id = CudaInterface<DataType>::get_device();
139 
140  // Subtracting two vectors with minus scale sign, which is adding.
142  this->cublas_handle[device_id], input_vector, vector_size, -scale,
143  output_vector);
144 }
static int get_device()
Gets the current device in multi-gpu applications.
cublasHandle_t * cublas_handle
static void subtract_scaled_vector(cublasHandle_t cublas_handle, const DataType *input_vector, const LongIndexType vector_size, const DataType scale, DataType *output_vector)
Subtracts the scaled input vector from the output vector.

References CudaInterface< 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 :math:\\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 cLinearOperator< DataType >.

Definition at line 93 of file cu_affine_matrix_function.cu.

97 {
98  ASSERT((this->eigenvalue_relation_known == 1),
99  "An eigenvalue relation is not known. This function should be "
100  "called only when the matrix B is a scalar multiple of the "
101  "identity matrix");
102 
103  // Shift the eigenvalue by the parameter
104  DataType inquiry_eigenvalue = \
105  known_eigenvalue - known_parameters[0] + inquiry_parameters[0];
106 
107  return inquiry_eigenvalue;
108 }
FlagType eigenvalue_relation_known
#define ASSERT(condition, message)
Definition: debugging.h:20

References ASSERT.

◆ set_parameters()

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

Member Data Documentation

◆ B_is_identity


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