Skip to content

spmv calculation error at one-base, correct calculation at zero-base #13

Description

@RustLyu

Hi.

  • aocl version:5.3
  • os:llinux
  • compile:gcc 16.1.1

Here is the code:
`#define M 5
#define N 5
#define NNZ 8

int test_example(void)
{
aoclsparse_status status;
aoclsparse_matrix A = NULL;
aoclsparse_mat_descr descr = NULL;
aoclsparse_operation trans = aoclsparse_operation_none;
//aoclsparse_index_base base = aoclsparse_index_base_zero;
aoclsparse_index_base base = aoclsparse_index_base_one;

double alpha = 1.0;
double beta  = 0.0;

// Original matrix
//  1  0  0  2  0
//  0  3  0  0  0
//  0  0  4  0  0
//  0  5  0  6  7
//  0  0  0  0  8
// aoclsparse_int coo_row_ind[NNZ] = {0, 0, 1, 2, 3, 3, 3, 4};
// aoclsparse_int coo_col_ind[NNZ] = {0, 3, 1, 2, 1, 3, 4, 4};
aoclsparse_int coo_row_ind[NNZ] = {1, 1, 2, 3, 4, 4, 4, 5};
aoclsparse_int coo_col_ind[NNZ] = {1, 4, 2, 4, 2, 4, 5, 5};
double         coo_val[NNZ]     = {1, 2, 3, 4, 5, 6, 7, 8};

// Input vectors
double x[N] = {1.0, 2.0, 3.0, 4.0, 5.0};
double y[M];

// Expected reference result & tolerance
double         y_exp[M] = {9.0, 6.0, 12.0, 69.0, 40.0};
double         tol      = 1e-12;
aoclsparse_int oki, ok = 1;

// Print aoclsparse version
printf("%s\n", aoclsparse_get_version());

// Create matrix descriptor
aoclsparse_create_mat_descr(&descr);

status = aoclsparse_create_dcoo(&A, base, M, N, NNZ, coo_row_ind, coo_col_ind, coo_val);
if(status != aoclsparse_status_success)
{
    printf("Error while creating COO sparse matrix, status = %i\n", status);
    return 1;
}
aoclsparse_matrix csr;

status = aoclsparse_convert_csr(
    A,
    aoclsparse_operation_none,
    &csr
    );
// Hint the system what operation to expect
status = aoclsparse_set_mv_hint(csr, trans, descr, 1);
if(status != aoclsparse_status_success)
{
    printf("Error while hinting operation, status = %i\n", status);
    return 1;
}

status = aoclsparse_optimize(csr);
if(status != aoclsparse_status_success)
{
    printf("Error while optimizing the matrix, status = %i\n", status);
    return 1;
}

// Invoke SPMV API (double precision)
printf("Invoking aoclsparse_dmv after COO->CSR optimize...\n");
status = aoclsparse_dmv(trans, &alpha, csr, descr, x, &beta, y);
if(status != aoclsparse_status_success)
{
    printf("Error while computing SPMV, status = %i\n", status);
    return 1;
}

// Print and check the results
printf("Output vector:\n");
for(aoclsparse_int i = 0; i < M; i++)
{
    oki = fabs(y[i] - y_exp[i]) <= tol;
    printf("  %lf %c\n", y[i], oki ? ' ' : '!');
    ok = ok && oki;
}

// Cleanup
aoclsparse_destroy_mat_descr(descr);
aoclsparse_destroy(&A);
return ok ? 0 : 2;

}
`
Everything is normal at 0 base, but when I just changed the matrix to 1-base, aoclsparse_det_mv_cint funtion returns aoclsparse_stus_invalid_value, Does this interface not support 1base?
Best regards!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions