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

Container for dense affine matrix functions of one parameter. More...

#include <cu_dense_affine_matrix_function.h>

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

Public Member Functions

 cuDenseAffineMatrixFunction (const DataType *A_, const LongIndexType num_rows_, const LongIndexType num_columns_, const FlagType A_is_row_major_, const FlagType A_is_symmetric_, const int num_gpu_devices_)
 Default constructor.
 
 cuDenseAffineMatrixFunction (const DataType *A_, const LongIndexType num_rows_, const LongIndexType num_columns_, const FlagType A_is_row_major_, const FlagType A_is_symmetric_, const DataType *B_, const FlagType B_is_row_major_, const FlagType B_is_symmetric_, const int num_gpu_devices_)
 Constructor.
 
virtual ~cuDenseAffineMatrixFunction ()
 Destructor.
 
virtual void set_symmetry (const FlagType symmetric)
 Specify whether the matrices are symmetic or non-symmetric.
 
virtual void dot (const DataType *vector, DataType *product)
 Matrix vector product.
 
virtual void transpose_dot (const DataType *vector, DataType *product)
 Matrix vector product written in place.
 
- Public Member Functions inherited from cuAffineMatrixFunction< DataType >
 cuAffineMatrixFunction ()
 Constructor.
 
virtual ~cuAffineMatrixFunction ()
 Virtual destructor.
 
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.
 
- 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.
 
- 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 Attributes

cuDenseMatrix< DataType > A
 
cuDenseMatrix< DataType > B
 
- Protected Attributes inherited from cuAffineMatrixFunction< DataType >
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
 

Additional Inherited Members

- Protected Member Functions inherited from cuAffineMatrixFunction< DataType >
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.
 

Detailed Description

template<typename DataType>
class cuDenseAffineMatrixFunction< DataType >

Container for dense affine matrix functions of one parameter.

The cuDenseAffineMatrixFunction contains two-dimensional dense matrices A and B. This operoator can perofrom matrix-vector product and transposed matrix-vector product.

See also
cuAffineMatrixFunction, cuCSRMatrixFunction, cuCSCMatrixFunction, cuDenseMatrix, cDenseAffineMatrixFunction

Definition at line 45 of file cu_dense_affine_matrix_function.h.

Constructor & Destructor Documentation

◆ cuDenseAffineMatrixFunction() [1/2]

template<typename DataType >
cuDenseAffineMatrixFunction< DataType >::cuDenseAffineMatrixFunction ( const DataType *  A_,
const LongIndexType  num_rows_,
const LongIndexType  num_columns_,
const FlagType  A_is_row_major_,
const FlagType  A_is_symmetric_,
const int  num_gpu_devices_ 
)

Default constructor.

Matrix B is assumed to be the identity matrix.

Parameters
[in]A_1D array that represents a 2D dense array with either C (row) major ordering or Fortran (column) major ordering. The major ordering should de defined by A_is_row_major flag.
[in]num_rows_Number of rows of A and B
[in]num_columns_Number of columns of A and B
[in]A_is_row_major_Boolean, can be 0 or 1 as follows:
  • If A is row major (C ordering where the last index is contiguous) this value should be 1.
  • If A is column major (Fortran ordering where the first index is contiguous), this value should be set to 0.
[in]A_is_symmetric_Boolean. If A is symmetric, set this value to 1, otherwise 0.
[in]num_gpu_devices_Number of GPU devices to be utilized for parallelization.

Definition at line 53 of file cu_dense_affine_matrix_function.cu.

59 :
60
61 // Base class constructor
62 cLinearOperatorBase(num_rows_, num_columns_),
63 cuLinearOperator<DataType>(num_gpu_devices_),
64
65 // Initializer list
66 A(A_, num_rows_, num_columns_, A_is_row_major_, A_is_symmetric_,
67 num_gpu_devices_)
68{
69 // This constructor is called assuming B is identity
70 this->B_is_identity = true;
71
72 // When B is identity, the eigenvalues of A+tB are known for any t
74
75 // Set gpu device
77}
cLinearOperatorBase()
Default constructor.
Base class for linear operators. This class serves as interface for all derived classes.
void initialize_cublas_handle()
Creates a cublasHandle_t object, if not created already.

References cuAffineMatrixFunction< DataType >::B_is_identity, cLinearOperatorBase::eigenvalue_relation_known, and cuLinearOperator< DataType >::initialize_cublas_handle().

Here is the call graph for this function:

◆ cuDenseAffineMatrixFunction() [2/2]

template<typename DataType >
cuDenseAffineMatrixFunction< DataType >::cuDenseAffineMatrixFunction ( const DataType *  A_,
const LongIndexType  num_rows_,
const LongIndexType  num_columns_,
const FlagType  A_is_row_major_,
const FlagType  A_is_symmetric_,
const DataType *  B_,
const FlagType  B_is_row_major_,
const FlagType  B_is_symmetric_,
const int  num_gpu_devices_ 
)

Constructor.

Matrix B is assumed to be the identity matrix.

Parameters
[in]A_1D array that represents a 2D dense array with either C (row) major ordering or Fortran (column) major ordering. The major ordering should de defined by A_is_row_major flag.
[in]num_rows_Number of rows of A and B
[in]num_columns_Number of columns of A and B
[in]A_is_row_major_Boolean, can be 0 or 1 as follows:
  • If A is row major (C ordering where the last index is contiguous) this value should be 1.
  • If A is column major (Fortran ordering where the first index is contiguous), this value should be set to 0.
[in]A_is_symmetric_Boolean. If A is symmetric, set this value to 1, otherwise 0.
[in]B_1D array that represents a 2D dense array with either C (row) major ordering or Fortran (column) major ordering. The major ordering should de defined by A_is_row_major flag.
[in]B_is_row_major_Boolean, can be 0 or 1 as follows:
  • If B is row major (C ordering where the last index is contiguous) this value should be 1.
  • If B is column major (Fortran ordering where the first index is contiguous), this value should be set to 0.
[in]B_is_symmetric_Boolean. If B is symmetric, set this value to 1, otherwise 0.
[in]num_gpu_devices_Number of GPU devices to be utilized for parallelization.

Definition at line 122 of file cu_dense_affine_matrix_function.cu.

131 :
132
133 // Base class constructor
134 cLinearOperatorBase(num_rows_, num_columns_),
135 cuLinearOperator<DataType>(num_gpu_devices_),
136
137 // Initializer list
138 A(A_, num_rows_, num_columns_, A_is_row_major_, A_is_symmetric_,
139 num_gpu_devices_),
140 B(B_, num_rows_, num_columns_, B_is_row_major_, B_is_symmetric_,
141 num_gpu_devices_)
142{
143 // Matrix B is assumed to be non-zero. Check if it is identity or generic
144 if (this->B.is_identity_matrix())
145 {
146 this->B_is_identity = true;
148 }
149
150 // Set gpu device
152}

References cuDenseAffineMatrixFunction< DataType >::B, cuAffineMatrixFunction< DataType >::B_is_identity, cLinearOperatorBase::eigenvalue_relation_known, and cuLinearOperator< DataType >::initialize_cublas_handle().

Here is the call graph for this function:

◆ ~cuDenseAffineMatrixFunction()

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

Destructor.

Definition at line 163 of file cu_dense_affine_matrix_function.cu.

164{
165}

Member Function Documentation

◆ dot()

template<typename DataType >
void cuDenseAffineMatrixFunction< DataType >::dot ( const DataType *  vector,
DataType *  product 
)
virtual

Matrix vector product.

Performs the matrix vector product \( \boldsymbol{y} = (\mathbf{A} + t \mathbf{B}) \boldsymbol{x} \).

Parameters
[in]vectorA one-dimensional input vector \( \boldsymbol{x} \) with size the of the number of columns of the matrix \( \mathbf{A} \). This array should be on GPU device.
[out]productA one-dimensional output vector \( \boldsymbol{y} \) with the size of the number of rows of \( \mathbf{A} \). This vector will be overwritten. This array should be on GPU device.
See also
cuDenseAffineMatrixFunction::transpose_dot

Implements cuLinearOperator< DataType >.

Definition at line 222 of file cu_dense_affine_matrix_function.cu.

225{
226 // Matrix A times vector
227 this->A.dot(vector, product);
228 LongIndexType min_vector_size;
229
230 // Matrix B times vector to be added to the product
231 if (this->B_is_identity)
232 {
233 // Check parameter is set
234 ASSERT((this->parameters != NULL), "Parameter is not set.");
235
236 // Find minimum of the number of rows and columns
237 min_vector_size = \
238 (this->num_rows < this->num_columns) ? \
239 this->num_rows : this->num_columns;
240
241 // Adding input vector to product
242 this->_add_scaled_vector(vector, min_vector_size,
243 this->parameters[0], product);
244 }
245 else
246 {
247 // Check parameter is set
248 ASSERT((this->parameters != NULL), "Parameter is not set.");
249
250 // Adding parameter times B times input vector to the product
251 this->B.dot_plus(vector, this->parameters[0], product);
252 }
253}
const LongIndexType num_rows
const LongIndexType num_columns
void _add_scaled_vector(const DataType *input_vector, const LongIndexType vector_size, const DataType scale, DataType *output_vector) const
Performs the operation , where is an input vector scaled by and it the output vector.
#define ASSERT(condition, message)
Definition debugging.h:20
int LongIndexType
Definition types.h:60

References ASSERT.

◆ set_symmetry()

template<typename DataType >
void cuDenseAffineMatrixFunction< DataType >::set_symmetry ( const FlagType  symmetric)
virtual

Specify whether the matrices are symmetic or non-symmetric.

This function overwrites the symmetry status that has been set by the constructor. Note that the symmetry status of both matrices \( \mathbf{A} \) and \( \mathbf{B} \) in the linear operator \( \mathbf{A} + t \mathbf{B} \) will be set together.

Parameters
[in]symmetricBoolean. If set to 1, the matrix is assumed to be symmetric. Otherwiese non-symmetric.

Implements cuAffineMatrixFunction< DataType >.

Definition at line 185 of file cu_dense_affine_matrix_function.cu.

187{
188 if (symmetric == 1)
189 {
190 this->A.set_symmetry(1);
191 this->B.set_symmetry(1);
192 }
193 else
194 {
195 this->A.set_symmetry(0);
196 this->B.set_symmetry(0);
197 }
198}

◆ transpose_dot()

template<typename DataType >
void cuDenseAffineMatrixFunction< DataType >::transpose_dot ( const DataType *  vector,
DataType *  product 
)
virtual

Matrix vector product written in place.

Performs the matrix vector product \( \boldsymbol{y} = (\mathbf{A} + t \mathbf{B})^{\intercal} \boldsymbol{x} \).

Parameters
[in]vectorA one-dimensional input vector \( \boldsymbol{x} \) with size the of the number of columns of the matrix \( \mathbf{A} \). This array should be on GPU device.
[out]productA one-dimensional output vector \( \boldsymbol{y} \) with the size of the number of rows of \( \mathbf{A} \). This array should be on GPU device.
See also
cuDenseAffineMatrixFunction::dot

Implements cuLinearOperator< DataType >.

Definition at line 277 of file cu_dense_affine_matrix_function.cu.

280{
281 // Matrix A times vector
282 this->A.transpose_dot(vector, product);
283 LongIndexType min_vector_size;
284
285 // Matrix B times vector to be added to the product
286 if (this->B_is_identity)
287 {
288 // Check parameter is set
289 ASSERT((this->parameters != NULL), "Parameter is not set.");
290
291 // Find minimum of the number of rows and columns
292 min_vector_size = \
293 (this->num_rows < this->num_columns) ? \
294 this->num_rows : this->num_columns;
295
296 // Adding input vector to product
297 this->_add_scaled_vector(vector, min_vector_size,
298 this->parameters[0], product);
299 }
300 else
301 {
302 // Check parameter is set
303 ASSERT((this->parameters != NULL), "Parameter is not set.");
304
305 // Adding "parameter * B * input vector" to the product
306 this->B.transpose_dot_plus(vector, this->parameters[0], product);
307 }
308}

References ASSERT.

Member Data Documentation

◆ A

template<typename DataType >
cuDenseMatrix<DataType> cuDenseAffineMatrixFunction< DataType >::A
protected

Definition at line 84 of file cu_dense_affine_matrix_function.h.

◆ B

template<typename DataType >
cuDenseMatrix<DataType> cuDenseAffineMatrixFunction< DataType >::B
protected

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