* [Bug middle-end/64247] program result depends on environment ?
2014-12-10 5:50 [Bug middle-end/64247] New: program result depends on environment ? Joost.VandeVondele at mat dot ethz.ch
@ 2014-12-10 12:27 ` rguenth at gcc dot gnu.org
2014-12-10 12:28 ` Joost.VandeVondele at mat dot ethz.ch
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-12-10 12:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64247
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Are you sure you are not using uninitialized memory? try using the various
-fsanitize flags (not sure if uninit memory use is in =address or =undefined).
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/64247] program result depends on environment ?
2014-12-10 5:50 [Bug middle-end/64247] New: program result depends on environment ? Joost.VandeVondele at mat dot ethz.ch
2014-12-10 12:27 ` [Bug middle-end/64247] " rguenth at gcc dot gnu.org
@ 2014-12-10 12:28 ` Joost.VandeVondele at mat dot ethz.ch
2014-12-10 12:30 ` Joost.VandeVondele at mat dot ethz.ch
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Joost.VandeVondele at mat dot ethz.ch @ 2014-12-10 12:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64247
Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |Joost.VandeVondele at mat dot ethz
| |.ch
--- Comment #2 from Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> ---
(In reply to Richard Biener from comment #1)
> Are you sure you are not using uninitialized memory? try using the various
> -fsanitize flags (not sure if uninit memory use is in =address or
> =undefined).
yes, tried that, also clean (in addition to valgrind).
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/64247] program result depends on environment ?
2014-12-10 5:50 [Bug middle-end/64247] New: program result depends on environment ? Joost.VandeVondele at mat dot ethz.ch
2014-12-10 12:27 ` [Bug middle-end/64247] " rguenth at gcc dot gnu.org
2014-12-10 12:28 ` Joost.VandeVondele at mat dot ethz.ch
@ 2014-12-10 12:30 ` Joost.VandeVondele at mat dot ethz.ch
2014-12-11 16:29 ` [Bug middle-end/64247] malloc alignment and -mavx Joost.VandeVondele at mat dot ethz.ch
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Joost.VandeVondele at mat dot ethz.ch @ 2014-12-10 12:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64247
--- Comment #3 from Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> ---
(In reply to Richard Biener from comment #1)
> Are you sure you are not using uninitialized memory? try using the various
> -fsanitize flags (not sure if uninit memory use is in =address or
> =undefined).
as a ps, uninit memory use in is neither, that would require memsan, which is
not ported to gcc.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/64247] malloc alignment and -mavx
2014-12-10 5:50 [Bug middle-end/64247] New: program result depends on environment ? Joost.VandeVondele at mat dot ethz.ch
` (2 preceding siblings ...)
2014-12-10 12:30 ` Joost.VandeVondele at mat dot ethz.ch
@ 2014-12-11 16:29 ` Joost.VandeVondele at mat dot ethz.ch
2014-12-11 19:22 ` Joost.VandeVondele at mat dot ethz.ch
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Joost.VandeVondele at mat dot ethz.ch @ 2014-12-11 16:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64247
Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|program result depends on |malloc alignment and -mavx
|environment ? |
--- Comment #4 from Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> ---
I think we isolated the issue. With -mavx the numerical results seem to depend
on the precise alignment of allocated data from malloc, i.e. 16 or 32 (..E0 or
F0) byte are not equivalent. As a result, the results from our code fluctuate
randomly from run to run. Does that make sense ?
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/64247] malloc alignment and -mavx
2014-12-10 5:50 [Bug middle-end/64247] New: program result depends on environment ? Joost.VandeVondele at mat dot ethz.ch
` (3 preceding siblings ...)
2014-12-11 16:29 ` [Bug middle-end/64247] malloc alignment and -mavx Joost.VandeVondele at mat dot ethz.ch
@ 2014-12-11 19:22 ` Joost.VandeVondele at mat dot ethz.ch
2014-12-11 20:26 ` Joost.VandeVondele at mat dot ethz.ch
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Joost.VandeVondele at mat dot ethz.ch @ 2014-12-11 19:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64247
--- Comment #5 from Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> ---
The following is a test program that illustrates the issue:
> cat test.f90
SUBROUTINE gemm(C,A,B,N)
REAL*8 :: A(N,N), B(N,N),C(N,N)
C=0
DO i=1,N
DO j=1,N
DO k=1,N
C(i,j)=C(i,j)+A(k,i)*B(k,j)
ENDDO
ENDDO
ENDDO
END SUBROUTINE
!
! simple test driver, computing the same matrix multiplication
! with the same data, but with arrays aligned differently,
! once at x, once at x+16 bytes.
! Illustrates that results will vary,
! depending randomly on what alignment malloc returns.
!
PROGRAM TEST
REAL*8, DIMENSION(:,:), POINTER, CONTIGUOUS :: A,B,C
REAL*8, DIMENSION(:), POINTER, CONTIGUOUS :: Av1,Bv1,Cv1
REAL*8, DIMENSION(:), POINTER, CONTIGUOUS :: Av2,Bv2,Cv2
REAL*8, DIMENSION(:), POINTER, CONTIGUOUS :: Av3,Bv3,Cv3
INTEGER :: N
READ(5,*) N
ALLOCATE(Av1(N*N+2),Av2(N*N+2),Bv1(N*N+2), &
Bv2(N*N+2),Cv1(N*N+2),Cv2(N*N+2))
CALL RANDOM_NUMBER(Av1)
CALL RANDOM_NUMBER(Bv1)
! try one: results as if allocated at boundary x
Av2(1:N*N)=Av1(1:N*N)
Bv2(1:N*N)=Bv1(1:N*N)
A(1:N,1:N)=>Av2(1:N*N)
B(1:N,1:N)=>Bv2(1:N*N)
C(1:N,1:N)=>Cv2(1:N*N)
CALL gemm(C,A,B,N)
Cv1(1:N*N)=Cv2(1:N*N)
! try two: results as if allocated at boundary x+16
Av2(1+2:N*N+2)=Av1(1:N*N)
Bv2(1+2:N*N+2)=Bv1(1:N*N)
A(1:N,1:N)=>Av2(1+2:N*N+2)
B(1:N,1:N)=>Bv2(1+2:N*N+2)
C(1:N,1:N)=>Cv2(1+2:N*N+2)
CALL gemm(C,A,B,N)
IF (ANY(Cv1(1:N*N).NE.Cv2(1+2:N*N+2))) CALL ABORT()
END PROGRAM TEST
> gfortran -g -march=sandybridge -mavx -O3 -ffast-math test.f90 && echo 10 | ./a.out
Program aborted. Backtrace:
#0 0x7F5C53950387
#1 0x7F5C53951A72
#2 0x7F5C53A23378
#3 0x4012D6 in test at test.f90:48
Aborted
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/64247] malloc alignment and -mavx
2014-12-10 5:50 [Bug middle-end/64247] New: program result depends on environment ? Joost.VandeVondele at mat dot ethz.ch
` (4 preceding siblings ...)
2014-12-11 19:22 ` Joost.VandeVondele at mat dot ethz.ch
@ 2014-12-11 20:26 ` Joost.VandeVondele at mat dot ethz.ch
2014-12-11 20:51 ` neleai at seznam dot cz
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Joost.VandeVondele at mat dot ethz.ch @ 2014-12-11 20:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64247
--- Comment #6 from Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> ---
some similarity with the problem discussed PR55916, except that this case
doesn't require __float128
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/64247] malloc alignment and -mavx
2014-12-10 5:50 [Bug middle-end/64247] New: program result depends on environment ? Joost.VandeVondele at mat dot ethz.ch
` (5 preceding siblings ...)
2014-12-11 20:26 ` Joost.VandeVondele at mat dot ethz.ch
@ 2014-12-11 20:51 ` neleai at seznam dot cz
2014-12-11 20:54 ` Joost.VandeVondele at mat dot ethz.ch
2014-12-11 21:18 ` Joost.VandeVondele at mat dot ethz.ch
8 siblings, 0 replies; 10+ messages in thread
From: neleai at seznam dot cz @ 2014-12-11 20:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64247
Ondrej Bilka <neleai at seznam dot cz> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |neleai at seznam dot cz
--- Comment #7 from Ondrej Bilka <neleai at seznam dot cz> ---
That looks like invalid bug. Fortran allows reassociate a+(b+c) into (a+b)+c
which give different result. You will get same instability if you compile
program with different versions of gcc.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/64247] malloc alignment and -mavx
2014-12-10 5:50 [Bug middle-end/64247] New: program result depends on environment ? Joost.VandeVondele at mat dot ethz.ch
` (6 preceding siblings ...)
2014-12-11 20:51 ` neleai at seznam dot cz
@ 2014-12-11 20:54 ` Joost.VandeVondele at mat dot ethz.ch
2014-12-11 21:18 ` Joost.VandeVondele at mat dot ethz.ch
8 siblings, 0 replies; 10+ messages in thread
From: Joost.VandeVondele at mat dot ethz.ch @ 2014-12-11 20:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64247
--- Comment #8 from Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> ---
(In reply to Ondrej Bilka from comment #7)
> That looks like invalid bug. Fortran allows reassociate a+(b+c) into (a+b)+c
> which give different result. You will get same instability if you compile
> program with different versions of gcc.
sure (well actually you mean it can evaluate a+b+c in either way, if there are
parens the order is set). However, the issue here is that the same binary will
produce different results from run to run.. that seems not OK.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/64247] malloc alignment and -mavx
2014-12-10 5:50 [Bug middle-end/64247] New: program result depends on environment ? Joost.VandeVondele at mat dot ethz.ch
` (7 preceding siblings ...)
2014-12-11 20:54 ` Joost.VandeVondele at mat dot ethz.ch
@ 2014-12-11 21:18 ` Joost.VandeVondele at mat dot ethz.ch
8 siblings, 0 replies; 10+ messages in thread
From: Joost.VandeVondele at mat dot ethz.ch @ 2014-12-11 21:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64247
--- Comment #9 from Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> ---
A variation on the testcase, to indicate how this behavior leads to conflicts
with the Fortran language standard. A routine declared 'PURE' and called with
all intent(in) arguments having the same value, returns different results.
> gfortran -g -mavx -O3 -ffast-math test.f90 && echo 8 | ./a.out
pure routine gives different results at iter: 1
pure routine gives different results at iter: 3
pure routine gives different results at iter: 5
pure routine gives different results at iter: 7
pure routine gives different results at iter: 9
> cat test.f90
MODULE M1
CONTAINS
PURE SUBROUTINE gemm(C,A,B,N)
INTEGER, INTENT(IN) :: N
REAL*8, INTENT(IN) :: A(N,N), B(N,N)
REAL*8, INTENT(OUT) :: C(N,N)
C=0
DO i=1,N
DO j=1,N
DO k=1,N
C(i,j)=C(i,j)+A(k,i)*B(k,j)
ENDDO
ENDDO
ENDDO
END SUBROUTINE gemm
END MODULE
PROGRAM TEST
USE M1
REAL*8, DIMENSION(:,:), POINTER, CONTIGUOUS :: A1,B1,C1
REAL*8, DIMENSION(:,:), POINTER, CONTIGUOUS :: A2,B2,C2
INTEGER :: N
READ(5,*) N
ALLOCATE(A1(N,N),B1(N,N),C1(N,N))
CALL RANDOM_NUMBER(A1)
CALL RANDOM_NUMBER(B1)
CALL GEMM(C1,A1,B1,N)
DO I=1,10
ALLOCATE(A2(N,N),B2(N,N),C2(N,N))
A2=A1 ; B2=B1
CALL GEMM(C2,A2,B2,N)
IF (ANY(C1.NE.C2)) THEN
WRITE(6,*) "pure routine gives different results at iter: ",i
ENDIF
ENDDO
END PROGRAM TEST
^ permalink raw reply [flat|nested] 10+ messages in thread