Skip to content

wrong answers with 0.3.7 on POWER8 and POWER9 #2233

Closed

Description

@cparrott73

Not sure if you guys were already aware of this, but I wanted to pass this one along, just in case.

I was trying out the OpenBLAS 0.3.7 release on our POWER8 ("garrison") and POWER9 ("newell") OpenPOWER systems here this week. I used GCC 9.2.0, although I have also observed similar behavior with GCC 8.3.0, which leads me to believe that this issue is not related to a particular release of GCC.

The library compiles fine, but several tests are failing on both platforms with accuracy errors:

 CGEMV  PASSED THE TESTS OF ERROR-EXITS

 ******* FATAL ERROR - COMPUTED RESULT IS LESS THAN HALF ACCURATE *******
                       EXPECTED RESULT                    COMPUTED RESULT
       1  (  -0.102385    ,   0.226428    )  (    0.00000    ,    0.00000    )
       2  (   0.108077    ,   0.805703E-01)  (  -0.102385    ,   0.226428    )
       3  (   0.992165E-02,  -0.840403E-01)  (   0.108077    ,   0.805703E-01)
       4  (   0.192725    ,   0.176668    )  (   0.992165E-02,  -0.840403E-01)
 ******* CGEMV  FAILED ON CALL NUMBER:
    512: CGEMV ('N',  4,  2,( 1.0, 0.0), A,  5, X,-1,( 0.0, 0.0), Y, 1)         .

I see similar issues with CGBMV, CHEMV, CHPMV, CTRMV, CTPMV, CTRSV, CTPSV, CGERC, CGERU, CHER, CHPR, CHER2, and CHPR2.

The cblas_cgemv test also fails:

 ******* FATAL ERROR - COMPUTED RESULT IS LESS THAN HALF ACCURATE *******
                       EXPECTED RESULT                    COMPUTED RESULT
       1  (  -0.342872    ,   0.714919E-02)  (  -0.342872    ,   0.714919E-02)
       2  (   0.233743    ,  -0.822020E-01)  (   0.233743    ,  -0.822020E-01)
       3  (   0.376182E-01,   0.161061    )  (   0.376182E-01,   0.161061    )
       4  (   0.144652    ,   0.137748    )  (    0.00000    ,    0.00000    )
 ******* cblas_cgemv  FAILED ON CALL NUMBER:
    440: cblas_cgemv (  CblasNoTrans,  4,  2,( 1.0, 0.0), A,
            5, X, 1,( 0.0, 0.0), Y, 1) .
 ******* cblas_cgemv  FAILED ON CALL NUMBER:
      4: cblas_cgemv (  CblasNoTrans,  2,  1,( 0.0, 0.0), A,
            3, X, 1,( 0.0, 0.0), Y, 1) .

 ******* FATAL ERROR - TESTS ABANDONED *******

I built this using the following command:

make CC=gcc FC=gfortran USE_OPENMP=1 NUM_THREADS=512 DYNAMIC_ARCH=1 all

I also tried this with USE_OPENMP=0, but still got the same failures.

Environment details:

CPU: POWER8, POWER9
OS: RHEL 7.5
Compiler: GCC 9.2.0, GCC 8.3.0 (both built internally from sources)

Thanks in advance.

Activity

  1. martin-frbg commented on Aug 21, 2019

    @martin-frbg
    Collaborator

    This would appear to point to a problem in #1994 - in that case the errors should go away when you switch back kernel/power/KERNEL.POWER8 (and KERNEL.POWER9) to define CGEMVNKERNEL=../arm/zgemv_n.c and CGEMVTKERNEL=../arm/zgemv_t.c instead of the new, local cgemv_n.c/cgemv_t.c

  2. cparrott73 commented on Aug 21, 2019

    @cparrott73
    ContributorAuthor

    Thanks, Martin. I tried reverting the kernels for CGEMV as you suggested, and indeed, the tests now pass:

     CGEMV  PASSED THE TESTS OF ERROR-EXITS
    
     CGEMV  PASSED THE COMPUTATIONAL TESTS (  4324 CALLS)
    

    I presume I would need to do a similar reversion for CGBMV and the other failures?

    Thanks so much.

    +chris

  3. martin-frbg commented on Aug 21, 2019

    @martin-frbg
    Collaborator

    Actually I would hope that these errors will be gone as well, once you do a full recompile. The "banded matrix" etc. variants should all use essentially the same "general" CGEMV microkernel

  4. cparrott73 commented on Aug 21, 2019

    @cparrott73
    ContributorAuthor

    You're right. Not sure what happened before, but I just cleaned everything and then commented out those two lines in for CGEMVNKERNEL and CGEMVTKERNEL in KERNEL.POWER8- essentially reverting to them how they were before - and everything passes now after I rebuilt.

  5. cparrott73 commented on Aug 21, 2019

    @cparrott73
    ContributorAuthor

    Correction - I did end up having to revert several other files, too. Here are the lines I ended up commenting out in KERNEL.POWER8:

    #SAXPYKERNEL  = saxpy.c
    #CAXPYKERNEL  = caxpy.c
    
    #CDOTKERNEL = cdot.c
    
    #SGEMVNKERNEL = sgemv_n.c
    #CGEMVNKERNEL = cgemv_n.c
    
    #SGEMVTKERNEL = sgemv_t.c
    #CGEMVTKERNEL = cgemv_t.c
    

    Uncommenting any one of these seems to be sufficient to cause test failures.

  6. martin-frbg commented on Aug 22, 2019

    @martin-frbg
    Collaborator

    Our Ci test is passing (e.g. https://travis-ci.org/xianyi/OpenBLAS/jobs/573911250), but it is using an older (5.2) release of gcc. In the past, misbehaviour with gcc 8 was usually a sign of mistakes in our inline assembly, brought to light by more aggressive register reuse. However the new cgemv files do not even use inline assembly directly. @quickwritereader ?

  7. cparrott73 commented on Aug 22, 2019

    @cparrott73
    ContributorAuthor

    Interesting. I figured I should try a newer GCC for POWER9 support. GCC 5.x doesn't seem to support the -mcpu=power9 argument, at least when I tried it here.

    I tried GCC 6.5.0 here instead, which does appear to support -mcpu=power9. Indeed, I did not get the test failures this time. So I would concur with your assessment that newer GCC versions must be doing something involving register selection that is messing with the inline assembly in these routines.

    It's not an issue for us to use GCC 6.5.0 to build OpenBLAS here, for the time being. Thanks.

  8. martin-frbg commented on Aug 26, 2019

    @martin-frbg
    Collaborator

    I have now requested&obtained an account on the unicamp.br minicloud - initial POWER8 compile tests there show that building with gcc/gfortran 7.3.1 works flawlessly, but a 8.2.1 build shows failures in a lot of the single-precision complex tests. (CGEMV, CGBMV, CHBMV, CHPMV, CTRMV, CTPMV, CTRSV and CTPSV are flagged as "less than half accurate", often with the deviating values in the 1e10 range . Others like CGERC and CGERU get "parameter 8 was changed incorrectly". Stack corruption ?)

  9. quickwritereader commented on Aug 26, 2019

    @quickwritereader
    Contributor

    I just saw. could you elaborate on what I should check

  10. quickwritereader commented on Aug 26, 2019

    @quickwritereader
    Contributor

    Passed for me using these:
    Operating System: CentOS Linux 7 (AltArch):

    gcc (GCC) 8.3.1 20190304 (Advance-Toolchain-at12.0) [revision 269374]
    Copyright (C) 2018 Free Software Foundation, Inc.


    Operating System: Ubuntu 18.04
    gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
    Copyright (C) 2017 Free Software Foundation, Inc. E.

  11. quickwritereader commented on Aug 26, 2019

    @quickwritereader
    Contributor

    Yes, failed codes by op are written with vector C (So, there are not any inline assembly codes ). So it can be reviewed easily. Sometimes, it is hard to spot your own problems.

  12. martin-frbg commented on Aug 26, 2019

    @martin-frbg
    Collaborator

    Most if not all of the "LESS THAN HALF ACCURATE" errors from the lapack test appear to be related to the new CAXPY. Trying to narrow it down further... my tests are run on openSUSE/ppc64le on POWER8 hardware as provided by unicamp. I have not yet tried to build my own gcc9 there

  13. quickwritereader commented on Aug 26, 2019

    @quickwritereader
    Contributor

    @martin-frbg if it is possible could you re-check caxpy using BLAS_TESTER ,too
    frankly, I don't know what can go wrong. if errors persist I will try to compile those version of gcc to test at the week-end
    ./xcl1blastst -N 1 1331 1

  14. martin-frbg commented on Aug 26, 2019

    @martin-frbg
    Collaborator

    As individual tests for some of these functions still work, I suspect we are seeing some unexpected side effect of (using) the codes from altivec.h. Not sure why this happens only with the newer gcc,
    would it perhaps enforce a requirement for the -maltivec option (which does not appear to be set in Makefile.power) ? (The xcl1blastst passes with both old and new versions of the caxpy kernel)

  15. quickwritereader commented on Aug 26, 2019

    @quickwritereader
    Contributor

    well, I think that gcc somehow messing ABI while translating if it gets parameters changed error. Such problems arise when writing assembly code by hand and when you improperly use registers.

  16. 27 remaining items

  17. quickwritereader commented on Aug 29, 2019

    @quickwritereader
    Contributor

    I remembered that I saw such behaviour once. Probably, lost that after toolchain changes

  18. martin-frbg commented on Aug 29, 2019

    @martin-frbg
    Collaborator

    Same values (with gcc, and all changes reverted except the undefining of the dgemv_t 4x8_ASM):

    ******* FATAL ERROR - COMPUTED RESULT IS LESS THAN HALF ACCURATE *******
                           EXPECTED RESULT                    COMPUTED RESULT
           1  (  -0.342872    ,   0.714919E-02)  (   0.233743    ,  -0.822020E-01)
           2  (   0.233743    ,  -0.822020E-01)  (   0.376182E-01,   0.161061    )
           3  (   0.376182E-01,   0.161061    )  (   0.144652    ,   0.137748    )
           4  (   0.144652    ,   0.137748    )  (    0.00000    ,    0.00000    )
     ******* cblas_cgemv  FAILED ON CALL NUMBER:
        440: cblas_cgemv (  CblasNoTrans,  4,  2,( 1.0, 0.0), A,
                5, X, 1,( 0.0, 0.0), Y, 1) .
     ******* cblas_cgemv  FAILED ON CALL NUMBER:
          4: cblas_cgemv (  CblasNoTrans,  2,  1,( 0.0, 0.0), A,
                3, X, 1,( 0.0, 0.0), Y, 1) .
    

    Took me a moment to realize what you meant by "shifted", made me wonder if you could do bit shifts on the internal representation of floats in your head...
    Edit: with the other errors it is less "obvious" - mostly individual numbers in the middle of a column
    that are wrong, or only the last line wrong (CHER,CHPR). Trying #pragma GCC optimize "O0" in cgemv_n.c and cgemv_t.c next...

  19. martin-frbg commented on Aug 29, 2019

    @martin-frbg
    Collaborator

    Adding #pragma GCC optimize "O0" to cgemv_n.c, cgemv_t.c, caxpy.c and cdot.c appears to be a (temporary) solution, at least as far as the built-in tests go. (No idea what that means - though the common factor of these four files is that they use vector intrinsics. Perhaps it is possible to make unsafe assumptions about register (re)usage there as well, with the potential to hit seemingly unrelated functions that use the same registers later ?)

  20. quickwritereader commented on Aug 29, 2019

    @quickwritereader
    Contributor

    for now I am suspicious of swap_mask . I wrote simple code and it did not load fully

  21. quickwritereader commented on Aug 29, 2019

    @quickwritereader
    Contributor

    Possible solution.
    static const char __attribute__((aligned(16))) swap_mask_arr[]={,,}
    with pure assembly I would use constant loading, anyway

    Alignment did not work. I will recheck ,later.

  22. quickwritereader commented on Aug 29, 2019

    @quickwritereader
    Contributor

    Ok. So far I cant understand why it chooses load 16byte-aligned lvx over (afaik 4byte or unaligned) lxv
    Here is assemblies
    gcc-8

       │0x10007390 <cgemv_n+2336>       lvx     v1,r5,r9                                                                                                                       │
       │0x10007394 <cgemv_n+2340>       lvx     v0,r30,r9                                                                                                                      │
       │0x10007398 <cgemv_n+2344>       addi    r8,r8,2                                                                                                                        │
       │0x1000739c <cgemv_n+2348>       lvx     v12,r7,r9                                                                                                                      │
       │0x100073a0 <cgemv_n+2352>       lvx     v13,r6,r9                                                                                                                      │
       │0x100073a4 <cgemv_n+2356>       cmpd    cr7,r3,r8                                                                                                                      │
       │0x100073a8 <cgemv_n+2360>       lvx     v5,r31,r9                                                                                                                      │
       │0x100073ac <cgemv_n+2364>       lvx     v6,r10,r9                                                                                                                      │
       │0x100073b0 <cgemv_n+2368>       xvmulsp vs10,vs12,vs33                                                                                                                 │
       │0x100073b4 <cgemv_n+2372>       xvmulsp vs11,vs12,vs32                                                                                                                 │
       │0x100073b8 <cgemv_n+2376>       vperm   v9,v12,v12,v11                                                                                                                 │
       │0x100073bc <cgemv_n+2380>       vperm   v10,v13,v13,v11                                                                                                                │
       │0x100073c0 <cgemv_n+2384>       vperm   v1,v1,v1,v11                                                                                                                   │
       │0x100073c4 <cgemv_n+2388>       vperm   v0,v0,v0,v11                                                                                                                   │
       │0x100073c8 <cgemv_n+2392>       xvmaddmsp vs44,vs0,vs10                                                                                                                │
       │0x100073cc <cgemv_n+2396>       xvmaddmsp vs45,vs0,vs11    
    
    

    gcc-7

       lxvd2x  vs43,r7,r9                                                                                                                     │
       │0x10006bf4 <cgemv_n+1860>       lxvd2x  vs33,r7,r10                                                                                                                    │
      >│0x10006bf8 <cgemv_n+1864>       lxvd2x  vs44,r8,r9                                                                                                                     │
       │0x10006bfc <cgemv_n+1868>       lxvd2x  vs32,r8,r10                                                                                                                    │
       │0x10006c00 <cgemv_n+1872>       lxvd2x  vs0,r31,r10                                                                                                                    │
       │0x10006c04 <cgemv_n+1876>       lxvd2x  vs10,r31,r9                                                                                                                    │
       │0x10006c08 <cgemv_n+1880>       xxswapd vs43,vs43                                                                                                                      │
       │0x10006c0c <cgemv_n+1884>       xxswapd vs33,vs33                                                                                                                      │
       │0x10006c10 <cgemv_n+1888>       xxswapd vs44,vs44                                                                                                                      │
       │0x10006c14 <cgemv_n+1892>       xxswapd vs32,vs32                                                                                                                      │
       │0x10006c18 <cgemv_n+1896>       xvmulsp vs11,vs7,vs33                                                                                                                  │
       │0x10006c1c <cgemv_n+1900>       xvmulsp vs9,vs7,vs43                                                                                                                   │
       │0x10006c20 <cgemv_n+1904>       vperm   v10,v12,v12,v9                                                                                                                 │
       │0x10006c24 <cgemv_n+1908>       vperm   v13,v0,v0,v9                                                                                                                   │
       │0x10006c28 <cgemv_n+1912>       vperm   v11,v11,v11,v9
    
  23. quickwritereader commented on Aug 29, 2019

    @quickwritereader
    Contributor

    gcc-8 doing good work getting rid of unnecessary xxswapd but using lvx (MEM & 0xFFFFFF...F0) instructor for loads mostly. but gcc-7 is using lxv (x as the second letter) most times avoiding lvx (v in the middle)

    Here is a simple command to check assemblies

    cd kernel/ && gcc-7 -S -Ofast -mcpu=power8 -mtune=power8 -mvsx -malign-power -DUSE_OPENMP -fno-fast-math -fopenmp -g -DMAX_STACK_ALLOC=2048 -fopenmp -Wall -m64 -DF_INTERFACE_GFORT -fPIC -DNO_LAPACK -DNO_LAPACKE -DSMP_SERVER -DUSE_OPENMP -DNO_WARMUP -DMAX_CPU_NUMBER=2 -DMAX_PARALLEL_NUMBER=1 -DVERSION=\"0.3.8.dev\" -DASMNAME=cgemv_s -DASMFNAME=cgemv_s_ -DNAME=cgemv_s_ -DCNAME=cgemv_s -DCHAR_NAME=\"cgemv_s_\" -DCHAR_CNAME=\"cgemv_s\" -DNO_AFFINITY -I.. -UDOUBLE  -DCOMPLEX -UDOUBLE -DCOMPLEX -UTRANS -DCONJ -DXCONJ ../kernel/power/cgemv_n.c -o ../cgcc-7_cgemv.S && cd ..
    
    cd kernel/ && gcc-8 -S -Ofast -mcpu=power8 -mtune=power8 -mvsx -malign-power -DUSE_OPENMP -fno-fast-math -fopenmp -g -DMAX_STACK_ALLOC=2048 -fopenmp -Wall -m64 -DF_INTERFACE_GFORT -fPIC -DNO_LAPACK -DNO_LAPACKE -DSMP_SERVER -DUSE_OPENMP -DNO_WARMUP -DMAX_CPU_NUMBER=2 -DMAX_PARALLEL_NUMBER=1 -DVERSION=\"0.3.8.dev\" -DASMNAME=cgemv_s -DASMFNAME=cgemv_s_ -DNAME=cgemv_s_ -DCNAME=cgemv_s -DCHAR_NAME=\"cgemv_s_\" -DCHAR_CNAME=\"cgemv_s\" -DNO_AFFINITY -I.. -UDOUBLE  -DCOMPLEX -UDOUBLE -DCOMPLEX -UTRANS -DCONJ -DXCONJ ../kernel/power/cgemv_n.c -o ../cgcc-8_cgemv.S && cd ..
    
  24. martin-frbg commented on Aug 29, 2019

    @martin-frbg
    Collaborator

    The change in gcc behaviour could be related to this patch https://www.mail-archive.com/gcc-patches@gcc.gnu.org/msg182366.html

  25. quickwritereader commented on Aug 29, 2019

    @quickwritereader
    Contributor

    I see.
    On power8 and power9 unaligned load store vsx pairs preferred. But they went on with old instructions.
    On power9 there are even new load store pairs with immediate offset support but big endian.
    It's hard to track pairs and endianess. if you mixes pairs you can end swapped answers.

    So should we provide some hint or fix?

    I think it is possible to check address and compute missed result for blas1 .
    And the same could be applied to cgemv.
    Other option is to switch to inline assembly for loads.
    Ironically I wrote vector code to make porting easier.

    gcc-8 ,incorrectly, using aligned  
    
    memory vector codes over  0x....8
     
    address that 8byte aligned.
    
  26. martin-frbg commented on Aug 29, 2019

    @martin-frbg
    Collaborator

    Not sure I follow you, but wouldn't any "check address and compute missed result" be more expensive than disabling over-enthusiastic optimization ? (As I understand it, there is no simple way in C to require a specific alignment like the .align or .p2align does in assembly)

  27. quickwritereader commented on Aug 29, 2019

    @quickwritereader
    Contributor

    yes I still have to add align options to internal buffers and swap_mask as default always choose data type size. It still can fail tests as passed cgemv matrix pointer by user is default aligned.

    Possible solution. static const char __attribute__((aligned(16))) swap_mask_arr[]={,,} with pure assembly I would use constant loading, anyway
    Alignment did not work. I will recheck ,later.

  28. quickwritereader commented on Aug 30, 2019

    @quickwritereader
    Contributor

    cgemv_n cgemv_t caxpy and cdot were re-written explicitly with vec_vsx_ld so that GCC used new load/store instructions.

  29. martin-frbg commented on Aug 30, 2019

    @martin-frbg
    Collaborator

    Fixed by quickwritereader's PR #2243

  30. added this to the 0.3.8 milestone on Aug 30, 2019
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