Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reliable segfault with >4d array #993

Closed
timholy opened this issue Jun 29, 2012 · 12 comments
Closed

Reliable segfault with >4d array #993

timholy opened this issue Jun 29, 2012 · 12 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@timholy
Copy link
Member

timholy commented Jun 29, 2012

At commit 850109e, changing to the "test" directory and running load("arrayperf.jl") causes a reliable segfault.

@timholy
Copy link
Member Author

timholy commented Jun 29, 2012

This is curious: the fault turns out to be in rand!:

julia> A = randn(4,4,4,4,4);

julia> A = zeros(4,4,4,4,4);

julia> A = rand(4,4,4,16);

julia> A = rand(4,4,4,4,4);
Segmentation fault (core dumped)

What's really weird about it is that the last two lines have the same number of elements. To make matters even stranger:
julia> A = zeros(4,4,4,4,4);

julia> A = reshape(A,4,4,4,16);

julia> size(A)
(4,4,4,16)

julia> rand!(A);
Segmentation fault (core dumped)

But this is not just dumb luck that it segfaulted this time, because I can call rand! repeatedly safely in 4 dimensions:

julia> for i = 1:1000
A = zeros(4,4,4,16)
rand!(A)
end

julia>

Very, very strange. I'm guessing there's a bug in the C-representation of the array?

@JeffBezanson
Copy link
Member

I could not reproduce this on either 32- or 64-bit linux.

@timholy
Copy link
Member Author

timholy commented Jun 29, 2012

OK. I'm building from a fresh repository now, I'll let you know what happens.

@timholy
Copy link
Member Author

timholy commented Jun 30, 2012

Still happens on a fresh clone, running it from the usr/bin/.

$ gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

$ uname -a
Linux diva 3.2.0-26-generic #41-Ubuntu SMP Thu Jun 14 17:49:24 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

Not sure what else would be helpful.

Anyone else see this? Easy to check: just do rand(4,4,4,4,4)

@JeffBezanson
Copy link
Member

Stack trace or valgrind?

@ViralBShah
Copy link
Member

Yup, segfaults for me too.

@ViralBShah
Copy link
Member

Looks like the segfault happens in the call to DSFMT.

@ViralBShah
Copy link
Member

Could the bug have to do with this?

Parameters:
dsfmt   dsfmt state vector.

array   an array where pseudorandom numbers are filled by this function. The pointer to the array must be "aligned" (namely, must be a multiple of 16) in the SIMD version, since it refers to the address of a 128-bit integer. In the standard C version, the pointer is arbitrary.

size    the number of 64-bit pseudorandom integers to be generated. size must be a multiple of 2, and greater than or equal to (SFMT_MEXP / 128) * 2.

Note:
memalign or posix_memalign is available to get aligned memory. Mac OSX doesn't have these functions, but malloc of OSX returns the pointer to the aligned memory block.

@ViralBShah
Copy link
Member

Yup - this proves it:

julia> a = Array(Float64,4,4,4,4,4);

julia> mod(int(pointer(a)), 16)
8

julia> rand!(a)
Hangs...

@JeffBezanson
Copy link
Member

OK, we should probably 16-byte align all arrays with element size >= 4. I don't know why I don't see the problem, but this explanation makes sense.

@ViralBShah
Copy link
Member

Works for me now.

@timholy
Copy link
Member Author

timholy commented Jun 30, 2012

Ditto. Nice work, gentlemen, on a subtle issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants