FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
cusolver.cu
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6// includes, FEAT
7#include <kernel/base_header.hpp>
8
9#include <kernel/util/exception.hpp>
10
11#include <cusolverSp.h>
12#include "cusparse_v2.h"
13
14using namespace FEAT;
15
16namespace FEAT
17{
18 namespace Solver
19 {
20 namespace Intern
21 {
22 int cuda_lu(int n, int nnzA, const double * csrValA, const int * csrRowPtrA, const int * csrColIndA,
23 const double * b, double * x)
24 {
25 cusolverSpHandle_t handle;
26 cusolverSpCreate(&handle);
27
28 cusparseMatDescr_t descr;
29 cusparseCreateMatDescr(&descr);
30 cusparseSetMatType(descr,CUSPARSE_MATRIX_TYPE_GENERAL);
31 cusparseSetMatIndexBase(descr,CUSPARSE_INDEX_BASE_ZERO);
32
33 int singularity;
34 cusolverStatus_t status = cusolverSpDcsrlsvluHost(handle, n, nnzA, descr, csrValA, csrRowPtrA, csrColIndA, b, 0.0, 1, x, &singularity);
35 if (status != CUSOLVER_STATUS_SUCCESS)
36 throw InternalError(__func__, __FILE__, __LINE__, "cusolverSpDcsrlsvluHost failed with status code: " + stringify(status));
37
38 cusparseDestroyMatDescr(descr);
39 cusolverSpDestroy(handle);
40
41 cudaDeviceSynchronize();
42#ifdef FEAT_DEBUG_MODE
43 cudaError_t last_error(cudaGetLastError());
44 if (cudaSuccess != last_error)
45 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
46#endif
47
48 return (status != CUSOLVER_STATUS_SUCCESS);
49 }
50
51
52 int cuda_qr(int m, int nnz, const double * csrValA, const int * csrRowPtrA, const int * csrColIndA,
53 const double * b, double * x)
54 {
55 cusolverSpHandle_t handle;
56 cusolverSpCreate(&handle);
57
58 cusparseMatDescr_t descr;
59 cusparseCreateMatDescr(&descr);
60 cusparseSetMatType(descr,CUSPARSE_MATRIX_TYPE_GENERAL);
61 cusparseSetMatIndexBase(descr,CUSPARSE_INDEX_BASE_ZERO);
62
63 int singularity;
64 cusolverStatus_t status = cusolverSpDcsrlsvqr(handle, m, nnz, descr, csrValA, csrRowPtrA, csrColIndA, b, 0.0, 1, x, &singularity);
65 if (status != CUSOLVER_STATUS_SUCCESS)
66 throw InternalError(__func__, __FILE__, __LINE__, "cusolverSPDcsrlvsqr failed with status code: " + stringify(status));
67
68 cusparseDestroyMatDescr(descr);
69 cusolverSpDestroy(handle);
70
71 cudaDeviceSynchronize();
72#ifdef FEAT_DEBUG_MODE
73 cudaError_t last_error(cudaGetLastError());
74 if (cudaSuccess != last_error)
75 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
76#endif
77
78 return (status != CUSOLVER_STATUS_SUCCESS);
79 }
80 }
81 }
82}