/// <summary> /// /// </summary> /// <returns></returns> public CudaSparseMatrixDescriptor Copy() { CudaSparseMatrixDescriptor retVal = new CudaSparseMatrixDescriptor(); res = CudaSparseNativeMethods.cusparseCopyMatDescr(retVal.Descriptor, _descr); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseCopyMatDescr", res)); if (res != cusparseStatus.Success) { throw new CudaSparseException(res); } return(retVal); }
/// <summary> /// Symmetric Approximate minimum degree algorithm based on quotient graph.<para/> /// This function implements Symmetric Approximate Minimum Degree Algorithm based /// on Quotient Graph. It returns a permutation vector p such that A(p,p) would have less /// zero fill-in during Cholesky factorization. /// </summary> /// <param name="n">number of rows and columns of matrix A.</param> /// <param name="nnzA">number of nonzeros of matrix A. It is the size of csrValA and csrColIndA.</param> /// <param name="descrA">the descriptor of matrix A. The supported matrix type is /// CUSPARSE_MATRIX_TYPE_GENERAL. Also, the supported index bases are CUSPARSE_INDEX_BASE_ZERO and CUSPARSE_INDEX_BASE_ONE.</param> /// <param name="csrRowPtrA">integer array of n + 1 elements that contains the start of every row and the end of the last row plus one.</param> /// <param name="csrColIndA">integer array of nnz (=csrRowPtrA(n) * csrRowPtrA(0)) column indices of the nonzero elements of matrix A.</param> /// <param name="p">permutation vector of size n.</param> public void CsrsymamdHost(int n, int nnzA, CudaSparseMatrixDescriptor descrA, int[] csrRowPtrA, int[] csrColIndA, int[] p) { res = CudaSolveNativeMethods.Sparse.cusolverSpXcsrsymamdHost(_handle, n, nnzA, descrA.Descriptor, csrRowPtrA, csrColIndA, p); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusolverSpXcsrsymamdHost", res)); if (res != cusolverStatus.Success) throw new CudaSolveException(res); }
/// <summary> /// /// </summary> /// <returns></returns> public CudaSparseMatrixDescriptor Copy() { CudaSparseMatrixDescriptor retVal = new CudaSparseMatrixDescriptor(); res = CudaSparseNativeMethods.cusparseCopyMatDescr(retVal.Descriptor, _descr); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseCopyMatDescr", res)); if (res != cusparseStatus.Success) throw new CudaSparseException(res); return retVal; }
/// <summary> /// This function solves the simple eigenvalue problem A*x=lambda*x by shift-inverse method. /// </summary> /// <param name="m">number of rows and columns of matrix A.</param> /// <param name="nnz">number of nonzeros of matrix A.</param> /// <param name="descrA">the descriptor of matrix A. The supported matrix type is /// CUSPARSE_MATRIX_TYPE_GENERAL. Also, the supported index bases are CUSPARSE_INDEX_BASE_ZERO and CUSPARSE_INDEX_BASE_ONE.</param> /// <param name="csrValA">array of nnz (= csrRowPtrA(n) * csrRowPtrA(0)) nonzero elements of matrix A.</param> /// <param name="csrRowPtrA">integer array of n + 1 elements that contains the start of every row and the end of the last row plus one.</param> /// <param name="csrColIndA">integer array of nnz (=csrRowPtrA(n) * csrRowPtrA(0)) column indices of the nonzero elements of matrix A.</param> /// <param name="mu0">initial guess of eigenvalue.</param> /// <param name="x0">initial guess of eigenvector, a vecotr of size m.</param> /// <param name="maxite">maximum iterations in shift-inverse method.</param> /// <param name="tol">tolerance for convergence.</param> /// <param name="mu">approximated eigenvalue nearest mu0 under tolerance.</param> /// <param name="x">approximated eigenvector of size m.</param> public void Csreigvsi(int m, int nnz, CudaSparseMatrixDescriptor descrA, CudaDeviceVariable<cuDoubleComplex> csrValA, CudaDeviceVariable<int> csrRowPtrA, CudaDeviceVariable<int> csrColIndA, cuDoubleComplex mu0, CudaDeviceVariable<cuDoubleComplex> x0, int maxite, double tol, ref cuDoubleComplex mu, CudaDeviceVariable<cuDoubleComplex> x) { res = CudaSolveNativeMethods.Sparse.cusolverSpZcsreigvsi(_handle, m, nnz, descrA.Descriptor, csrValA.DevicePointer, csrRowPtrA.DevicePointer, csrColIndA.DevicePointer, mu0, x0.DevicePointer, maxite, tol, ref mu, x.DevicePointer); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusolverSpZcsreigvsi", res)); if (res != cusolverStatus.Success) throw new CudaSolveException(res); }
/// <summary/> public void CsreigsHost(int m, int nnz, CudaSparseMatrixDescriptor descrA, cuDoubleComplex[] csrValA, int[] csrRowPtrA, int[] csrColIndA, cuDoubleComplex left_bottom_corner, cuDoubleComplex right_upper_corner, ref int num_eigs) { res = CudaSolveNativeMethods.Sparse.cusolverSpZcsreigsHost(_handle, m, nnz, descrA.Descriptor, csrValA, csrRowPtrA, csrColIndA, left_bottom_corner, right_upper_corner, ref num_eigs); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusolverSpZcsreigsHost", res)); if (res != cusolverStatus.Success) throw new CudaSolveException(res); }
/// <summary> /// This function solves the following least-square problem x = argmin||A*z-b|| /// </summary> /// <param name="m">number of rows of matrix A.</param> /// <param name="n">number of columns of matrix A.</param> /// <param name="nnz">number of nonzeros of matrix A.</param> /// <param name="descrA">the descriptor of matrix A. The supported matrix type is /// CUSPARSE_MATRIX_TYPE_GENERAL. Also, the supported index bases are CUSPARSE_INDEX_BASE_ZERO and CUSPARSE_INDEX_BASE_ONE.</param> /// <param name="csrValA">array of nnz (= csrRowPtrA(n) * csrRowPtrA(0)) nonzero elements of matrix A.</param> /// <param name="csrRowPtrA">integer array of n + 1 elements that contains the start of every row and the end of the last row plus one.</param> /// <param name="csrColIndA">integer array of nnz (=csrRowPtrA(n) * csrRowPtrA(0)) column indices of the nonzero elements of matrix A.</param> /// <param name="b">right hand side vector of size m.</param> /// <param name="tol">tolerance to decide rank of A.</param> /// <param name="rankA">numerical rank of A.</param> /// <param name="x">solution vector of size n, x=pinv(A)*b.</param> /// <param name="p">a vector of size n, which represents the permuation matrix P satisfying A*P^T=Q*R.</param> /// <param name="min_norm">||A*x-b||, x=pinv(A)*b.</param> public void CsrlsqvqrHost(int m, int n, int nnz, CudaSparseMatrixDescriptor descrA, cuDoubleComplex[] csrValA, int[] csrRowPtrA, int[] csrColIndA, cuDoubleComplex[] b, double tol, ref int rankA, cuDoubleComplex[] x, int[] p, ref double min_norm) { res = CudaSolveNativeMethods.Sparse.cusolverSpZcsrlsqvqrHost(_handle, m, n, nnz, descrA.Descriptor, csrValA, csrRowPtrA, csrColIndA, b, tol, ref rankA, x, p, ref min_norm); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusolverSpZcsrlsqvqrHost", res)); if (res != cusolverStatus.Success) throw new CudaSolveException(res); }
/// <summary> /// This function solves the simple eigenvalue problem A*x=lambda*x by shift-inverse method. /// </summary> /// <param name="m">number of rows and columns of matrix A.</param> /// <param name="nnz">number of nonzeros of matrix A.</param> /// <param name="descrA">the descriptor of matrix A. The supported matrix type is /// CUSPARSE_MATRIX_TYPE_GENERAL. Also, the supported index bases are CUSPARSE_INDEX_BASE_ZERO and CUSPARSE_INDEX_BASE_ONE.</param> /// <param name="csrValA">array of nnz (= csrRowPtrA(n) * csrRowPtrA(0)) nonzero elements of matrix A.</param> /// <param name="csrRowPtrA">integer array of n + 1 elements that contains the start of every row and the end of the last row plus one.</param> /// <param name="csrColIndA">integer array of nnz (=csrRowPtrA(n) * csrRowPtrA(0)) column indices of the nonzero elements of matrix A.</param> /// <param name="mu0">initial guess of eigenvalue.</param> /// <param name="x0">initial guess of eigenvector, a vecotr of size m.</param> /// <param name="maxite">maximum iterations in shift-inverse method.</param> /// <param name="tol">tolerance for convergence.</param> /// <param name="mu">approximated eigenvalue nearest mu0 under tolerance.</param> /// <param name="x">approximated eigenvector of size m.</param> public void CsreigvsiHost(int m, int nnz, CudaSparseMatrixDescriptor descrA, cuDoubleComplex[] csrValA, int[] csrRowPtrA, int[] csrColIndA, cuDoubleComplex mu0, cuDoubleComplex[] x0, int maxite, double tol, ref cuDoubleComplex mu, cuDoubleComplex[] x) { res = CudaSolveNativeMethods.Sparse.cusolverSpZcsreigvsiHost(_handle, m, nnz, descrA.Descriptor, csrValA, csrRowPtrA, csrColIndA, mu0, x0, maxite, tol, ref mu, x); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusolverSpZcsreigvsiHost", res)); if (res != cusolverStatus.Success) throw new CudaSolveException(res); }
/// <summary> /// This function solves the linear system A*x=b /// </summary> /// <param name="m">number of rows and columns of matrix A.</param> /// <param name="nnz">number of nonzeros of matrix A.</param> /// <param name="descrA">the descriptor of matrix A. The supported matrix type is /// CUSPARSE_MATRIX_TYPE_GENERAL. Also, the supported index bases are CUSPARSE_INDEX_BASE_ZERO and CUSPARSE_INDEX_BASE_ONE.</param> /// <param name="csrValA">array of nnz (= csrRowPtrA(n) * csrRowPtrA(0)) nonzero elements of matrix A.</param> /// <param name="csrRowPtrA">integer array of n + 1 elements that contains the start of every row and the end of the last row plus one.</param> /// <param name="csrColIndA">integer array of nnz (=csrRowPtrA(n) * csrRowPtrA(0)) column indices of the nonzero elements of matrix A.</param> /// <param name="b">right hand side vector of size m.</param> /// <param name="tol">tolerance to decide singularity.</param> /// <param name="reorder">no effect.</param> /// <param name="x">solution vector of size m, x = inv(A)*b.</param> /// <returns>-1 if A is invertible. Otherwise, first index j such that U(j,j)≈0</returns> public int CsrlsvcholHost(int m, int nnz, CudaSparseMatrixDescriptor descrA, cuFloatComplex[] csrValA, int[] csrRowPtrA, int[] csrColIndA, cuFloatComplex[] b, float tol, int reorder, cuFloatComplex[] x) { int singularity = 0; res = CudaSolveNativeMethods.Sparse.cusolverSpCcsrlsvcholHost(_handle, m, nnz, descrA.Descriptor, csrValA, csrRowPtrA, csrColIndA, b, tol, reorder, x, ref singularity); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusolverSpCcsrlsvcholHost", res)); if (res != cusolverStatus.Success) throw new CudaSolveException(res); return singularity; }
/// <summary> /// This function solves the linear system A*x=b /// </summary> /// <param name="m">number of rows and columns of matrix A.</param> /// <param name="nnz">number of nonzeros of matrix A.</param> /// <param name="descrA">the descriptor of matrix A. The supported matrix type is /// CUSPARSE_MATRIX_TYPE_GENERAL. Also, the supported index bases are CUSPARSE_INDEX_BASE_ZERO and CUSPARSE_INDEX_BASE_ONE.</param> /// <param name="csrValA">array of nnz (= csrRowPtrA(n) * csrRowPtrA(0)) nonzero elements of matrix A.</param> /// <param name="csrRowPtrA">integer array of n + 1 elements that contains the start of every row and the end of the last row plus one.</param> /// <param name="csrColIndA">integer array of nnz (=csrRowPtrA(n) * csrRowPtrA(0)) column indices of the nonzero elements of matrix A.</param> /// <param name="b">right hand side vector of size m.</param> /// <param name="tol">tolerance to decide singularity.</param> /// <param name="reorder">no effect.</param> /// <param name="x">solution vector of size m, x = inv(A)*b.</param> /// <returns>-1 if A is invertible. Otherwise, first index j such that U(j,j)≈0</returns> public int Csrlsvchol(int m, int nnz, CudaSparseMatrixDescriptor descrA, CudaDeviceVariable<cuDoubleComplex> csrValA, CudaDeviceVariable<int> csrRowPtrA, CudaDeviceVariable<int> csrColIndA, CudaDeviceVariable<cuDoubleComplex> b, float tol, int reorder, CudaDeviceVariable<cuDoubleComplex> x) { int singularity = 0; res = CudaSolveNativeMethods.Sparse.cusolverSpZcsrlsvchol(_handle, m, nnz, descrA.Descriptor, csrValA.DevicePointer, csrRowPtrA.DevicePointer, csrColIndA.DevicePointer, b.DevicePointer, tol, reorder, x.DevicePointer, ref singularity); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusolverSpZcsrlsvchol", res)); if (res != cusolverStatus.Success) throw new CudaSolveException(res); return singularity; }
/// <summary> /// This function checks if A has symmetric pattern or not. The output parameter issym /// reports 1 if A is symmetric; otherwise, it reports 0. /// </summary> /// <param name="m">number of rows and columns of matrix A.</param> /// <param name="nnzA">number of nonzeros of matrix A. It is the size of csrValA and csrColIndA.</param> /// <param name="descrA">the descriptor of matrix A. The supported matrix /// type is CUSPARSE_MATRIX_TYPE_GENERAL. Also, the supported index bases are CUSPARSE_INDEX_BASE_ZERO and CUSPARSE_INDEX_BASE_ONE.</param> /// <param name="csrRowPtrA">integer array of m elements that contains the start of every row.</param> /// <param name="csrEndPtrA">integer array of m elements that contains the end of the last row plus one.</param> /// <param name="csrColIndA">integer array of nnzAcolumn indices of the nonzero elements of matrix A.</param> /// <returns>1 if A is symmetric; 0 otherwise.</returns> public int CsrissymHost(int m, int nnzA, CudaSparseMatrixDescriptor descrA, int[] csrRowPtrA, int[] csrEndPtrA, int[] csrColIndA) { int issym = 0; res = CudaSolveNativeMethods.Sparse.cusolverSpXcsrissymHost(_handle, m, nnzA, descrA.Descriptor, csrRowPtrA, csrEndPtrA, csrColIndA, ref issym); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusolverSpXcsrissymHost", res)); if (res != cusolverStatus.Success) throw new CudaSolveException(res); return issym; }
/// <summary> /// The batched sparse QR factorization is used to solve either a set of least-squares /// problems or a set of linear systems /// </summary> /// <param name="m">number of rows of each matrix Aj.</param> /// <param name="n">number of columns of each matrix Aj.</param> /// <param name="nnz">number of nonzeros of each matrix Aj. It is the size csrColIndA.</param> /// <param name="descrA">the descriptor of matrix A. The supported matrix type is /// CUSPARSE_MATRIX_TYPE_GENERAL. Also, the supported index bases are CUSPARSE_INDEX_BASE_ZERO and CUSPARSE_INDEX_BASE_ONE.</param> /// <param name="csrValA">array of nnzA*batchSize nonzero /// elements of matrices A0, A1, .... All matrices are aggregated one after another.</param> /// <param name="csrRowPtrA">integer array of m+1 elements that contains the /// start of every row and the end of the last row plus one.</param> /// <param name="csrColIndA">integer array of nnzAcolumn indices of the nonzero elements of each matrix Aj.</param> /// <param name="b">array of m*batchSize of right-hand-side vectors b0, b1, .... All vectors are aggregated one after another.</param> /// <param name="x">array of m*batchSize of solution vectors x0, x1, .... All vectors are aggregated one after another.</param> /// <param name="batchSize">number of systems to be solved.</param> /// <param name="info">opaque structure for QR factorization.</param> /// <param name="pBuffer">buffer allocated by the user, the size is returned /// by cusolverSpXcsrqrBufferInfoBatched().</param> public void CsrqrsvBatched(int m, int n, int nnz, CudaSparseMatrixDescriptor descrA, CudaDeviceVariable<cuDoubleComplex> csrValA, CudaDeviceVariable<int> csrRowPtrA, CudaDeviceVariable<int> csrColIndA, CudaDeviceVariable<cuDoubleComplex> b, CudaDeviceVariable<cuDoubleComplex> x, int batchSize, CsrQrInfo info, CudaDeviceVariable<byte> pBuffer) { res = CudaSolveNativeMethods.Sparse.cusolverSpZcsrqrsvBatched(_handle, m, n, nnz, descrA.Descriptor, csrValA.DevicePointer, csrRowPtrA.DevicePointer, csrColIndA.DevicePointer, b.DevicePointer, x.DevicePointer, batchSize, info.Info, pBuffer.DevicePointer); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusolverSpZcsrqrsvBatched", res)); if (res != cusolverStatus.Success) throw new CudaSolveException(res); }
/// <summary> /// The batched sparse QR factorization is used to solve either a set of least-squares /// problems or a set of linear systems /// </summary> /// <param name="m">number of rows of each matrix Aj.</param> /// <param name="n">number of columns of each matrix Aj.</param> /// <param name="nnz">number of nonzeros of each matrix Aj. It is the size csrColIndA.</param> /// <param name="descrA">the descriptor of matrix A. The supported matrix type is /// CUSPARSE_MATRIX_TYPE_GENERAL. Also, the supported index bases are CUSPARSE_INDEX_BASE_ZERO and CUSPARSE_INDEX_BASE_ONE.</param> /// <param name="csrVal">array of nnzA*batchSize nonzero /// elements of matrices A0, A1, .... All matrices are aggregated one after another.</param> /// <param name="csrRowPtr">integer array of m+1 elements that contains the /// start of every row and the end of the last row plus one.</param> /// <param name="csrColInd">integer array of nnzAcolumn indices of the nonzero elements of each matrix Aj.</param> /// <param name="batchSize">number of systems to be solved.</param> /// <param name="info">opaque structure for QR factorization.</param> /// <param name="internalDataInBytes">number of bytes of the internal data.</param> /// <param name="workspaceInBytes">number of bytes of the buffer in numerical factorization.</param> public void CsrqrBufferInfoBatched(int m, int n, int nnz, CudaSparseMatrixDescriptor descrA, CudaDeviceVariable<cuDoubleComplex> csrVal, CudaDeviceVariable<int> csrRowPtr, CudaDeviceVariable<int> csrColInd, int batchSize, CsrQrInfo info, ref SizeT internalDataInBytes, ref SizeT workspaceInBytes) { res = CudaSolveNativeMethods.Sparse.cusolverSpZcsrqrBufferInfoBatched(_handle, m, n, nnz, descrA.Descriptor, csrVal.DevicePointer, csrRowPtr.DevicePointer, csrColInd.DevicePointer, batchSize, info.Info, ref internalDataInBytes, ref workspaceInBytes); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusolverSpZcsrqrBufferInfoBatched", res)); if (res != cusolverStatus.Success) throw new CudaSolveException(res); }
/// <summary> /// The batched sparse QR factorization is used to solve either a set of least-squares /// problems or a set of linear systems /// </summary> /// <param name="m">number of rows of each matrix Aj.</param> /// <param name="n">number of columns of each matrix Aj.</param> /// <param name="nnzA">number of nonzeros of each matrix Aj. It is the size csrColIndA.</param> /// <param name="descrA">the descriptor of matrix A. The supported matrix type is /// CUSPARSE_MATRIX_TYPE_GENERAL. Also, the supported index bases are CUSPARSE_INDEX_BASE_ZERO and CUSPARSE_INDEX_BASE_ONE.</param> /// <param name="csrRowPtrA">integer array of m+1 elements that contains the /// start of every row and the end of the last row plus one.</param> /// <param name="csrColIndA">integer array of nnzAcolumn indices of the nonzero elements of each matrix Aj.</param> /// <param name="info">opaque structure for QR factorization.</param> public void CsrqrAnalysisBatched(int m, int n, int nnzA, CudaSparseMatrixDescriptor descrA, CudaDeviceVariable<int> csrRowPtrA, CudaDeviceVariable<int> csrColIndA, CsrQrInfo info) { res = CudaSolveNativeMethods.Sparse.cusolverSpXcsrqrAnalysisBatched(_handle, m, n, nnzA, descrA.Descriptor, csrRowPtrA.DevicePointer, csrColIndA.DevicePointer, info.Info); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusolverSpXcsrqrAnalysisBatched", res)); if (res != cusolverStatus.Success) throw new CudaSolveException(res); }
/// <summary> /// Given a left permutation vector p which corresponds to permutation matrix P and a /// right permutation vector q which corresponds to permutation matrix Q, this function /// computes permutation of matrix A by B = P*A*Q^T /// </summary> /// <param name="m">number of rows of matrix A.</param> /// <param name="n">number of columns of matrix A.</param> /// <param name="nnzA">number of nonzeros of matrix A. It is the size of csrValA and csrColIndA.</param> /// <param name="descrA">the descriptor of matrix A. The supported matrix type is /// CUSPARSE_MATRIX_TYPE_GENERAL. Also, the supported index bases are CUSPARSE_INDEX_BASE_ZERO and CUSPARSE_INDEX_BASE_ONE.</param> /// <param name="csrRowPtrA">integer array of n + 1 elements that contains the start of every row and the end of the last row plus one.</param> /// <param name="csrColIndA">integer array of nnz (=csrRowPtrA(n) * csrRowPtrA(0)) column indices of the nonzero elements of matrix A.</param> /// <param name="p">left permutation vector of size m.</param> /// <param name="q">right permutation vector of size n.</param> /// <returns>number of bytes of the buffer.</returns> public SizeT Csrperm_bufferSizeHost(int m, int n, int nnzA, CudaSparseMatrixDescriptor descrA, int[] csrRowPtrA, int[] csrColIndA, int[] p, int[] q) { SizeT bufferSizeInBytes = new SizeT(); res = CudaSolveNativeMethods.Sparse.cusolverSpXcsrperm_bufferSizeHost(_handle, m, n, nnzA, descrA.Descriptor, csrRowPtrA, csrColIndA, p, q, ref bufferSizeInBytes); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusolverSpXcsrperm_bufferSizeHost", res)); if (res != cusolverStatus.Success) throw new CudaSolveException(res); return bufferSizeInBytes; }