Skip to content

loongarch64: fix segfaults in copy kernels and adjust dsyrk block size#5942

Open
HecaiYuan wants to merge 4 commits into
OpenMathLib:developfrom
HecaiYuan:develop
Open

loongarch64: fix segfaults in copy kernels and adjust dsyrk block size#5942
HecaiYuan wants to merge 4 commits into
OpenMathLib:developfrom
HecaiYuan:develop

Conversation

@HecaiYuan

Copy link
Copy Markdown

On LA464, dsyrk produces incorrect results with specific block dimension combinations (e.g., 80×16), which causes dcholesky and dpotrf to fail on positive-definite matrices.

Reduce GEMM_P from 112 to 96 for LoongArch64 LA464 double-precision builds, so the blocking logic avoids generating the problematic size.

The following minimal C program was used to pinpoint the issue:

// test_dsyrk.c
#include <stdio.h>
#include <cblas.h>
#include <stdlib.h>

#define N 194
int main(){
    double *A = malloc(N*N*sizeof(double));
    double *B = malloc(N*N*sizeof(double));
    for(int j=0;j<N;j++){
        for(int i=0;i<j;i++) A[i + j*N] = (double)rand()/RAND_MAX - 0.5;
        A[j + j*N] = (double)rand()/RAND_MAX + 8.0;
        for(int i=j+1;i<N;i++) A[i + j*N] = 0.0;
    }

    double alpha = 1.0, beta = 0.0;
    cblas_dsyrk(CblasColMajor, CblasLower, CblasNoTrans, N, N, alpha, A, N, beta, B, N);

    for (int i = 0; i < N; i++) 
        printf("B[%d][%d] = %g\n", i, i, B[i + i*N]);

    free(A); free(B);
    return 0;
}

Compile and run:

gcc test_dsyrk.c -o testd_syrk -I. -L. -lopenblas -lpthread -lm
./test_dsyrk

After fix: all diagonal elements remain positive as expected.

On LoongArch LA464 platform, dsyrk produces incorrect results
when processing certain block sizes, which in turn causes
dcholesky and dpotrf to fail on positive-definite matrices.

The issue manifests with specific block dimension combinations
(e.g., 80x16). Adjust GEMM_P from 112 to 96 so that
dsyrk's blocking logic avoids generating the problematic size.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant