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

Julia crash when using fft_plan #277

Open
JuhaHeiskala opened this issue Sep 8, 2023 · 4 comments
Open

Julia crash when using fft_plan #277

JuhaHeiskala opened this issue Sep 8, 2023 · 4 comments

Comments

@JuhaHeiskala
Copy link

(Filed this first in Julia issues 51249, but got directed here. My gut feeling was that Julia gives invalid memory to FFTW)

Julia 1.9.3 installed from Generic linux package on Ubuntu 22.04 system.

julia> versioninfo()
Julia Version 1.9.3
Commit bed2cd540a1 (2023-08-24 14:43 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 32 × AMD Ryzen 9 7950X 16-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, znver3)
  Threads: 1 on 32 virtual cores
Environment:
  LD_LIBRARY_PATH = :/usr/local/lib

I get a crash when using the below code as a module with using Test, but not if I load the source directly in REPL include("Test.jl").

Test.jl code below
view in fft_out = fft(view(A, :, 1)) is not actually needed, also fft_plan*A[:,1] crashes. I just used the view when hit this the first time)

module Test
using FFTW

A = randn(ComplexF64, 128, 10)

fft_out = fft(view(A, :, 1))
fft_plan = plan_fft(zeros(ComplexF64, 128))

# This doesn't crash when loading the module
fft_out = fft_plan*view(A, :, 1)

function test()

  A = randn(ComplexF64, 128, 10)
  # this crashes
  f = fft_plan*view(A, :, 1)

  # this doesn't crash either loaded from REPL or as module
  # f = fft(view(A, :, 1))
end

end # module Test

I.e. below does not crash

julia> include("Test.jl")
Main.Test

julia> Test.test()
128-element Vector{ComplexF64}:
   -5.399150700691746 - 13.263908986406738im
   4.4856379107268936 + 14.76279541263508im
...

but this crashes

julia> using Test

julia> Test.test()

[532823] signal (11.1): Segmentation fault
in expression starting at REPL[2]:1
fftw_execute_dft at /home/juha/.julia/artifacts/e95ca94c82899616429924e9fdc7eccda275aa38/lib/libfftw3.so (unknown line)
unknown function (ip: 0x7fe691102216)
@giordano
Copy link
Member

giordano commented Sep 8, 2023

The plan object contains a pointer:

FFTW.jl/src/fft.jl

Lines 252 to 253 in ef8fc5b

mutable struct $P{T<:fftwNumber,K,inplace,N,G} <: FFTWPlan{T,K,inplace}
plan::PlanPtr

You can't serialise a pointer in a session and then deserialise it in another session, the old pointer is garbage in the new session, hence the segmentation fault. Please read the documentation about module loading.

@giordano giordano closed this as not planned Won't fix, can't repro, duplicate, stale Sep 8, 2023
@JuhaHeiskala
Copy link
Author

Ah, ok, thanks. Did't realize that the module variables are stored in the precompiled cache.

@giordano
Copy link
Member

giordano commented Sep 8, 2023

Global variables are, yes. You may find this blog post about what happens in top-level of Julia packages useful.

@vchuravy
Copy link

vchuravy commented Sep 8, 2023

Should FFTW check for C_NULL and provide a better error?

@vchuravy vchuravy reopened this Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants