public abstract void CreateSolveAnalysisInfo(ref cusparseSolveAnalysisInfo info);
public abstract void DestroySolveAnalysisInfo(cusparseSolveAnalysisInfo info);
private static extern CUSPARSEStatus cusparseCreateSolveAnalysisInfo(ref cusparseSolveAnalysisInfo info);
private static extern CUSPARSEStatus cusparseDcsrsv_analysis_v2(cusparseHandle handle, cusparseOperation transA, int m, int nnz, cusparseMatDescr descrA, IntPtr csrValA, IntPtr csrRowPtrA, IntPtr csrColIndA, cusparseSolveAnalysisInfo info);
public CUSPARSEStatus CusparseCreateSolveAnalysisInfo(ref cusparseSolveAnalysisInfo info) { return(cusparseCreateSolveAnalysisInfo(ref info)); }
public CUSPARSEStatus CusparseDcsrsv_analysis(cusparseHandle handle, cusparseOperation transA, int m, int nnz, cusparseMatDescr descrA, IntPtr csrValA, IntPtr csrRowPtrA, IntPtr csrColIndA, cusparseSolveAnalysisInfo info) { return(cusparseDcsrsv_analysis_v2(handle, transA, m, nnz, descrA, csrValA, csrRowPtrA, csrColIndA, info));; }
private static extern CUSPARSEStatus cusparseCreateSolveAnalysisInfo(ref cusparseSolveAnalysisInfo info);
private static extern CUSPARSEStatus cusparseDcsrsv_analysis_v2(cusparseHandle handle, cusparseOperation transA, int m, int nnz, cusparseMatDescr descrA, IntPtr csrValA, IntPtr csrRowPtrA, IntPtr csrColIndA, cusparseSolveAnalysisInfo info);
public CUSPARSEStatus CusparseDcsrsv_analysis(cusparseHandle handle, cusparseOperation transA, int m, int nnz, cusparseMatDescr descrA, IntPtr csrValA, IntPtr csrRowPtrA, IntPtr csrColIndA, cusparseSolveAnalysisInfo info) { return cusparseDcsrsv_analysis_v2(handle, transA, m, nnz, descrA, csrValA, csrRowPtrA, csrColIndA, info); ; }
public CUSPARSEStatus CusparseDcsrsv_solve(cusparseHandle handle, cusparseOperation transA, int m, ref double alpha, cusparseMatDescr descrA, IntPtr csrValA, IntPtr csrRowPtrA, IntPtr csrColIndA, cusparseSolveAnalysisInfo info, IntPtr x, IntPtr y) { return cusparseDcsrsv_solve_v2(handle, transA, m, ref alpha, descrA, csrValA, csrRowPtrA, csrColIndA, info, x, y); }
public CUSPARSEStatus CusparseDestroySolveAnalysisInfo(cusparseSolveAnalysisInfo info) { return cusparseDestroySolveAnalysisInfo(info); }
public CUSPARSEStatus CusparseCreateSolveAnalysisInfo(ref cusparseSolveAnalysisInfo info) { return cusparseCreateSolveAnalysisInfo(ref info); }
private static extern CUSPARSEStatus cusparseDcsrsv_solve_v2(cusparseHandle handle, cusparseOperation transA, int m, ref double alpha, cusparseMatDescr descrA, IntPtr csrValA, IntPtr csrRowPtrA, IntPtr csrColIndA, cusparseSolveAnalysisInfo info, IntPtr x, IntPtr y);
/// <summary> /// Performs the analysis phase of the solution of a sparse triangular linear system. /// op(A) * y = alpha * x /// </summary> /// <param name="m">specifies the number of rows and columns of matrix A; m must be at least zero.</param> /// <param name="nnz">number of non-zero elements of matrix A.</param> /// <param name="csrValA">array of nnz elements, where nnz is the number of non-zero elements and can be obtained from csrRow[m] - csrRow[0].</param> /// <param name="csrRowA">array of m+1 index elements.</param> /// <param name="csrColA">array of nnz column indices.</param> /// <param name="op">specifies op(A).</param> /// <param name="info">structure that stores the information collected during the analysis phase. It should be passed to the solve phase unchanged.</param> /// <param name="descrA">descriptor of matrix A.</param> public abstract void CSRSV_ANALYSIS(int m, int nnz, double[] csrValA, int[] csrRowA, int[] csrColA, cusparseOperation op, cusparseSolveAnalysisInfo info, cusparseMatDescr descrA);
private static extern CUSPARSEStatus cusparseDestroySolveAnalysisInfo(cusparseSolveAnalysisInfo info);
/// <summary> /// Performs the solve phase of the solution of a sparse triangular linear system. /// op(A) * y = alpha * x /// </summary> /// <param name="m">specifies the number of rows and columns of matrix A; m must be at least zero.</param> /// <param name="alpha">scalar multiplier applied to x.</param> /// <param name="csrValA">array of nnz elements, where nnz is the number of non-zero elements and can be obtained from csrRow[m] - csrRow[0].</param> /// <param name="csrRowA">array of m+1 index elements.</param> /// <param name="csrColA">array of nnz column indices.</param> /// <param name="x">vector of m elements.</param> /// <param name="y">vector of m elements. updated according to op(A) * y = alpha * x</param> /// <param name="op">specifies op(A).</param> /// <param name="info">structure that stores the information collected during the analysis phase. It should be passed to the solve phase unchanged.</param> /// <param name="descrA">descriptor of matrix A.</param> public abstract void CSRSV_SOLVE(int m, ref double alpha, double[] csrValA, int[] csrRowA, int[] csrColA, double[] x, double[] y, cusparseOperation op, cusparseSolveAnalysisInfo info, cusparseMatDescr descrA);
public override void CreateSolveAnalysisInfo(ref cusparseSolveAnalysisInfo info) { LastStatus = _driver.CusparseCreateSolveAnalysisInfo(ref info); }
private static extern CUSPARSEStatus cusparseDcsrsv_solve_v2(cusparseHandle handle, cusparseOperation transA, int m, ref double alpha, cusparseMatDescr descrA, IntPtr csrValA, IntPtr csrRowPtrA, IntPtr csrColIndA, cusparseSolveAnalysisInfo info, IntPtr x, IntPtr y);
public override void DestroySolveAnalysisInfo(cusparseSolveAnalysisInfo info) { LastStatus = _driver.CusparseDestroySolveAnalysisInfo(info); }
public CUSPARSEStatus CusparseDestroySolveAnalysisInfo(cusparseSolveAnalysisInfo info) { return(cusparseDestroySolveAnalysisInfo(info)); }
public override void CSRSV_ANALYSIS(int m, int nnz, double[] csrValA, int[] csrRowA, int[] csrColA, cusparseOperation op, cusparseSolveAnalysisInfo info, cusparseMatDescr descrA) { CUdeviceptr ptrcsrv = GetDeviceMemory(csrValA); CUdeviceptr ptrcsrr = GetDeviceMemory(csrRowA); CUdeviceptr ptrcsrc = GetDeviceMemory(csrColA); LastStatus = _driver.CusparseDcsrsv_analysis(_sparse, op, m, nnz, descrA, ptrcsrv.Pointer, ptrcsrr.Pointer, ptrcsrc.Pointer, info); }
public CUSPARSEStatus CusparseDcsrsv_solve(cusparseHandle handle, cusparseOperation transA, int m, ref double alpha, cusparseMatDescr descrA, IntPtr csrValA, IntPtr csrRowPtrA, IntPtr csrColIndA, cusparseSolveAnalysisInfo info, IntPtr x, IntPtr y) { return(cusparseDcsrsv_solve_v2(handle, transA, m, ref alpha, descrA, csrValA, csrRowPtrA, csrColIndA, info, x, y)); }
public override void CSRSV_SOLVE(int m, ref double alpha, double[] csrValA, int[] csrRowA, int[] csrColA, double[] x, double[] y, cusparseOperation op, cusparseSolveAnalysisInfo info, cusparseMatDescr descrA) { CUdeviceptr ptrcsrv = GetDeviceMemory(csrValA); CUdeviceptr ptrcsrr = GetDeviceMemory(csrRowA); CUdeviceptr ptrcsrc = GetDeviceMemory(csrColA); CUdeviceptr ptrx = GetDeviceMemory(x); CUdeviceptr ptry = GetDeviceMemory(y); LastStatus = _driver.CusparseDcsrsv_solve(_sparse, op, m, ref alpha, descrA, ptrcsrv.Pointer, ptrcsrr.Pointer, ptrcsrc.Pointer, info, ptrx.Pointer, ptry.Pointer); }
private static extern CUSPARSEStatus cusparseDestroySolveAnalysisInfo(cusparseSolveAnalysisInfo info);
public SolveResult CGPreconditioned( int n, int nnz, float[] csrValA, int[] csrRowA, int[] csrColA, float[] dx, float[] db, float[] csrValICP, int[] csrRowICP, int[] csrColICP, float[] dy, float[] dp, float[] domega, float[] zm1, float[] zm2, float[] rm2, float tolerence = 0.0001f, int maxIterate = 300) { SolveResult result = new SolveResult(); // Make Incomplete Cholesky Preconditioner. gpu.Launch().DefineLower(n, csrRowICP, csrColICP); gpu.Launch(n, 1).CopyAIntoH(n, csrValA, csrRowA, csrValICP, csrRowICP); gpu.Launch(n, 1).ConstructH(n, csrValICP, csrRowICP); cusparseMatDescr descrM = new cusparseMatDescr(); descrM.MatrixType = cusparseMatrixType.Triangular; descrM.FillMode = cusparseFillMode.Lower; descrM.IndexBase = cusparseIndexBase.Zero; descrM.DiagType = cusparseDiagType.NonUnit; cusparseSolveAnalysisInfo info = new cusparseSolveAnalysisInfo(); sparse.CreateSolveAnalysisInfo(ref info); cusparseSolveAnalysisInfo infoTrans = new cusparseSolveAnalysisInfo(); sparse.CreateSolveAnalysisInfo(ref infoTrans); sparse.CSRSV_ANALYSIS(n, nnz, csrValICP, csrRowICP, csrColICP, cusparseOperation.NonTranspose, info, descrM); sparse.CSRSV_ANALYSIS(n, nnz, csrValICP, csrRowICP, csrColICP, cusparseOperation.Transpose, infoTrans, descrM); int k = 0; float r1 = blas.DOT(db, db); float alpha, beta; float identityFloat = 1.0f; float zeroFloat = 0.0f; while (true) { sparse.CSRSV_SOLVE(n, ref identityFloat, csrValICP, csrRowICP, csrColICP, db, dy, cusparseOperation.NonTranspose, info, descrM); sparse.CSRSV_SOLVE(n, ref identityFloat, csrValICP, csrRowICP, csrColICP, dy, zm1, cusparseOperation.Transpose, infoTrans, descrM); k++; if (k == 1) { blas.COPY(zm1, dp); } else { beta = blas.DOT(db, zm1) / blas.DOT(rm2, zm2); blas.SCAL(beta, dp); blas.AXPY(1.0f, zm1, dp); } sparse.CSRMV(n, n, nnz, ref identityFloat, csrValA, csrRowA, csrColA, dp, ref zeroFloat, domega); alpha = blas.DOT(db, zm1) / blas.DOT(dp, domega); blas.AXPY(alpha, dp, dx); blas.COPY(db, rm2); blas.COPY(zm1, zm2); blas.AXPY(-alpha, domega, db); r1 = blas.DOT(db, db); if (r1 <= tolerence * tolerence) { result.IsSuccess = true; result.IterateCount = k; result.LastError = r1; break; } if (k > maxIterate) { result.IsSuccess = false; result.IterateCount = k; result.LastError = r1; break; } } return result; }