Repository navigation
Description
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
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
kavanabhat commentedon Jun 19, 2019
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
martin-frbg commentedon Jun 19, 2019
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 #1997kavanabhat commentedon Jun 19, 2019
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.
martin-frbg commentedon Jun 19, 2019
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)
martin-frbg commentedon Jun 19, 2019
Thanks for the fix. So it was essentially a stray line, somehow duplicated from the code I was editing.☹️
Merge pull request #2167 from kavanabhat/dtrmm_power8_segfault
quickwritereader commentedon Jun 20, 2019
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
rguenth commentedon Apr 17, 2025
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
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;
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.
quickwritereader commentedon Apr 17, 2025
what compilers are used?. Are using Ibm ones?
I will try to check the issue. Long time, I did not touch this
rguenth commentedon Apr 17, 2025
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.
quickwritereader commentedon Apr 17, 2025
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)
20 remaining items
quickwritereader commentedon Apr 17, 2025
nope, did not work for me in compiler explorer. https://godbolt.org/z/4neT6jnvc.@martin-frbg should we write inline assembly.
quickwritereader commentedon Apr 17, 2025
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
martin-frbg commentedon Apr 17, 2025
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
quickwritereader commentedon Apr 17, 2025
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.
quickwritereader commentedon Apr 17, 2025
Here is the forced unaligned version using helper with inline assemblyhttps://godbolt.org/z/c6n8bj1fYquickwritereader commentedon Apr 17, 2025
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.
quickwritereader commentedon Apr 17, 2025
This version should produce better assembly imho
for
unalinged loadsquickwritereader commentedon Apr 17, 2025
@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
quickwritereader commentedon Apr 17, 2025
Just for notes:lvx - loads unaligned--aligned ones-- (better for performance, used inside gemm)~lxv - loads aligned ~
lxvd2x - loads alignedvec_vsx_ld - loads alignedno builtins for unaligned. We use inline assembly helperIBM's gcc can correctly picks unaligned instructionsOrdinary gcc picks aligned instruction usually, though there were not any hint.Possible solutions:A) force unalignedB) check what buffers can come unaligned, and manually align and correctfor now we went with variant Aquickwritereader commentedon Apr 17, 2025
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
quickwritereader commentedon Apr 17, 2025
@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
quickwritereader commentedon Apr 17, 2025
@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/ofh6rY5Knn should be <n; i+=4it'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)
quickwritereader commentedon Apr 17, 2025
so gcc version 8.3 was compiling it using unaligned loads.
@rguenth could you try above unaligned loads. and see if it fixes.
quickwritereader commentedon Apr 17, 2025
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
quickwritereader commentedon Apr 18, 2025
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