17#include "../_cu_definitions/cu_types.h"
20#include "../_cu_basic_algebra/cu_vector_operations.h"
21#include "../_cu_trace_estimator/cu_orthogonalization.h"
22#include "../_cuda_utilities/cuda_api.h"
23#include "../_cu_arithmetics/cu_arithmetics.h"
27 #pragma warning(push, 0)
28 #include <cublas_v2.h>
30#elif defined(__INTEL_LLVM_COMPILER) || defined(__INTEL_COMPILER)
31 #pragma warning(push, 0)
32 #include <cublas_v2.h>
34#elif defined(__GNUC__) || defined(__clang__)
35 #pragma GCC diagnostic push
36 #pragma GCC diagnostic ignored "-Wswitch-enum"
37 #include <cublas_v2.h>
38 #pragma GCC diagnostic pop
40 #include <cublas_v2.h>
132template <
typename DataType>
138 const DataType lanczos_tol,
148 if (orthogonalize == 0)
153 else if ((orthogonalize < 0) ||
154 (orthogonalize >
static_cast<FlagType>(m) - 1))
163 buffer_size = orthogonalize + 1;
175 cublas_handle, &device_V[0], n);
183 for (j=0; j < m; ++j)
189 A->
dot(&device_V[(j % buffer_size)*n], &device_U[(j % buffer_size)*n]);
196 &device_U[((j-1) % buffer_size)*n], n, beta[j-1],
197 &device_U[(j % buffer_size)*n]);
201 if (orthogonalize != 0)
210 num_ortho = buffer_size - 1;
217 cublas_handle, &device_U[0], n, buffer_size,
218 (j-1)%buffer_size, num_ortho,
219 &device_U[(j % buffer_size)*n]);
225 cublas_handle, &device_U[(j % buffer_size)*n], n);
229 &device_V[((j+1) % buffer_size)*n]);
233 cublas_handle, &device_V[(j % buffer_size)*n], n, alpha[j],
234 &device_V[((j+1) % buffer_size)*n]);
237 if (orthogonalize != 0)
240 cublas_handle, &device_V[0], n, buffer_size, j%buffer_size,
241 num_ortho, &device_V[((j+1) % buffer_size)*n]);
246 cublas_handle, &device_V[((j+1) % buffer_size)*n], n);
254 static_cast<double>(std::sqrt(n)))
275#if defined(USE_CUDA_FP8_E5M2) && (USE_CUDA_FP8_E5M2 == 1)
276 template IndexType cu_golub_kahn_bidiagonalization<__nv_fp8_e5m2>(
288#if defined(USE_CUDA_FP8_E4M3) && (USE_CUDA_FP8_E4M3 == 1)
289 template IndexType cu_golub_kahn_bidiagonalization<__nv_fp8_e4m3>(
301#if defined(USE_CUDA_FP16) && (USE_CUDA_FP16 == 1)
302 template IndexType cu_golub_kahn_bidiagonalization<__half>(
307 const __half lanczos_tol,
314#if defined(USE_CUDA_BF16) && (USE_CUDA_BF16 == 1)
315 template IndexType cu_golub_kahn_bidiagonalization<__nv_bfloat16>(
317 const __nv_bfloat16* v,
320 const __nv_bfloat16 lanczos_tol,
322 __nv_bfloat16* alpha,
323 __nv_bfloat16* beta);
327#if defined(USE_CUDA_FP32) && (USE_CUDA_FP32 == 1)
333 const float lanczos_tol,
340#if defined(USE_CUDA_FP64) && (USE_CUDA_FP64 == 1)
346 const double lanczos_tol,
static ArrayType * alloc(const size_t array_size)
Allocates memory on gpu device. This function creates a pointer and returns it.
static void del(void *device_array)
Deletes memory on gpu device if its pointer is not NULL, then sets the pointer to NULL.
static void copy_to_device(const ArrayType *host_array, const size_t array_size, ArrayType *device_array)
Copies memory on host to device memory.
Base class for linear operators. This class serves as interface for all derived classes.
virtual void dot(const DataType *vector, DataType *product)=0
cublasHandle_t get_cublas_handle() const
This function returns a reference to the cublasHandle_t object. The object will be created,...
virtual void transpose_dot(const DataType *vector, DataType *product)=0
static void gram_schmidt_process(cublasHandle_t cublas_handle, const DataType *V, const LongIndexType vector_size, const IndexType num_vectors, const IndexType last_vector, const FlagType num_ortho, DataType *r)
Modified Gram-Schmidt orthogonalization process to orthogonalize the vector v against a subset of the...
static DataType normalize_vector_in_place(cublasHandle_t cublas_handle, DataType *RESTRICT vector, const LongIndexType vector_size)
Normalizes a vector based on Euclidean 2-norm. The result is written in-place.
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.
template IndexType cu_golub_kahn_bidiagonalization< double >(cuLinearOperator< double > *A, const double *v, const LongIndexType n, const IndexType m, const double lanczos_tol, const FlagType orthogonalize, double *alpha, double *beta)
IndexType cu_golub_kahn_bidiagonalization(cuLinearOperator< DataType > *A, const DataType *v, const LongIndexType n, const IndexType m, const DataType lanczos_tol, const FlagType orthogonalize, DataType *alpha, DataType *beta)
Bi-diagonalizes the positive-definite matrix A using Golub-Kahn-Lanczos method.
template IndexType cu_golub_kahn_bidiagonalization< float >(cuLinearOperator< float > *A, const float *v, const LongIndexType n, const IndexType m, const float lanczos_tol, const FlagType orthogonalize, float *alpha, float *beta)
__host__ __device__ DataType mul(const DataType x, const DataType y)
Multiply two floating point numbers in round-to-nearest-even mode.
__host__ __device__ DataType abs(const DataType x)
Absolute value of a floating point number.