FilesLast commitLast update
README

Pentadiagonal Linear System Batch Solver Operator (Interleaved Batch)

Operator Overview

The gpsv_interleaved_batch operator batch-solves multiple independent pentadiagonal linear systems. Given batchCount pentadiagonal matrices A^(k) and the corresponding right-hand side vectors b^(k), the operator solves:

A^(k) · x^(k) = b^(k), k = 0, 1, ..., batchCount - 1

Each pentadiagonal matrix A^(k) is an m × m square matrix represented by five diagonals:

  • ds: distance-2 sub-diagonal
  • dl: sub-diagonal
  • d: main diagonal
  • du: super-diagonal
  • dw: distance-2 super-diagonal

The operator uses the row-major interleaved data layout, that is, each diagonal is viewed as a two-dimensional array [m][batchCount], and all batch data with the same row index are stored consecutively in memory:

data[row][batch] = data[row * batchCount + batch]

The current version is implemented with the QR decomposition algorithm (algo=0, based on Givens rotations), and the algorithm flow consists of two steps:

  1. Forward Givens Rotation: eliminate the distance-2 sub-diagonal ds and the sub-diagonal dl row by row through orthogonal rotations to obtain the upper triangular banded matrix R. For row i:
    • First apply a Givens rotation to rows i-2 and i to eliminate ds[i]
    • Then apply a Givens rotation to rows i-1 and i to eliminate dl[i]
  2. Backward Substitution: solve x step by step upward from the last row

This operator includes the following APIs:

API Brief Description
aclsparseSgpsvInterleavedBatch Batch-solves pentadiagonal linear systems (FP32), QR decomposition algorithm (Givens rotations)
aclsparseSgpsvInterleavedBatch_bufferSizeExt Queries the workspace size required by aclsparseSgpsvInterleavedBatch

Operator Execution APIs

aclsparseSgpsvInterleavedBatch

Product support

  • Ascend 950PR&950DT products: Supported
  • Atlas A3 products: Not supported
  • Atlas A2 products: Not supported

Function prototype

aclsparseStatus_t aclsparseSgpsvInterleavedBatch(
    aclsparseHandle_t handle,
    int algo, int m,
    float *ds, float *dl, float *d, float *du, float *dw, float *x,
    int batchCount, void *pBuffer);

Parameter description

Parameter Input/Output Type Description Memory Location
handle Input aclsparseHandle_t Context handle of the ops-sparse library, carrying the stream Host memory
algo Input int Algorithm selection: 0 = QR decomposition (Givens rotations, currently the only supported option) Host memory
m Input int Size of the linear system (number of rows = number of columns); must be ≥ 1 Host memory
ds Input float* Distance-2 sub-diagonal array of size m × batchCount (row-major interleaved). ds[0][*] and ds[1][*] are out-of-range elements and must be set to 0 before the call Device memory
dl Input float* Sub-diagonal array of size m × batchCount (row-major interleaved). dl[0][*] is an out-of-range element and must be set to 0 before the call Device memory
d Input float* Main diagonal array of size m × batchCount (row-major interleaved); cannot be nullptr Device memory
du Input float* Super-diagonal array of size m × batchCount (row-major interleaved). du[m-1][*] is an out-of-range element and must be set to 0 before the call Device memory
dw Input float* Distance-2 super-diagonal array of size m × batchCount (row-major interleaved). dw[m-2][*] and dw[m-1][*] are out-of-range elements and must be set to 0 before the call Device memory
x Input/Output float* Right-hand side b (input) / solution x (output), of size m × batchCount (row-major interleaved). On input, it is the right-hand side vector b, and after the computation, it is overwritten in place with the solution vector x Device memory
batchCount Input int Number of batches (number of independent systems); must be ≥ 1 Host memory
pBuffer Input void* Workspace buffer. nullptr can be passed when m=1; when m>1, a workspace is needed to store the R factor diagonals, whose size is queried by bufferSizeExt, and the address must be 128-byte aligned Device memory

Constraints

  • m ≥ 1
  • batchCount ≥ 1
  • Currently, algo supports only 0 (QR decomposition Givens rotations). algo = 1 or 2 returns ACL_SPARSE_STATUS_NOT_SUPPORTED, and algo < 0 or algo > 2 returns ACL_SPARSE_STATUS_INVALID_VALUE
  • None of ds, dl, d, du, dw, or x can be nullptr
  • pBuffer can be nullptr when m=1 (no workspace is needed); when m>1, pBuffer cannot be nullptr, and the address must be a multiple of 128 bytes
  • Out-of-range element constraints (user responsibility):
    • ds[0][k] = ds[1][k] = 0 (k = 0..batchCount-1), that is, ds[k] and ds[batchCount + k] must be 0
    • dl[0][k] = 0 (k = 0..batchCount-1), that is, dl[k] must be 0
    • du[m-1][k] = 0 (when m-1 >= 0), that is, du[(m-1)*batchCount + k] must be 0
    • dw[m-2][k] = dw[m-1][k] = 0 (when the corresponding row index >= 0), that is, dw[(m-2)*batchCount + k] and dw[(m-1)*batchCount + k] must be 0
  • The QR decomposition algorithm (algo=0) is based on Givens orthogonal rotations and has good numerical stability for general pentadiagonal systems (including non-diagonally dominant matrices). However, if the matrix is singular or nearly singular, the pivot may become zero or nearly zero during the rotations, resulting in an unstable solution or Inf/NaN under the IEEE-754 standard. The caller must ensure that the input pentadiagonal matrix is well-conditioned; otherwise, the precision of this batch is unpredictable.

aclsparseSgpsvInterleavedBatch_bufferSizeExt

Product support

  • Ascend 950PR&950DT products: Supported
  • Atlas A3 products: Not supported
  • Atlas A2 products: Not supported

Function prototype

aclsparseStatus_t aclsparseSgpsvInterleavedBatch_bufferSizeExt(
    aclsparseHandle_t handle,
    int algo, int m,
    const float *ds, const float *dl, const float *d, const float *du,
    const float *dw, const float *x,
    int batchCount, size_t *pBufferSizeInBytes);

Parameter description

Parameter Input/Output Type Description Memory Location
handle Input aclsparseHandle_t Context handle of the ops-sparse library Host memory
algo Input int Algorithm selection: 0 = QR decomposition (Givens rotations, currently the only supported option) Host memory
m Input int Size of the linear system (number of rows = number of columns); must be ≥ 1 Host memory
ds Input const float* Distance-2 sub-diagonal array pointer (nullptr can be passed for the query; bufferSizeExt does not read it) Device memory
dl Input const float* Sub-diagonal array pointer (nullptr can be passed for the query; bufferSizeExt does not read it) Device memory
d Input const float* Main diagonal array pointer (nullptr can be passed for the query; bufferSizeExt does not read it) Device memory
du Input const float* Super-diagonal array pointer (nullptr can be passed for the query; bufferSizeExt does not read it) Device memory
dw Input const float* Distance-2 super-diagonal array pointer (nullptr can be passed for the query; bufferSizeExt does not read it) Device memory
x Input const float* Right-hand side/solution vector array pointer (nullptr can be passed for the query; bufferSizeExt does not read it) Device memory
batchCount Input int Number of batches (number of independent systems); must be ≥ 1 Host memory
pBufferSizeInBytes Output size_t* Outputs the workspace size (bytes) required by aclsparseSgpsvInterleavedBatch; cannot be nullptr Host memory

Constraints

  • m ≥ 1
  • batchCount ≥ 1
  • Currently, algo supports only 0 (QR decomposition Givens rotations). algo = 1 or 2 returns ACL_SPARSE_STATUS_NOT_SUPPORTED, and algo < 0 or algo > 2 returns ACL_SPARSE_STATUS_INVALID_VALUE
  • pBufferSizeInBytes cannot be nullptr
  • Returns 0 when m=1 (no workspace is needed); when m>1, a workspace of 5 * ceil(m * batchCount / 32) * 32 * sizeof(float) bytes is needed (to store the 5 upper diagonals of the R factor)

Returns / Error Codes

Return Value Applicable APIs and Scenarios
ACL_SPARSE_STATUS_SUCCESS The query or solve succeeds
ACL_SPARSE_STATUS_HANDLE_IS_NULLPTR The handle of aclsparseSgpsvInterleavedBatch_bufferSizeExt or aclsparseSgpsvInterleavedBatch is nullptr
ACL_SPARSE_STATUS_INVALID_VALUE The parameters do not satisfy the constraints of the corresponding API; when m > 1, the workspace required by the query or solve API exceeds the 1 TiB upper limit; when m > 1, pBuffer of the solve API is empty or is not 128-byte aligned
ACL_SPARSE_STATUS_NOT_SUPPORTED algo is 1 or 2
ACL_SPARSE_STATUS_INTERNAL_ERROR The solve API fails to obtain the AIV core count or the result is 0
ACL_SPARSE_STATUS_EXECUTION_FAILED The solve API detects that kernel enqueue fails

The workspace size query API writes back the query result synchronously. The solve API returns asynchronously, and the caller checks the device asynchronous execution result through stream synchronization.

Supported sparse formats

Format Supported Description
CSR No Not applicable (this operator is a pentadiagonal solver and does not use the CSR format)
COO No Not applicable (this operator is a pentadiagonal solver and does not use the COO format)
CSC No Not applicable (this operator is a pentadiagonal solver and does not use the CSC format)
Pentadiagonal Yes Dense array representation using five diagonals (ds, dl, d, du, dw), row-major interleaved layout

Multi-Precision Version List

Precision Prefix Data Type Support
S float (FP32) Supported
D double (FP64) Not supported
C cuComplex (FP32 complex) Not supported
Z cuDoubleComplex (FP64 complex) Not supported

Currently, only the S prefix (FP32) version is implemented.

Invocation example

The example code is for reference only. For details about compilation and running, see Compiling and Running a Sample.

#include <cstdio>
#include <cstdlib>
#include <memory>
#include <vector>

#include "acl/acl.h"
#include "cann_ops_sparse.h"

#define CHECK_RET(cond, return_expr) \
    do {                             \
        if (!(cond)) {               \
            return_expr;             \
        }                            \
    } while (0)

#define LOG_PRINT(message, ...)         \
    do {                                \
        printf(message, ##__VA_ARGS__); \
    } while (0)

class AclContext {
public:
    explicit AclContext(int32_t deviceId) : deviceId_(deviceId) {}

    ~AclContext()
    {
        if (stream_ != nullptr) {
            aclrtDestroyStream(stream_);
            stream_ = nullptr;
        }
        if (deviceSet_) {
            aclrtResetDevice(deviceId_);
            deviceSet_ = false;
        }
        if (aclInited_) {
            aclFinalize();
            aclInited_ = false;
        }
    }

    int Init()
    {
        auto ret = aclInit(nullptr);
        CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret);
        aclInited_ = true;

        ret = aclrtSetDevice(deviceId_);
        CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret);
        deviceSet_ = true;

        ret = aclrtCreateStream(&stream_);
        CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret);
        return ACL_SUCCESS;
    }

    aclrtStream Stream() const { return stream_; }

private:
    int32_t deviceId_;
    aclrtStream stream_ = nullptr;
    bool aclInited_ = false;
    bool deviceSet_ = false;
};

int aclsparseSgpsvInterleavedBatchTest(AclContext& ctx)
{
    aclrtStream stream = ctx.Stream();

    // 1. Create the ops-sparse handle
    aclsparseHandle_t rawHandle = nullptr;
    auto sparseRet = aclsparseCreate(&rawHandle);
    CHECK_RET(sparseRet == ACL_SPARSE_STATUS_SUCCESS,
              LOG_PRINT("aclsparseCreate failed. ERROR: %d\n", sparseRet); return sparseRet);
    std::unique_ptr<aclsparseContext, aclsparseStatus_t (*)(aclsparseHandle_t)>
        handlePtr(rawHandle, aclsparseDestroy);

    sparseRet = aclsparseSetStream(static_cast<aclsparseHandle_t>(handlePtr.get()), stream);
    CHECK_RET(sparseRet == ACL_SPARSE_STATUS_SUCCESS,
              LOG_PRINT("aclsparseSetStream failed. ERROR: %d\n", sparseRet); return sparseRet);

    // 2. Prepare host data
    //    Example: m=4, batchCount=2, solving 2 pentadiagonal systems of 4x4
    //
    //    System 0:                         System 1:
    //    [ 4  1  1  0] [x0]   [ 6]         [ 5  1  1  0] [x0]   [ 7]
    //    [ 1  4  1  1] [x1] = [ 7]         [ 1  5  1  1] [x1] = [ 8]
    //    [ 1  1  4  1] [x2]   [ 7]         [ 1  1  5  1] [x2] = [ 8]
    //    [ 0  1  1  4] [x3]   [ 6]         [ 0  1  1  5] [x3]   [ 7]
    //
    //    row-major interleaved: data[row * batchCount + batch]

    const int m = 4;
    const int batchCount = 2;
    const int totalElems = m * batchCount;  // 8

    // ds: distance-2 sub-diagonal [m][batchCount], ds[0][*] and ds[1][*] must be 0
    std::vector<float> hDs(totalElems, 0.0f);
    // ds[0][0]=ds[0][1]=0, ds[1][0]=ds[1][1]=0 (out-of-range elements, already initialized to 0)
    hDs[2 * batchCount + 0] = 1.0f;  // ds[2][0]
    hDs[2 * batchCount + 1] = 1.0f;  // ds[2][1]
    hDs[3 * batchCount + 0] = 1.0f;  // ds[3][0] = 1
    hDs[3 * batchCount + 1] = 1.0f;  // ds[3][1] = 1

    // dl: sub-diagonal [m][batchCount], dl[0][*] must be 0
    std::vector<float> hDl(totalElems, 0.0f);
    // dl[0][0]=0, dl[0][1]=0 (out-of-range elements, already initialized to 0)
    hDl[1 * batchCount + 0] = 1.0f;  // dl[1][0]
    hDl[1 * batchCount + 1] = 1.0f;  // dl[1][1]
    hDl[2 * batchCount + 0] = 1.0f;  // dl[2][0]
    hDl[2 * batchCount + 1] = 1.0f;  // dl[2][1]
    hDl[3 * batchCount + 0] = 1.0f;  // dl[3][0]
    hDl[3 * batchCount + 1] = 1.0f;  // dl[3][1]

    // d: main diagonal [m][batchCount]
    std::vector<float> hD(totalElems, 0.0f);
    hD[0 * batchCount + 0] = 4.0f;   // d[0][0]
    hD[0 * batchCount + 1] = 5.0f;   // d[0][1]
    hD[1 * batchCount + 0] = 4.0f;   // d[1][0]
    hD[1 * batchCount + 1] = 5.0f;   // d[1][1]
    hD[2 * batchCount + 0] = 4.0f;   // d[2][0]
    hD[2 * batchCount + 1] = 5.0f;   // d[2][1]
    hD[3 * batchCount + 0] = 4.0f;   // d[3][0]
    hD[3 * batchCount + 1] = 5.0f;   // d[3][1]

    // du: super-diagonal [m][batchCount], du[m-1][*] must be 0
    std::vector<float> hDu(totalElems, 0.0f);
    hDu[0 * batchCount + 0] = 1.0f;  // du[0][0]
    hDu[0 * batchCount + 1] = 1.0f;  // du[0][1]
    hDu[1 * batchCount + 0] = 1.0f;  // du[1][0]
    hDu[1 * batchCount + 1] = 1.0f;  // du[1][1]
    hDu[2 * batchCount + 0] = 1.0f;  // du[2][0]
    hDu[2 * batchCount + 1] = 1.0f;  // du[2][1]
    // du[3][0]=0, du[3][1]=0 (out-of-range elements, already initialized to 0)

    // dw: distance-2 super-diagonal [m][batchCount], dw[m-2][*] and dw[m-1][*] must be 0
    std::vector<float> hDw(totalElems, 0.0f);
    hDw[0 * batchCount + 0] = 1.0f;  // dw[0][0]
    hDw[0 * batchCount + 1] = 1.0f;  // dw[0][1]
    hDw[1 * batchCount + 0] = 1.0f;  // dw[1][0]
    hDw[1 * batchCount + 1] = 1.0f;  // dw[1][1]
    // dw[2][0]=dw[2][1]=0, dw[3][0]=dw[3][1]=0 (out-of-range elements, already initialized to 0)

    // x: right-hand side b [m][batchCount] (input), to be overwritten with the solution
    std::vector<float> hX(totalElems, 0.0f);
    hX[0 * batchCount + 0] = 6.0f;   // b[0][0]
    hX[0 * batchCount + 1] = 7.0f;   // b[0][1]
    hX[1 * batchCount + 0] = 7.0f;   // b[1][0]
    hX[1 * batchCount + 1] = 8.0f;   // b[1][1]
    hX[2 * batchCount + 0] = 7.0f;   // b[2][0]
    hX[2 * batchCount + 1] = 8.0f;   // b[2][1]
    hX[3 * batchCount + 0] = 6.0f;   // b[3][0]
    hX[3 * batchCount + 1] = 7.0f;   // b[3][1]

    // 3. Allocate device memory and copy data
    const size_t dataSize = static_cast<size_t>(totalElems) * sizeof(float);

    void *dDs = nullptr, *dDl = nullptr, *dD = nullptr, *dDu = nullptr, *dDw = nullptr, *dX = nullptr;
    auto aclRet = aclrtMalloc(&dDs, dataSize, ACL_MEM_MALLOC_HUGE_FIRST);
    CHECK_RET(aclRet == ACL_SUCCESS, LOG_PRINT("aclrtMalloc for ds failed\n"); return aclRet);
    aclRet = aclrtMalloc(&dDl, dataSize, ACL_MEM_MALLOC_HUGE_FIRST);
    CHECK_RET(aclRet == ACL_SUCCESS, LOG_PRINT("aclrtMalloc for dl failed\n"); return aclRet);
    aclRet = aclrtMalloc(&dD, dataSize, ACL_MEM_MALLOC_HUGE_FIRST);
    CHECK_RET(aclRet == ACL_SUCCESS, LOG_PRINT("aclrtMalloc for d failed\n"); return aclRet);
    aclRet = aclrtMalloc(&dDu, dataSize, ACL_MEM_MALLOC_HUGE_FIRST);
    CHECK_RET(aclRet == ACL_SUCCESS, LOG_PRINT("aclrtMalloc for du failed\n"); return aclRet);
    aclRet = aclrtMalloc(&dDw, dataSize, ACL_MEM_MALLOC_HUGE_FIRST);
    CHECK_RET(aclRet == ACL_SUCCESS, LOG_PRINT("aclrtMalloc for dw failed\n"); return aclRet);
    aclRet = aclrtMalloc(&dX, dataSize, ACL_MEM_MALLOC_HUGE_FIRST);
    CHECK_RET(aclRet == ACL_SUCCESS, LOG_PRINT("aclrtMalloc for x failed\n"); return aclRet);

    aclrtMemcpy(dDs, dataSize, hDs.data(), dataSize, ACL_MEMCPY_HOST_TO_DEVICE);
    aclrtMemcpy(dDl, dataSize, hDl.data(), dataSize, ACL_MEMCPY_HOST_TO_DEVICE);
    aclrtMemcpy(dD, dataSize, hD.data(), dataSize, ACL_MEMCPY_HOST_TO_DEVICE);
    aclrtMemcpy(dDu, dataSize, hDu.data(), dataSize, ACL_MEMCPY_HOST_TO_DEVICE);
    aclrtMemcpy(dDw, dataSize, hDw.data(), dataSize, ACL_MEMCPY_HOST_TO_DEVICE);
    aclrtMemcpy(dX, dataSize, hX.data(), dataSize, ACL_MEMCPY_HOST_TO_DEVICE);

    // 4. Query the required buffer size
    size_t bufferSize = 0;
    sparseRet = aclsparseSgpsvInterleavedBatch_bufferSizeExt(
        static_cast<aclsparseHandle_t>(handlePtr.get()),
        0,  // algo = QR/Givens
        m,
        static_cast<const float*>(dDs),
        static_cast<const float*>(dDl),
        static_cast<const float*>(dD),
        static_cast<const float*>(dDu),
        static_cast<const float*>(dDw),
        static_cast<const float*>(dX),
        batchCount,
        &bufferSize);
    CHECK_RET(sparseRet == ACL_SPARSE_STATUS_SUCCESS,
              LOG_PRINT("bufferSizeExt failed. ERROR: %d\n", sparseRet); return sparseRet);

    // 5. Allocate the workspace buffer (when m>1, the QR algorithm needs a workspace to store the R factor diagonals)
    void *pBuffer = nullptr;
    if (bufferSize > 0) {
        aclRet = aclrtMalloc(&pBuffer, bufferSize, ACL_MEM_MALLOC_HUGE_FIRST);
        CHECK_RET(aclRet == ACL_SUCCESS,
                  LOG_PRINT("aclrtMalloc for pBuffer failed\n"); return aclRet);
    }

    // 6. Call the operator to solve
    sparseRet = aclsparseSgpsvInterleavedBatch(
        static_cast<aclsparseHandle_t>(handlePtr.get()),
        0,  // algo = QR/Givens
        m,
        static_cast<float*>(dDs),
        static_cast<float*>(dDl),
        static_cast<float*>(dD),
        static_cast<float*>(dDu),
        static_cast<float*>(dDw),
        static_cast<float*>(dX),
        batchCount,
        pBuffer);
    CHECK_RET(sparseRet == ACL_SPARSE_STATUS_SUCCESS,
              LOG_PRINT("aclsparseSgpsvInterleavedBatch failed. ERROR: %d\n", sparseRet);
              if (pBuffer) aclrtFree(pBuffer); return sparseRet);

    // 7. Synchronize and read the result
    aclRet = aclrtSynchronizeStream(stream);
    CHECK_RET(aclRet == ACL_SUCCESS,
              LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", aclRet); return aclRet);

    std::vector<float> hResult(totalElems, 0.0f);
    aclRet = aclrtMemcpy(hResult.data(), dataSize, dX, dataSize, ACL_MEMCPY_DEVICE_TO_HOST);
    CHECK_RET(aclRet == ACL_SUCCESS,
              LOG_PRINT("copy result failed. ERROR: %d\n", aclRet); return aclRet);

    // Print the solution vector
    for (int k = 0; k < batchCount; k++) {
        LOG_PRINT("Batch %d solution:\n", k);
        for (int i = 0; i < m; i++) {
            LOG_PRINT("  x[%d][%d] = %f\n", i, k, hResult[i * batchCount + k]);
        }
    }

    // 8. Clean up
    if (pBuffer) aclrtFree(pBuffer);
    aclrtFree(dDs);
    aclrtFree(dDl);
    aclrtFree(dD);
    aclrtFree(dDu);
    aclrtFree(dDw);
    aclrtFree(dX);

    return ACL_SPARSE_STATUS_SUCCESS;
}

int main()
{
    AclContext ctx(0);
    auto ret = ctx.Init();
    CHECK_RET(ret == ACL_SUCCESS, return ret);

    ret = aclsparseSgpsvInterleavedBatchTest(ctx);
    CHECK_RET(ret == ACL_SPARSE_STATUS_SUCCESS,
              LOG_PRINT("aclsparseSgpsvInterleavedBatchTest failed. ERROR: %d\n", ret); return ret);
    return 0;
}

The expected output is as follows:

Batch 0 solution:
  x[0][0] = 1.000000
  x[1][0] = 1.000000
  x[2][0] = 1.000000
  x[3][0] = 1.000000
Batch 1 solution:
  x[0][1] = 1.000000
  x[1][1] = 1.000000
  x[2][1] = 1.000000
  x[3][1] = 1.000000

Appendix: Algorithm Description

QR Decomposition (Givens Rotations) for Pentadiagonal Banded Matrices

This operator uses QR decomposition (based on Givens orthogonal rotations) to solve pentadiagonal linear systems. For an m × m pentadiagonal matrix A, its non-zero elements are distributed only on five diagonals:

A[i][i-2] = ds[i]   (i ≥ 2)
A[i][i-1] = dl[i]   (i ≥ 1)
A[i][i]   = d[i]    (0 ≤ i < m)
A[i][i+1] = du[i]   (0 ≤ i < m-1)
A[i][i+2] = dw[i]   (0 ≤ i < m-2)

Forward Givens rotations: for each row i (starting from row 2), perform two rotations in sequence:

  1. Eliminate ds[i]: construct the Givens rotation matrix G(i-2, i) for rows i-2 and i, so that the distance-2 sub-diagonal element of row i is eliminated after the rotation. The rotation parameters are cs = d'[i-2] / hyp, sn = ds'[i] / hyp, where hyp = sqrt(d'[i-2]² + ds'[i]²)
  2. Eliminate dl[i]: construct the Givens rotation matrix G(i-1, i) for rows i-1 and i, so that the sub-diagonal element of row i is eliminated after the rotation. The rotation parameters are computed in the same way

After the rotations, the original matrix is transformed into the upper triangular banded matrix R = Q^T A, and the right-hand side is transformed into b' = Q^T b. Due to the fill-in effect of Givens rotations, R contains 5 upper diagonals:

  • d'[i]: main diagonal of R
  • du'[i]: first super-diagonal of R (R[i, i+1])
  • dw'[i]: second super-diagonal of R (R[i, i+2])
  • d4'[i]: third super-diagonal of R (R[i, i+3]), valid only when i ≤ m-4
  • d5'[i]: fourth super-diagonal of R (R[i, i+4]), valid only when i ≤ m-5
  • b'[i]: transformed right-hand side

Backward substitution: solve upward from the last row:

x[m-1] = b'[m-1] / d'[m-1]
x[m-2] = (b'[m-2] - du'[m-2] * x[m-1]) / d'[m-2]
x[m-3] = (b'[m-3] - du'[m-3] * x[m-2] - dw'[m-3] * x[m-1]) / d'[m-3]
x[m-4] = (b'[m-4] - du'[m-4] * x[m-3] - dw'[m-4] * x[m-2] - d4'[m-4] * x[m-1]) / d'[m-4]
x[i]   = (b'[i] - du'[i]*x[i+1] - dw'[i]*x[i+2] - d4'[i]*x[i+3] - d5'[i]*x[i+4]) / d'[i]  (i = m-5, ..., 0)

This algorithm needs an additional workspace to store the 5 upper diagonals of R (d', du', dw', d4', d5'), and the workspace size is queried by aclsparseSgpsvInterleavedBatch_bufferSizeExt. The input diagonals ds/dl/d/du/dw remain read-only during the computation and are not modified.