Preconditioner functions#

This module contains all sparse preconditioners.

The sparse preconditioners describe manipulations on a matrix in sparse format to obtain a sparse preconditioner matrix.

hipsparseXbsrilu02_zeroPivot()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXbsrilu02_numericBoost()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXbsrilu02_bufferSize()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXbsrilu02_analysis()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXbsrilu02()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

  1int main(int argc, char* argv[])
  2{
  3    // hipSPARSE handle
  4    hipsparseHandle_t handle;
  5    HIPSPARSE_CHECK(hipsparseCreate(&handle));
  6
  7    // A sample square matrix A (4x4) in BSR format for ILU(0) factorization.
  8    // The 'S' in Sbsrilu02 indicates single precision float.
  9    // We'll use a block size of 1 for simplicity, making it behave like CSR ILU.
 10    // Matrix A:
 11    // ( 1  2  0  0 )
 12    // ( 3  4  5  0 )
 13    // ( 0  6  7  8 )
 14    // ( 0  0  9 10 )
 15
 16    int m    = 4; // Number of rows
 17    int n    = 4; // Number of columns
 18    int bs   = 1; // Block size
 19    int mb   = m / bs; // Number of block rows
 20    int nb   = n / bs; // Number of block columns
 21    int nnzb = 10; // Number of non-zero blocks
 22
 23    // BSR row pointers
 24    std::vector<int> hbsrRowPtr = {0, 2, 5, 8, 10};
 25
 26    // BSR column indices
 27    std::vector<int> hbsrColInd = {0, 1, 0, 1, 2, 1, 2, 3, 2, 3};
 28
 29    // BSR values (single precision float)
 30    std::vector<float> hbsrVal = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f};
 31
 32    // Matrix descriptor
 33    hipsparseMatDescr_t descr;
 34    HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr));
 35
 36    // Set index base on descriptor
 37    HIPSPARSE_CHECK(hipsparseSetMatIndexBase(descr, HIPSPARSE_INDEX_BASE_ZERO));
 38
 39    // For ILU(0), the L factor often has a unit diagonal.
 40    HIPSPARSE_CHECK(hipsparseSetMatDiagType(descr, HIPSPARSE_DIAG_TYPE_UNIT));
 41
 42    // BSRILU02 info
 43    bsrilu02Info_t info;
 44    HIPSPARSE_CHECK(hipsparseCreateBsrilu02Info(&info));
 45
 46    // Offload data to device
 47    int*   dbsrRowPtr;
 48    int*   dbsrColInd;
 49    float* dbsrVal; // This will store the factorized L and U values
 50
 51    HIP_CHECK(hipMalloc((void**)&dbsrRowPtr, sizeof(int) * (mb + 1)));
 52    HIP_CHECK(hipMalloc((void**)&dbsrColInd, sizeof(int) * nnzb));
 53    HIP_CHECK(hipMalloc((void**)&dbsrVal, sizeof(float) * nnzb * bs * bs));
 54
 55    HIP_CHECK(
 56        hipMemcpy(dbsrRowPtr, hbsrRowPtr.data(), sizeof(int) * (mb + 1), hipMemcpyHostToDevice));
 57    HIP_CHECK(hipMemcpy(dbsrColInd, hbsrColInd.data(), sizeof(int) * nnzb, hipMemcpyHostToDevice));
 58    HIP_CHECK(
 59        hipMemcpy(dbsrVal, hbsrVal.data(), sizeof(float) * nnzb * bs * bs, hipMemcpyHostToDevice));
 60
 61    // 1. Get buffer size
 62    int bufferSize = 0;
 63    HIPSPARSE_CHECK(
 64        hipsparseSbsrilu02_bufferSize(handle,
 65                                      HIPSPARSE_DIRECTION_COLUMN, // Block storage direction
 66                                      mb,
 67                                      nnzb,
 68                                      descr,
 69                                      dbsrVal,
 70                                      dbsrRowPtr,
 71                                      dbsrColInd,
 72                                      bs,
 73                                      info,
 74                                      &bufferSize));
 75
 76    void* dbuffer = nullptr;
 77    HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize));
 78
 79    // 2. Perform analysis (symbolic factorization)
 80    // This step analyzes the sparsity pattern of A to determine the structure of L and U.
 81    HIPSPARSE_CHECK(
 82        hipsparseSbsrilu02_analysis(handle,
 83                                    HIPSPARSE_DIRECTION_COLUMN,
 84                                    mb,
 85                                    nnzb,
 86                                    descr,
 87                                    dbsrVal,
 88                                    dbsrRowPtr,
 89                                    dbsrColInd,
 90                                    bs,
 91                                    info,
 92                                    HIPSPARSE_SOLVE_POLICY_USE_LEVEL, // Policy for analysis
 93                                    dbuffer));
 94
 95    // 3. Perform factorization (numerical computation)
 96    // This step computes the actual numerical values of L and U, stored in dbsrVal.
 97    HIPSPARSE_CHECK(hipsparseSbsrilu02(handle,
 98                                       HIPSPARSE_DIRECTION_COLUMN,
 99                                       mb,
100                                       nnzb,
101                                       descr,
102                                       dbsrVal,
103                                       dbsrRowPtr,
104                                       dbsrColInd,
105                                       bs,
106                                       info,
107                                       HIPSPARSE_SOLVE_POLICY_USE_LEVEL, // Policy for factorization
108                                       dbuffer));
109
110    // 4. Check for zero pivots
111    // A zero pivot can occur during factorization, indicating a numerical breakdown.
112    int zeroPivot = 0; // -1 if no zero pivot, otherwise the block row index of the first zero pivot
113    HIPSPARSE_CHECK(hipsparseXbsrilu02_zeroPivot(handle, info, &zeroPivot));
114    if(zeroPivot != -1)
115    {
116        printf("Error: Zero pivot detected during ILU0 factorization at block row index %d\n",
117               zeroPivot);
118        // Handle the error (e.g., return, use a different preconditioner, etc.)
119    }
120    else
121    {
122        printf("BSRILU0 factorization completed successfully (no zero pivots detected).\n");
123    }
124
125    // Copy the factorized values (L and U combined) back to host
126    std::vector<float> hbsrVal_result(nnzb * bs * bs);
127    HIP_CHECK(hipMemcpy(
128        hbsrVal_result.data(), dbsrVal, sizeof(float) * nnzb * bs * bs, hipMemcpyDeviceToHost));
129
130    // Print the result (the values of the factorized L and U combined)
131    printf("\nFactorized BSR values (L and U combined):\n");
132    for(int i = 0; i < nnzb * bs * bs; ++i)
133    {
134        printf("val[%d] = %f\n", i, hbsrVal_result[i]);
135    }
136
137    // Clean up
138    HIPSPARSE_CHECK(hipsparseDestroyBsrilu02Info(info));
139    HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr));
140    HIPSPARSE_CHECK(hipsparseDestroy(handle));
141
142    HIP_CHECK(hipFree(dbsrRowPtr));
143    HIP_CHECK(hipFree(dbsrColInd));
144    HIP_CHECK(hipFree(dbsrVal));
145    HIP_CHECK(hipFree(dbuffer));
146
147    return 0;
148}

hipsparseXcsrilu02_zeroPivot()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXcsrilu02_numericBoost()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXcsrilu02_bufferSize()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXcsrilu02_bufferSizeExt()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXcsrilu02_analysis()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXcsrilu02()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

  1int main(int argc, char* argv[])
  2{
  3    // hipSPARSE handle
  4    hipsparseHandle_t handle;
  5    HIPSPARSE_CHECK(hipsparseCreate(&handle));
  6
  7    // A sample square matrix A (4x4) in CSR format for ILU(0) factorization.
  8    // The 'S' in Scsrilu02 indicates single precision float.
  9    // Matrix A:
 10    // ( 1  2  0  0 )
 11    // ( 3  4  5  0 )
 12    // ( 0  6  7  8 )
 13    // ( 0  0  9 10 )
 14
 15    int m   = 4; // Number of rows
 16    int n   = 4; // Number of columns (equal to m for ILU)
 17    int nnz = 10; // Number of non-zero elements
 18
 19    // CSR row pointers
 20    std::vector<int> hcsrRowPtr = {0, 2, 5, 8, 10};
 21
 22    // CSR column indices
 23    std::vector<int> hcsrColInd = {0, 1, 0, 1, 2, 1, 2, 3, 2, 3};
 24
 25    // CSR values
 26    std::vector<float> hcsrVal = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f};
 27
 28    // Matrix descriptor
 29    hipsparseMatDescr_t descr;
 30    HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr));
 31
 32    // Set index base on descriptor
 33    HIPSPARSE_CHECK(hipsparseSetMatIndexBase(descr, HIPSPARSE_INDEX_BASE_ZERO));
 34
 35    // For incomplete LU, the L factor often has a unit diagonal.
 36    HIPSPARSE_CHECK(hipsparseSetMatDiagType(descr, HIPSPARSE_DIAG_TYPE_UNIT));
 37
 38    // CSRILU02 info (for incomplete LU factorization)
 39    csrilu02Info_t info;
 40    HIPSPARSE_CHECK(hipsparseCreateCsrilu02Info(&info));
 41
 42    // Offload data to device
 43    int*   dcsrRowPtr;
 44    int*   dcsrColInd;
 45    float* dcsrVal; // This will store the factorized L and U values
 46
 47    HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1)));
 48    HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz));
 49    HIP_CHECK(
 50        hipMalloc((void**)&dcsrVal,
 51                  sizeof(float) * nnz)); // Note: Same size as input, values will be overwritten
 52
 53    HIP_CHECK(
 54        hipMemcpy(dcsrRowPtr, hcsrRowPtr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice));
 55    HIP_CHECK(hipMemcpy(dcsrColInd, hcsrColInd.data(), sizeof(int) * nnz, hipMemcpyHostToDevice));
 56    HIP_CHECK(hipMemcpy(dcsrVal, hcsrVal.data(), sizeof(float) * nnz, hipMemcpyHostToDevice));
 57
 58    // 1. Get buffer size
 59    int bufferSize = 0;
 60    HIPSPARSE_CHECK(hipsparseScsrilu02_bufferSize(
 61        handle, m, nnz, descr, dcsrVal, dcsrRowPtr, dcsrColInd, info, &bufferSize));
 62
 63    void* dbuffer = nullptr;
 64    HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize));
 65
 66    // 2. Perform analysis (symbolic factorization)
 67    // This step analyzes the sparsity pattern of A to determine the structure of L and U.
 68    HIPSPARSE_CHECK(
 69        hipsparseScsrilu02_analysis(handle,
 70                                    m,
 71                                    nnz,
 72                                    descr,
 73                                    dcsrVal,
 74                                    dcsrRowPtr,
 75                                    dcsrColInd,
 76                                    info,
 77                                    HIPSPARSE_SOLVE_POLICY_USE_LEVEL, // Policy for analysis
 78                                    dbuffer));
 79
 80    // 3. Perform factorization (numerical computation)
 81    // This step computes the actual numerical values of L and U, stored in dcsrVal.
 82    HIPSPARSE_CHECK(hipsparseScsrilu02(handle,
 83                                       m,
 84                                       nnz,
 85                                       descr,
 86                                       dcsrVal,
 87                                       dcsrRowPtr,
 88                                       dcsrColInd,
 89                                       info,
 90                                       HIPSPARSE_SOLVE_POLICY_USE_LEVEL, // Policy for factorization
 91                                       dbuffer));
 92
 93    // 4. Check for zero pivots
 94    // A zero pivot can occur during factorization, indicating a numerical breakdown.
 95    int zeroPivot = 0; // -1 if no zero pivot, otherwise the row index of the first zero pivot
 96    HIPSPARSE_CHECK(hipsparseXcsrilu02_zeroPivot(handle, info, &zeroPivot));
 97    if(zeroPivot != -1)
 98    {
 99        printf("Error: Zero pivot detected during ILU0 factorization at row index %d\n", zeroPivot);
100        // Depending on your application, you might want to handle this error
101        // or switch to a different preconditioner.
102    }
103    else
104    {
105        printf("CSRILU0 factorization completed successfully (no zero pivots detected).\n");
106    }
107
108    // Copy the factorized values (L and U combined) back to host
109    std::vector<float> hcsrVal_result(nnz);
110    HIP_CHECK(
111        hipMemcpy(hcsrVal_result.data(), dcsrVal, sizeof(float) * nnz, hipMemcpyDeviceToHost));
112
113    // Print the result (the values of the factorized L and U combined)
114    printf("\nFactorized CSR values (L and U combined):\n");
115    for(int i = 0; i < nnz; ++i)
116    {
117        printf("val[%d] = %f\n", i, hcsrVal_result[i]);
118    }
119
120    // Clean up
121    HIPSPARSE_CHECK(hipsparseDestroyCsrilu02Info(info));
122    HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr));
123    HIPSPARSE_CHECK(hipsparseDestroy(handle));
124
125    HIP_CHECK(hipFree(dcsrRowPtr));
126    HIP_CHECK(hipFree(dcsrColInd));
127    HIP_CHECK(hipFree(dcsrVal));
128    HIP_CHECK(hipFree(dbuffer));
129
130    return 0;
131}

hipsparseXbsric02_zeroPivot()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXbsric02_bufferSize()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXbsric02_analysis()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXbsric02()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

  1int main(int argc, char* argv[])
  2{
  3    // hipSPARSE handle
  4    hipsparseHandle_t handle;
  5    HIPSPARSE_CHECK(hipsparseCreate(&handle));
  6
  7    // A sample symmetric positive definite matrix A (4x4)
  8    // with a block size of 1. This example effectively uses BSR format
  9    // for a CSR-like matrix.
 10    // Matrix A:
 11    // ( 4  1  0  0 )
 12    // ( 1  5  2  0 )
 13    // ( 0  2  3  1 )
 14    // ( 0  0  1  2 )
 15
 16    const int m    = 4; // Number of rows
 17    const int n    = 4; // Number of columns
 18    const int bs   = 1; // Block size
 19    const int mb   = m / bs; // Number of block rows
 20    const int nb   = n / bs; // Number of block columns
 21    const int nnzb = 10; // Number of non-zero blocks
 22
 23    // BSR row pointers
 24    std::vector<int> hbsrRowPtr = {0, 2, 5, 8, 10};
 25
 26    // BSR column indices
 27    std::vector<int> hbsrColInd = {0, 1, 0, 1, 2, 1, 2, 3, 2, 3};
 28
 29    // BSR values (single precision float for 'S'bsric02)
 30    // Values are stored column-major within each block, but with bs=1, this is simple.
 31    // The values correspond to the upper triangular part of the matrix.
 32    std::vector<float> hbsrVal = {4.0f, 1.0f, 1.0f, 5.0f, 2.0f, 2.0f, 3.0f, 1.0f, 1.0f, 2.0f};
 33
 34    // Matrix descriptor
 35    hipsparseMatDescr_t descr;
 36    HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr));
 37
 38    // Set index base on descriptor
 39    HIPSPARSE_CHECK(hipsparseSetMatIndexBase(descr, HIPSPARSE_INDEX_BASE_ZERO));
 40
 41    // Set fill mode to lower and diagonal type to unit (required for IC02)
 42    HIPSPARSE_CHECK(hipsparseSetMatFillMode(descr, HIPSPARSE_FILL_MODE_LOWER));
 43    HIPSPARSE_CHECK(hipsparseSetMatDiagType(descr, HIPSPARSE_DIAG_TYPE_UNIT));
 44
 45    // BSRIC02 info
 46    bsric02Info_t info;
 47    HIPSPARSE_CHECK(hipsparseCreateBsric02Info(&info));
 48
 49    // Offload data to device
 50    int*   dbsrRowPtr;
 51    int*   dbsrColInd;
 52    float* dbsrVal;
 53
 54    HIP_CHECK(hipMalloc((void**)&dbsrRowPtr, sizeof(int) * (mb + 1)));
 55    HIP_CHECK(hipMalloc((void**)&dbsrColInd, sizeof(int) * nnzb));
 56    HIP_CHECK(hipMalloc((void**)&dbsrVal, sizeof(float) * nnzb * bs * bs));
 57
 58    HIP_CHECK(
 59        hipMemcpy(dbsrRowPtr, hbsrRowPtr.data(), sizeof(int) * (mb + 1), hipMemcpyHostToDevice));
 60    HIP_CHECK(hipMemcpy(dbsrColInd, hbsrColInd.data(), sizeof(int) * nnzb, hipMemcpyHostToDevice));
 61    HIP_CHECK(
 62        hipMemcpy(dbsrVal, hbsrVal.data(), sizeof(float) * nnzb * bs * bs, hipMemcpyHostToDevice));
 63
 64    // 1. Get buffer size
 65    int bufferSize = 0;
 66    HIPSPARSE_CHECK(hipsparseSbsric02_bufferSize(handle,
 67                                                 HIPSPARSE_DIRECTION_COLUMN,
 68                                                 mb,
 69                                                 nnzb,
 70                                                 descr,
 71                                                 dbsrVal,
 72                                                 dbsrRowPtr,
 73                                                 dbsrColInd,
 74                                                 bs,
 75                                                 info,
 76                                                 &bufferSize));
 77
 78    void* dbuffer = nullptr;
 79    HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize));
 80
 81    // 2. Perform analysis (symbolic factorization)
 82    HIPSPARSE_CHECK(hipsparseSbsric02_analysis(handle,
 83                                               HIPSPARSE_DIRECTION_COLUMN,
 84                                               mb,
 85                                               nnzb,
 86                                               descr,
 87                                               dbsrVal,
 88                                               dbsrRowPtr,
 89                                               dbsrColInd,
 90                                               bs,
 91                                               info,
 92                                               HIPSPARSE_SOLVE_POLICY_USE_LEVEL,
 93                                               dbuffer));
 94
 95    // 3. Perform factorization (numerical computation)
 96    HIPSPARSE_CHECK(hipsparseSbsric02(handle,
 97                                      HIPSPARSE_DIRECTION_COLUMN,
 98                                      mb,
 99                                      nnzb,
100                                      descr,
101                                      dbsrVal,
102                                      dbsrRowPtr,
103                                      dbsrColInd,
104                                      bs,
105                                      info,
106                                      HIPSPARSE_SOLVE_POLICY_USE_LEVEL,
107                                      dbuffer));
108
109    // 4. Check for zero pivots
110    int zeroPivot = 0;
111    HIPSPARSE_CHECK(hipsparseXbsric02_zeroPivot(handle, info, &zeroPivot));
112    if(zeroPivot != -1)
113    {
114        printf("Error: Zero pivot detected at index %d\n", zeroPivot);
115        // Handle error, e.g., by returning an error code
116    }
117
118    // Copy the factorized values back to host
119    std::vector<float> hbsrVal_result(nnzb * bs * bs);
120    HIP_CHECK(hipMemcpy(
121        hbsrVal_result.data(), dbsrVal, sizeof(float) * nnzb * bs * bs, hipMemcpyDeviceToHost));
122
123    // Print the result (the values of the factorized matrix)
124    printf("Successfully computed incomplete Cholesky factorization.\n");
125    printf("Factorized BSR values:\n");
126    for(int i = 0; i < nnzb * bs * bs; ++i)
127    {
128        printf("val[%d] = %f\n", i, hbsrVal_result[i]);
129    }
130
131    // Clean up
132    HIPSPARSE_CHECK(hipsparseDestroyBsric02Info(info));
133    HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr));
134    HIPSPARSE_CHECK(hipsparseDestroy(handle));
135
136    HIP_CHECK(hipFree(dbsrRowPtr));
137    HIP_CHECK(hipFree(dbsrColInd));
138    HIP_CHECK(hipFree(dbsrVal));
139    HIP_CHECK(hipFree(dbuffer));
140
141    return 0;
142}

hipsparseXcsric02_zeroPivot()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXcsric02_bufferSize()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXcsric02_bufferSizeExt()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXcsric02_analysis()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXcsric02()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

  1int main(int argc, char* argv[])
  2{
  3    // hipSPARSE handle
  4    hipsparseHandle_t handle;
  5    HIPSPARSE_CHECK(hipsparseCreate(&handle));
  6
  7    // A sample symmetric positive definite matrix A (4x4) in CSR format.
  8    // The 'S' in Scsric02 indicates single precision float.
  9    // Matrix A:
 10    // ( 4  1  0  0 )
 11    // ( 1  5  2  0 )
 12    // ( 0  2  3  1 )
 13    // ( 0  0  1  2 )
 14    // This matrix is symmetric. For IC02, we typically provide the full matrix
 15    // or just the lower/upper part if using `HIPSPARSE_MATRIX_TYPE_SYMMETRIC`
 16    // with the descriptor. Here, we provide elements for both lower and upper parts
 17    // for simplicity, but the factorization will operate on the implicitly
 18    // symmetric matrix and produce the lower triangular factor L.
 19
 20    int m   = 4; // Number of rows
 21    int n   = 4; // Number of columns (equal to m for Cholesky)
 22    int nnz = 10; // Number of non-zero elements (counting only one side for symmetric)
 23
 24    // CSR row pointers
 25    std::vector<int> hcsrRowPtr = {0, 2, 5, 8, 10};
 26
 27    // CSR column indices
 28    // These indices correspond to the non-zero values used below.
 29    // For a symmetric matrix A, we implicitly work with A_lower.
 30    // The output will be L.
 31    std::vector<int> hcsrColInd = {0, 1, 0, 1, 2, 1, 2, 3, 2, 3};
 32
 33    // CSR values (single precision float for 'S'csric02)
 34    // The factorization computes the lower triangular L factor.
 35    // The input values represent the entries of A that correspond to the non-zero pattern.
 36    std::vector<float> hcsrVal = {4.0f, 1.0f, 1.0f, 5.0f, 2.0f, 2.0f, 3.0f, 1.0f, 1.0f, 2.0f};
 37
 38    // Matrix descriptor
 39    hipsparseMatDescr_t descr;
 40    HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr));
 41
 42    // Set index base on descriptor
 43    HIPSPARSE_CHECK(hipsparseSetMatIndexBase(descr, HIPSPARSE_INDEX_BASE_ZERO));
 44
 45    // For incomplete Cholesky, the L factor is computed.
 46    // L is lower triangular with a unit diagonal.
 47    HIPSPARSE_CHECK(hipsparseSetMatFillMode(descr, HIPSPARSE_FILL_MODE_LOWER));
 48    HIPSPARSE_CHECK(hipsparseSetMatDiagType(descr, HIPSPARSE_DIAG_TYPE_UNIT));
 49    // Optionally set matrix type to symmetric if only storing one triangle of A
 50    // HIPSPARSE_CHECK(hipsparseSetMatType(descr, HIPSPARSE_MATRIX_TYPE_SYMMETRIC));
 51
 52    // CSRIC02 info
 53    csric02Info_t info;
 54    HIPSPARSE_CHECK(hipsparseCreateCsric02Info(&info));
 55
 56    // Offload data to device
 57    int*   dcsrRowPtr;
 58    int*   dcsrColInd;
 59    float* dcsrVal; // This will store the factorized L values
 60
 61    HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1)));
 62    HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz));
 63    HIP_CHECK(
 64        hipMalloc((void**)&dcsrVal,
 65                  sizeof(float) * nnz)); // Note: Same size as input, values will be overwritten
 66
 67    HIP_CHECK(
 68        hipMemcpy(dcsrRowPtr, hcsrRowPtr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice));
 69    HIP_CHECK(hipMemcpy(dcsrColInd, hcsrColInd.data(), sizeof(int) * nnz, hipMemcpyHostToDevice));
 70    HIP_CHECK(hipMemcpy(dcsrVal, hcsrVal.data(), sizeof(float) * nnz, hipMemcpyHostToDevice));
 71
 72    // 1. Get buffer size
 73    int bufferSize = 0;
 74    HIPSPARSE_CHECK(hipsparseScsric02_bufferSize(
 75        handle, m, nnz, descr, dcsrVal, dcsrRowPtr, dcsrColInd, info, &bufferSize));
 76
 77    void* dbuffer = nullptr;
 78    HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize));
 79
 80    // 2. Perform analysis (symbolic factorization)
 81    // This step analyzes the sparsity pattern of A to determine the structure of L.
 82    HIPSPARSE_CHECK(
 83        hipsparseScsric02_analysis(handle,
 84                                   m,
 85                                   nnz,
 86                                   descr,
 87                                   dcsrVal,
 88                                   dcsrRowPtr,
 89                                   dcsrColInd,
 90                                   info,
 91                                   HIPSPARSE_SOLVE_POLICY_USE_LEVEL, // Policy for analysis
 92                                   dbuffer));
 93
 94    // 3. Perform factorization (numerical computation)
 95    // This step computes the actual numerical values of L, stored in dcsrVal.
 96    HIPSPARSE_CHECK(hipsparseScsric02(handle,
 97                                      m,
 98                                      nnz,
 99                                      descr,
100                                      dcsrVal,
101                                      dcsrRowPtr,
102                                      dcsrColInd,
103                                      info,
104                                      HIPSPARSE_SOLVE_POLICY_USE_LEVEL, // Policy for factorization
105                                      dbuffer));
106
107    // 4. Check for zero pivots
108    // A zero pivot can occur during factorization, indicating a numerical breakdown.
109    int zeroPivot = 0; // -1 if no zero pivot, otherwise the row index of the first zero pivot
110    HIPSPARSE_CHECK(hipsparseXcsric02_zeroPivot(handle, info, &zeroPivot));
111    if(zeroPivot != -1)
112    {
113        printf("Error: Zero pivot detected during IC02 factorization at row index %d\n", zeroPivot);
114        // Depending on your application, you might want to handle this error
115        // or switch to a different preconditioner.
116    }
117    else
118    {
119        printf("CSRIC02 factorization completed successfully (no zero pivots detected).\n");
120    }
121
122    // Copy the factorized values (L) back to host
123    std::vector<float> hcsrVal_result(nnz);
124    HIP_CHECK(
125        hipMemcpy(hcsrVal_result.data(), dcsrVal, sizeof(float) * nnz, hipMemcpyDeviceToHost));
126
127    // Print the result (the values of the factorized L)
128    printf("\nFactorized CSR values (L factor):\n");
129    for(int i = 0; i < nnz; ++i)
130    {
131        printf("val[%d] = %f\n", i, hcsrVal_result[i]);
132    }
133
134    // Clean up
135    HIPSPARSE_CHECK(hipsparseDestroyCsric02Info(info));
136    HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr));
137    HIPSPARSE_CHECK(hipsparseDestroy(handle));
138
139    HIP_CHECK(hipFree(dcsrRowPtr));
140    HIP_CHECK(hipFree(dcsrColInd));
141    HIP_CHECK(hipFree(dcsrVal));
142    HIP_CHECK(hipFree(dbuffer));
143
144    return 0;
145}

hipsparseXgtsv2_bufferSizeExt()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXgtsv2()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

 1int main(int argc, char* argv[])
 2{
 3    // Size of square tridiagonal matrix
 4    int m = 5;
 5
 6    // Number of columns in right-hand side (column ordered) matrix
 7    int n = 3;
 8
 9    // Leading dimension of right-hand side (column ordered) matrix
10    int ldb = m;
11
12    // Host tri-diagonal matrix
13    // 2 3 0 0 0
14    // 2 4 2 0 0
15    // 0 1 1 1 0
16    // 0 0 1 3 1
17    // 0 0 0 1 4
18    std::vector<float> hdl = {0.0f, 2.0f, 1.0f, 1.0f, 1.0f};
19    std::vector<float> hd  = {2.0f, 4.0f, 1.0f, 3.0f, 4.0f};
20    std::vector<float> hdu = {3.0f, 2.0f, 1.0f, 1.0f, 0.0f};
21
22    // Host right-hand side column vectors
23    std::vector<float> hB(ldb * n, 2.0f);
24
25    float* ddl = nullptr;
26    float* dd  = nullptr;
27    float* ddu = nullptr;
28    float* dB  = nullptr;
29    HIP_CHECK(hipMalloc((void**)&ddl, sizeof(float) * m));
30    HIP_CHECK(hipMalloc((void**)&dd, sizeof(float) * m));
31    HIP_CHECK(hipMalloc((void**)&ddu, sizeof(float) * m));
32    HIP_CHECK(hipMalloc((void**)&dB, sizeof(float) * ldb * n));
33
34    HIP_CHECK(hipMemcpy(ddl, hdl.data(), sizeof(float) * m, hipMemcpyHostToDevice));
35    HIP_CHECK(hipMemcpy(dd, hd.data(), sizeof(float) * m, hipMemcpyHostToDevice));
36    HIP_CHECK(hipMemcpy(ddu, hdu.data(), sizeof(float) * m, hipMemcpyHostToDevice));
37    HIP_CHECK(hipMemcpy(dB, hB.data(), sizeof(float) * ldb * n, hipMemcpyHostToDevice));
38
39    // hipSPARSE handle
40    hipsparseHandle_t handle;
41    HIPSPARSE_CHECK(hipsparseCreate(&handle));
42
43    // 1. Get buffer size
44    size_t bufferSize = 0;
45    HIPSPARSE_CHECK(
46        hipsparseSgtsv2_bufferSizeExt(handle, m, m, ddl, dd, ddu, dB, ldb, &bufferSize));
47
48    void* dbuffer = nullptr;
49    HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize));
50
51    // 2. Perform tridiagonal solve with pivoting
52    // The solution is computed and stored in the dB vector.
53    HIPSPARSE_CHECK(hipsparseSgtsv2(handle, m, m, ddl, dd, ddu, dB, ldb, dbuffer));
54
55    // Copy solution back to host from dB
56    HIP_CHECK(hipMemcpy(hB.data(), dB, sizeof(float) * m, hipMemcpyDeviceToHost));
57
58    // Print the solution
59    printf("Solution for the tridiagonal system:\n");
60    for(int i = 0; i < m; ++i)
61    {
62        printf("  x[%d] = %f\n", i, hB[i]);
63    }
64
65    // Clean up
66    HIP_CHECK(hipFree(ddl));
67    HIP_CHECK(hipFree(dd));
68    HIP_CHECK(hipFree(ddu));
69    HIP_CHECK(hipFree(dB));
70    HIP_CHECK(hipFree(dbuffer));
71
72    HIPSPARSE_CHECK(hipsparseDestroy(handle));
73
74    return 0;
75}

hipsparseXgtsv2_nopivot_bufferSizeExt()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXgtsv2_nopivot()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

 1int main(int argc, char* argv[])
 2{
 3    // hipSPARSE handle
 4    hipsparseHandle_t handle;
 5    HIPSPARSE_CHECK(hipsparseCreate(&handle));
 6
 7    // Size of square tridiagonal matrix
 8    int m = 5;
 9
10    // Number of columns in right-hand side (column ordered) matrix
11    int n = 3;
12
13    // Leading dimension of right-hand side (column ordered) matrix
14    int ldb = m;
15
16    // Host tri-diagonal matrix
17    //  2 -1  0  0  0
18    // -1  2 -1  0  0
19    //  0 -1  2 -1  0
20    //  0  0 -1  2 -1
21    //  0  0  0 -1  2
22    std::vector<float> hdl = {0.0f, -1.0f, -1.0f, -1.0f, -1.0f};
23    std::vector<float> hd  = {2.0f, 2.0f, 2.0f, 2.0f, 2.0f};
24    std::vector<float> hdu = {-1.0f, -1.0f, -1.0f, -1.0f, 0.0f};
25
26    // Host right-hand side column vectors
27    std::vector<float> hB(ldb * n, 1.0f);
28
29    float* ddl = nullptr;
30    float* dd  = nullptr;
31    float* ddu = nullptr;
32    float* dB  = nullptr;
33    HIP_CHECK(hipMalloc((void**)&ddl, sizeof(float) * m));
34    HIP_CHECK(hipMalloc((void**)&dd, sizeof(float) * m));
35    HIP_CHECK(hipMalloc((void**)&ddu, sizeof(float) * m));
36    HIP_CHECK(hipMalloc((void**)&dB, sizeof(float) * ldb * n));
37
38    HIP_CHECK(hipMemcpy(ddl, hdl.data(), sizeof(float) * m, hipMemcpyHostToDevice));
39    HIP_CHECK(hipMemcpy(dd, hd.data(), sizeof(float) * m, hipMemcpyHostToDevice));
40    HIP_CHECK(hipMemcpy(ddu, hdu.data(), sizeof(float) * m, hipMemcpyHostToDevice));
41    HIP_CHECK(hipMemcpy(dB, hB.data(), sizeof(float) * ldb * n, hipMemcpyHostToDevice));
42
43    // Obtain required buffer size
44    size_t bufferSize;
45    HIPSPARSE_CHECK(
46        hipsparseSgtsv2_nopivot_bufferSizeExt(handle, m, n, ddl, dd, ddu, dB, ldb, &bufferSize));
47
48    void* dbuffer;
49    HIP_CHECK(hipMalloc(&dbuffer, bufferSize));
50
51    HIPSPARSE_CHECK(hipsparseSgtsv2_nopivot(handle, m, n, ddl, dd, ddu, dB, ldb, dbuffer));
52
53    // Copy right-hand side to host
54    HIP_CHECK(hipMemcpy(hB.data(), dB, sizeof(float) * ldb * n, hipMemcpyDeviceToHost));
55
56    // Print the solution
57    printf("Solution for the tridiagonal system:\n");
58    for(int i = 0; i < m; ++i)
59    {
60        printf("  x[%d] = %f\n", i, hB[i]);
61    }
62
63    // Clean up
64    HIP_CHECK(hipFree(ddl));
65    HIP_CHECK(hipFree(dd));
66    HIP_CHECK(hipFree(ddu));
67    HIP_CHECK(hipFree(dB));
68    HIP_CHECK(hipFree(dbuffer));
69
70    HIPSPARSE_CHECK(hipsparseDestroy(handle));
71
72    return 0;
73}

hipsparseXgtsv2StridedBatch_bufferSizeExt()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXgtsv2StridedBatch()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXgtsvInterleavedBatch_bufferSizeExt()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXgtsvInterleavedBatch()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

  1int main(int argc, char* argv[])
  2{
  3    // hipSPARSE handle
  4    hipsparseHandle_t handle;
  5    HIPSPARSE_CHECK(hipsparseCreate(&handle));
  6
  7    // Size of each square tridiagonal matrix
  8    int m = 6;
  9
 10    // Number of batches
 11    int batchCount = 4;
 12
 13    // Can be Thomas algorithm (0), LU (1), or QR (2)
 14    int algo = 1;
 15
 16    // Host tridiagonal matrix
 17    std::vector<float> hdl(m * batchCount);
 18    std::vector<float> hd(m * batchCount);
 19    std::vector<float> hdu(m * batchCount);
 20
 21    // Solve multiple tridiagonal matrix systems by interleaving matrices for better memory access:
 22    //
 23    //      4 2 0 0 0 0        5 3 0 0 0 0        6 4 0 0 0 0        7 5 0 0 0 0
 24    //      2 4 2 0 0 0        3 5 3 0 0 0        4 6 4 0 0 0        5 7 5 0 0 0
 25    // A1 = 0 2 4 2 0 0   A2 = 0 3 5 3 0 0   A3 = 0 4 6 4 0 0   A4 = 0 5 7 5 0 0
 26    //      0 0 2 4 2 0        0 0 3 5 3 0        0 0 4 6 4 0        0 0 5 7 5 0
 27    //      0 0 0 2 4 2        0 0 0 3 5 3        0 0 0 4 6 4        0 0 0 5 7 5
 28    //      0 0 0 0 2 4        0 0 0 0 3 5        0 0 0 0 4 6        0 0 0 0 5 7
 29    //
 30    // hdl = 0 0 0 0 2 3 4 5 2 3 4 5 2 3 4 5 2 3 4 5 2 3 4 5
 31    // hd  = 4 5 6 7 4 5 6 7 4 5 6 7 4 5 6 7 4 5 6 7 4 5 6 7
 32    // hdu = 2 3 4 5 2 3 4 5 2 3 4 5 2 3 4 5 2 3 4 5 0 0 0 0
 33    for(int b = 0; b < batchCount; ++b)
 34    {
 35        for(int i = 0; i < m; ++i)
 36        {
 37            hdl[batchCount * i + b] = 2 + b;
 38            hd[batchCount * i + b]  = 4 + b;
 39            hdu[batchCount * i + b] = 2 + b;
 40        }
 41
 42        hdl[batchCount * 0 + b]       = 0.0f;
 43        hdu[batchCount * (m - 1) + b] = 0.0f;
 44    }
 45
 46    // Host dense rhs
 47    std::vector<float> hx(m * batchCount);
 48
 49    for(int b = 0; b < batchCount; ++b)
 50    {
 51        for(int i = 0; i < m; ++i)
 52        {
 53            hx[batchCount * i + b] = static_cast<float>(b + 1);
 54        }
 55    }
 56
 57    float* ddl = nullptr;
 58    float* dd  = nullptr;
 59    float* ddu = nullptr;
 60    float* dx  = nullptr;
 61    HIP_CHECK(hipMalloc((void**)&ddl, sizeof(float) * m * batchCount));
 62    HIP_CHECK(hipMalloc((void**)&dd, sizeof(float) * m * batchCount));
 63    HIP_CHECK(hipMalloc((void**)&ddu, sizeof(float) * m * batchCount));
 64    HIP_CHECK(hipMalloc((void**)&dx, sizeof(float) * m * batchCount));
 65
 66    HIP_CHECK(hipMemcpy(ddl, hdl.data(), sizeof(float) * m * batchCount, hipMemcpyHostToDevice));
 67    HIP_CHECK(hipMemcpy(dd, hd.data(), sizeof(float) * m * batchCount, hipMemcpyHostToDevice));
 68    HIP_CHECK(hipMemcpy(ddu, hdu.data(), sizeof(float) * m * batchCount, hipMemcpyHostToDevice));
 69    HIP_CHECK(hipMemcpy(dx, hx.data(), sizeof(float) * m * batchCount, hipMemcpyHostToDevice));
 70
 71    // 1. Get buffer size
 72    size_t bufferSize = 0;
 73    HIPSPARSE_CHECK(hipsparseSgtsvInterleavedBatch_bufferSizeExt(
 74        handle, algo, m, ddl, dd, ddu, dx, batchCount, &bufferSize));
 75
 76    void* dbuffer = nullptr;
 77    HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize));
 78
 79    // 2. Perform batched tridiagonal solve
 80    HIPSPARSE_CHECK(
 81        hipsparseSgtsvInterleavedBatch(handle, algo, m, ddl, dd, ddu, dx, batchCount, dbuffer));
 82
 83    // Copy solution back to host
 84    HIP_CHECK(hipMemcpy(hx.data(), dx, sizeof(float) * m * batchCount, hipMemcpyDeviceToHost));
 85
 86    // Print the solutions
 87    printf("Solutions for batched tridiagonal systems:\n");
 88    for(int b = 0; b < batchCount; ++b)
 89    {
 90        printf("  Batch %d:\n", b);
 91        for(int i = 0; i < m; ++i)
 92        {
 93            printf("    x[%d] = %f\n", i, hx[i * batchCount + b]);
 94        }
 95    }
 96
 97    // Clean up
 98    HIP_CHECK(hipFree(ddl));
 99    HIP_CHECK(hipFree(dd));
100    HIP_CHECK(hipFree(ddu));
101    HIP_CHECK(hipFree(dx));
102    HIP_CHECK(hipFree(dbuffer));
103
104    HIPSPARSE_CHECK(hipsparseDestroy(handle));
105
106    return 0;
107}

hipsparseXgpsvInterleavedBatch_bufferSizeExt()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

hipsparseXgpsvInterleavedBatch()#

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml

Warning

doxygenfunction: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipsparse/checkouts/7.13.0-preview/projects/hipsparse/docs/doxygen/xml/index.xml