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.
 
    7#include <kernel/base_header.hpp>
 
    9#include <kernel/util/exception.hpp>
 
   11#include <cusolverSp.h>
 
   12#include "cusparse_v2.h"
 
   22      int cuda_lu(int n, int nnzA, const double * csrValA, const int * csrRowPtrA, const int * csrColIndA,
 
   23          const double * b, double * x)
 
   25        cusolverSpHandle_t handle;
 
   26        cusolverSpCreate(&handle);
 
   28        cusparseMatDescr_t descr;
 
   29        cusparseCreateMatDescr(&descr);
 
   30        cusparseSetMatType(descr,CUSPARSE_MATRIX_TYPE_GENERAL);
 
   31        cusparseSetMatIndexBase(descr,CUSPARSE_INDEX_BASE_ZERO);
 
   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));
 
   38        cusparseDestroyMatDescr(descr);
 
   39        cusolverSpDestroy(handle);
 
   41        cudaDeviceSynchronize();
 
   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)));
 
   48        return (status != CUSOLVER_STATUS_SUCCESS);
 
   52      int cuda_qr(int m, int nnz, const double * csrValA, const int * csrRowPtrA, const int * csrColIndA,
 
   53          const double * b, double * x)
 
   55        cusolverSpHandle_t handle;
 
   56        cusolverSpCreate(&handle);
 
   58        cusparseMatDescr_t descr;
 
   59        cusparseCreateMatDescr(&descr);
 
   60        cusparseSetMatType(descr,CUSPARSE_MATRIX_TYPE_GENERAL);
 
   61        cusparseSetMatIndexBase(descr,CUSPARSE_INDEX_BASE_ZERO);
 
   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));
 
   68        cusparseDestroyMatDescr(descr);
 
   69        cusolverSpDestroy(handle);
 
   71        cudaDeviceSynchronize();
 
   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)));
 
   78        return (status != CUSOLVER_STATUS_SUCCESS);