Skip to content

OpenBLAS build fails due to segmentation fault on Power8 platform #2166

Closed

Description

@kavanabhat

OpenBLAS build fails for Power8 target in 64-bit mode(Both Redhat Big endian and AIX ). Details are as below:

#make DEBUG=1 BINARY=64 TARGET=POWER8
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0 0x3FFF95A692C3
#1 0x3FFF95A69E23
#2 0x3FFF95CB0477
#3 0x10078920 in dtrmm_ounucopy at trmm_uncopy_4.c:93
OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 ./cblat2 < ./cblat2.dat
OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 ./zblat2 < ./zblat2.dat
/bin/sh: line 1: 54413 Segmentation fault (core dumped) OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 ./dblat3 < ./dblat3.dat
make[1]: *** [level3] Error 139
make[1]: *** Waiting for unfinished jobs....
rm -f ?BLAT2.SUMM
OMP_NUM_THREADS=2 ./sblat2 < ./sblat2.dat
OMP_NUM_THREADS=2 ./dblat2 < ./dblat2.dat
OMP_NUM_THREADS=2 ./cblat2 < ./cblat2.dat
OMP_NUM_THREADS=2 ./zblat2 < ./zblat2.dat
make[1]: Leaving directory `/home/kavana/OpenBLAS/test'
make: *** [tests] Error 2
[root@pokndd8 OpenBLAS]# cd test
[root@pokndd8 test]# gdb ./dblat3
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-100.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "ppc64-redhat-linux-gnu".
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/...
Reading symbols from /home/kavana/OpenBLAS/test/dblat3...done.
(gdb) run < ./dblat3.dat
Starting program: /home/kavana/OpenBLAS/test/./dblat3 < ./dblat3.dat
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x3ffeb391f140 (LWP 54472)]
[New Thread 0x3ffeb311f140 (LWP 54473)]

.......

Program received signal SIGSEGV, Segmentation fault.
dtrmm_ounucopy (m=4294967297, n=12, a=0x3fffffff5ff0, lda=2, posX=0, posY=1, b=) at generic/trmm_uncopy_4.c:93
93 b[ 0] = data01;
(gdb) where
#0 dtrmm_ounucopy (m=4294967297, n=12, a=0x3fffffff5ff0, lda=2, posX=0, posY=1, b=) at generic/trmm_uncopy_4.c:93
#1 0x0000000010014f14 in dtrmm_RNUU (args=, range_m=, range_n=, sa=0x3ffeb3920000,
sb=0x3ffeb3cc0000, dummy=) at trmm_R.c:254
#2 0x000000001000fa64 in dtrmm_ (SIDE=, UPLO=, TRANS=, DIAG=,
M=, N=, alpha=, a=, ldA=0x3ffffffb3cd8, b=0x3ffffffe57e0, ldB=0x3ffffffb3cd4)
at trsm.c:381
#3 0x0000000010005bd8 in dchk3 (sname='DTRMM ', eps=2.2204460492503131e-16, thresh=16, nout=6, ntra=-1, trace=.FALSE., rewi=.FALSE.,
fatal=.FALSE., nidim=6, idim=..., nalf=3, alf=..., nmax=65, a=..., aa=..., as=..., b=..., bb=..., bs=..., ct=..., g=..., c=..., _sname=6)
at dblat3.f:1059
#4 0x000000001000e9a4 in dblat3 () at dblat3.f:292
#5 0x000000001000180c in main (argc=, argv=) at dblat3.f:355
#6 0x00003fffb7a06bec in generic_start_main (main=@0x100a0190: 0x100017e0

, argc=, ubp_av=0x3ffffffff4f8,
auxvec=0x3ffffffff5e8, init=, rtld_fini=, stack_end=, fini=)
at ../csu/libc-start.c:274
#7 0x00003fffb7a06e14 in __libc_start_main (argc=, ubp_av=, ubp_ev=, auxvec=,
rtld_fini=, stinfo=, stack_on_entry=) at ../sysdeps/unix/sysv/linux/powerpc/libc-start.c:91
#8 0x0000000000000000 in ?? ()
(gdb)

Activity

  1. kavanabhat commented on Jun 19, 2019

    @kavanabhat
    ContributorAuthor

    This issue is observed in the develop branch. But, the issue seems to be fixed in the master branch. The segmentation fault is due to stack corruption caused in kernel/power/dtrmm_kernel_16x4_power8.S. Closing this issue as it is fixed in master branch

  2. martin-frbg commented on Jun 19, 2019

    @martin-frbg
    Collaborator

    master branch is actually stale (and does not provide optimized assembly kernels for power8) but the power8 code in develop (and 0.3.6 release) is little-endian only. see #1997

  3. kavanabhat commented on Jun 19, 2019

    @kavanabhat
    ContributorAuthor

    Thanks for the information. The issue is not specific to endianness but the application mode. When compiled in 64-bit mode, this bug will be definitely corrupting the stack even on little endian systems. So, will reopen this.

  4. martin-frbg commented on Jun 19, 2019

    @martin-frbg
    Collaborator

    Then I assume this must have been caused by (or at least related to) my PR #1317 almost two years ago. I do wonder why it would go unnoticed for so long as I would think 64bit is what is typically used on that platform ? @quickwritereader
    (And I do need to correct what I wrote earlier - while master branch is stale at approximately v0.2.20,
    it already had the power8 codes written by wernsaar - unfortunately around two years ago it was noticed that these contained several systematic bugs including clobbering the vsx registers. An IBM guy submitted a partial fix and I tried to apply "corresponding" changes to the remaining files back then - without access to actual hardware and with only a limited understanding of ppc assembly)

  5. added this to the 0.3.7 milestone on Jun 19, 2019
  6. martin-frbg commented on Jun 19, 2019

    @martin-frbg
    Collaborator

    Thanks for the fix. So it was essentially a stray line, somehow duplicated from the code I was editing. ☹️

  7. added a commit that references this issue on Jun 19, 2019
  8. quickwritereader commented on Jun 20, 2019

    @quickwritereader
    Contributor

    as far as I know @martin-frbg your fixes worked and I did not have a problem with little endian. Still, fixes are welcomed. for power9 I was almost re-writing entry but just for le

  9. rguenth commented on Apr 17, 2025

    @rguenth

    I openend a bug on the GCC side, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119234, and after it was analyzed to
    be an alignment issue it shows it's an obvious bug in the powerpc specific openblas parts:

    OK, so the sources have

    __attribute__((altivec(vector__))) float *va0, *va1, *va2, *va3, *va4, *va5, 
    

    va6, va7, v_x;
    ...
    va0 = (attribute((altivec(vector__))) float
    ) a0;
    va1 = (attribute((altivec(vector__))) float
    ) a1;
    va2 = (attribute((altivec(vector__))) float
    ) a2;
    va3 = (attribute((altivec(vector__))) float*) a3;
    va4 = (attribute((altivec(vector__))) float*) a4;
    va5 = (attribute((altivec(vector__))) float*) a5;
    va6 = (attribute((altivec(vector__))) float*) a6;
    va7 = (attribute((altivec(vector__))) float*) a7;
    v_x = (attribute((altivec(vector__))) float*) x;

        for (i = 0; i < n/4; i ++) {
            temp0 += v_x[i] * va0[i];
            temp1 += v_x[i] * va1[i];
            temp2 += v_x[i] * va2[i];
            temp3 += v_x[i] * va3[i];
            temp4 += v_x[i] * va4[i];
            temp5 += v_x[i] * va5[i];
            temp6 += v_x[i] * va6[i];
            temp7 += v_x[i] * va7[i];
        }
    

    so GCC rightfully assumes that va?[i] and v_x[i] are aligned.

    The standard blas sgem kernels impose no such restrictions on the data arguments, so sgemv_t_POWER8 should, but I don't see any such thing.

    -> blas bug.

  10. quickwritereader commented on Apr 17, 2025

    @quickwritereader
    Contributor

    what compilers are used?. Are using Ibm ones?
    I will try to check the issue. Long time, I did not touch this

  11. rguenth commented on Apr 17, 2025

    @rguenth

    We ran into this using GCC compilers provided by SUSE Linux Enterprise 15 SP6 and later, but it reproduces with stock GCC from upstream for.

  12. quickwritereader commented on Apr 17, 2025

    @quickwritereader
    Contributor

    Could you check the problematic side on compiler-explorer.
    I mean, take the called function and called inner kernel function. #define what it needs.
    or just give me the problematic lines, I will see what it outputs.
    (p.s I should revise power side. right now I can't recall anything)

  13. 20 remaining items

  14. quickwritereader commented on Apr 17, 2025

    @quickwritereader
    Contributor

    nope, did not work for me in compiler explorer. https://godbolt.org/z/4neT6jnvc.
    @martin-frbg should we write inline assembly.

    Image

  15. quickwritereader commented on Apr 17, 2025

    @quickwritereader
    Contributor

    imho, what I wrote is the same intrinsics underhood. Just with named calls. it at least convert everything to the same. previously it was doing half half some with lvx the other with lxvd2x

  16. martin-frbg commented on Apr 17, 2025

    @martin-frbg
    Collaborator

    Inline assembly would probably be best to keep any compiler from making assumptions - I would not exclude that your code even worked with stock GNU GCC until recently, and only the recent expansion of the vectorizer code in GCC led to unsafe assumptions

  17. quickwritereader commented on Apr 17, 2025

    @quickwritereader
    Contributor

    I will try to see what I can do next week.
    1st option will be to try manually align and use force aligned vector intrinsics.
    2nd option will be just using inline assembly and force unaligned.
    `

    I suppose lda can come not multiply by 4, right, so it should be checked?. x buffer should come aligned.

  18. quickwritereader commented on Apr 17, 2025

    @quickwritereader
    Contributor

    Here is the forced unaligned version using helper with inline assembly

    https://godbolt.org/z/c6n8bj1fY

  19. quickwritereader commented on Apr 17, 2025

    @quickwritereader
    Contributor

    but of course, the better solution could be manually aligning buffers and checking lda, and using unaligned inside.
    but for gemv, I dont know if it is even worth to do it.

  20. quickwritereader commented on Apr 17, 2025

    @quickwritereader
    Contributor

    This version should produce better assembly imho
    for un alinged loads

     __vector float  lvx(FLOAT *ptr, BLASLONG byte_index) {
        __vector float v;
        __asm__("lvx %0, %1, %2"
                : "=v" (v)
                : "b" (ptr), "r" (byte_index));
        return v;
    }
    
    
    
           BLASLONG j=0;
            for (j = 0; j < n; j+=16) {
                vector float vx = lvx( x,j);
                vector float va0 = lvx(a0, j);
                vector float va1 = lvx( a1, j);
                vector float va2 = lvx( a2, j);
                vector float va3 = lvx( a3, j);
                vector float va4 = lvx( a4, j);
                vector float va5 = lvx( a5, j);
                vector float va6 = lvx( a6, j);
                vector float va7 = lvx( a7, j);
    
             
                temp0 += vx * va0;
                temp1 += vx * va1;
                temp2 += vx * va2;
                temp3 += vx * va3;
                temp4 += vx * va4;
                temp5 += vx * va5;
                temp6 += vx * va6;
                temp7 += vx * va7; 
            }
    
    
  21. quickwritereader commented on Apr 17, 2025

    @quickwritereader
    Contributor

    @martin-frbg , @rguenth Possible fix/workaround, forcing unalinged loads. Also produces the code similar to ibm's one.
    But it should be still tested. I only did it using compiler explorer

    https://godbolt.org/z/xY1nrjzb6

    Unfortunately, I dont have time to write better one, i.e aligned kernels, As It should be throughly tested for edge cases.
    I try next week if I have a time

  22. quickwritereader commented on Apr 17, 2025

    @quickwritereader
    Contributor

    Just for notes:
    lvx - loads unaligned
    --aligned ones-- (better for performance, used inside gemm)
    ~lxv - loads aligned ~
    lxvd2x - loads aligned
    vec_vsx_ld - loads aligned

    no builtins for unaligned. We use inline assembly helper
    IBM's gcc can correctly picks unaligned instructions
    Ordinary gcc picks aligned instruction usually, though there were not any hint.

    Possible solutions:
    A) force unaligned
    B) check what buffers can come unaligned, and manually align and correct

    for now we went with variant A

  23. quickwritereader commented on Apr 17, 2025

    @quickwritereader
    Contributor

    Just for notes: lvx - loads unaligned --aligned ones-- (better for performance, used inside gemm) ~lxv - loads aligned ~ lxvd2x - loads aligned vec_vsx_ld - loads aligned

    no builtins for unaligned. We use inline assembly helper IBM's gcc can correctly picks unaligned instructions Ordinary gcc picks aligned instruction usually, though there were not any hint.

    Possible solutions: A) force unaligned B) check what buffers can come unaligned, and manually align and correct

    for now we went with variant A

    alright, It seems I messed things as well, Probably I called alinged one unaligned. I recalled wrongly

    So the issue might be something else. like gcc mixing lvx and lxvd2x

  24. quickwritereader commented on Apr 17, 2025

    @quickwritereader
    Contributor

    @martin-frbg, @rguenth Guys, for now, do not apply any patch.
    it might be something else. not related to aligned or unaligned. or things related if any of compilers follows strict C standards( or not(imho in that case ordinary gcc is wrong again, by mixing things if it insists on size being aligned as well)
    Maybe loading order issue. loading two doubles vs 16 bytes
    I may need to check documents. and write simple executable codes. with compiler explorer I cant execute anything

  25. quickwritereader commented on Apr 17, 2025

    @quickwritereader
    Contributor

    @martin-frbg I just checked and compiled using the old power8 where It was build before.
    It is using unaligned loads correctly. so no problem.
    It means we can use unaligned loads for now. (Note: previously my recall lvx as aligned was wrong).
    in that case
    The proposed solution Jeevita's solution could be patch. No need inline lvx ,

    https://godbolt.org/z/ofh6rY5Kn n should be <n; i+=4

    it's better to check with the compiler where it makes issue.
    as for alignment(better performance) One needs to check lda for all a's and and shift maximum misaligned bytes. and compute those misaligned cases entrance and tail(is its needed)

  26. quickwritereader commented on Apr 17, 2025

    @quickwritereader
    Contributor

    so gcc version 8.3 was compiling it using unaligned loads.

    Image

    Image

    Image

    @rguenth could you try above unaligned loads. and see if it fixes.

  27. quickwritereader commented on Apr 17, 2025

    @quickwritereader
    Contributor

    Here is another case. It seems -DPOWER8 makes gcc to use an unaligned loads and also produce concise output

    @martin-frbg but, safe bet to explicitly to make it, for now to avoid problems. and also defined(POWER8) should be checked if it is passed or not

    https://godbolt.org/z/cP911qbar

  28. quickwritereader commented on Apr 18, 2025

    @quickwritereader
    Contributor

    patch sgemv_t: explicit unaligned vector loads(vec_vsx_load). patch

    coming on aligned access. for 8x4 inner kernel, we need either 3 extra x buffers misaligned(4, 8, 12) the same way as lda cases. or 1 extra buffer for 8 byte alignments. so its better users padds their matrix. Or we should use merge/shifting with mask to achieve pairwise i a[i]*x[i] from two consquences vectors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions