imate
C++/CUDA Reference
cu_affine_matrix_function.cu
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright 2021, Siavash Ameli <sameli@berkeley.edu>
3  * SPDX-License-Identifier: BSD-3-Clause
4  * SPDX-FileType: SOURCE
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the license found in the LICENSE.txt file in the root
8  * directory of this source tree.
9  */
10 
11 
12 // =======
13 // Headers
14 // =======
15 
17 #include <cassert> // assert
18 #include "../_definitions/debugging.h" // ASSERT
19 #include "../_cu_basic_algebra/cu_vector_operations.h" // cuVectorOperations
20 #include "../_cuda_utilities/cuda_interface.h" // CudaInterface
21 
22 
23 // ===========
24 // constructor
25 // ===========
26 
29 
30 template <typename DataType>
32  B_is_identity(false)
33 {
34  // This class has one parameter that is t in A+tB
35  this->num_parameters = 1;
36 }
37 
38 
39 // ==========
40 // destructor
41 // ==========
42 
44 
45 template <typename DataType>
47 {
48 }
49 
50 
51 // ==============
52 // get eigenvalue
53 // ==============
54 
91 
92 template <typename DataType>
94  const DataType* known_parameters,
95  const DataType known_eigenvalue,
96  const DataType* inquiry_parameters) const
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 }
109 
110 
111 // =================
112 // add scaled vector
113 // =================
114 
129 
130 template <typename DataType>
132  const DataType* input_vector,
133  const LongIndexType vector_size,
134  const DataType scale,
135  DataType* output_vector) const
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 }
145 
146 
147 // ===============================
148 // Explicit template instantiation
149 // ===============================
150 
151 template class cuAffineMatrixFunction<float>;
152 template class cuAffineMatrixFunction<double>;
static int get_device()
Gets the current device in multi-gpu applications.
IndexType num_parameters
Base class for affine matrix functions of one parameter.
virtual ~cuAffineMatrixFunction()
Virtual destructor.
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 correspondin...
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.
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.
#define ASSERT(condition, message)
Definition: debugging.h:20
int LongIndexType
Definition: types.h:60