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

Init error on Mac M2 #290

Closed
mattsignorelli opened this issue Jan 8, 2024 · 22 comments
Closed

Init error on Mac M2 #290

mattsignorelli opened this issue Jan 8, 2024 · 22 comments

Comments

@mattsignorelli
Copy link

Running on Mac arm64, Julia v1.10, here is the full output:

julia> using FFTW
ERROR: InitError: could not load symbol "fftw_init_threads":
dlsym(0x85691410, fftw_init_threads): symbol not found
Stacktrace:
  [1] fftw_init_threads
    @ FFTW ~/.julia/packages/FFTW/ToovV/src/providers.jl:69 [inlined]
  [2] __init__()
    @ FFTW ~/.julia/packages/FFTW/ToovV/src/FFTW.jl:32
  [3] run_module_init(mod::Module, i::Int64)
    @ Base ./loading.jl:1128
  [4] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)
    @ Base ./loading.jl:1116
  [5] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any})
    @ Base ./loading.jl:1061
  [6] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128)
    @ Base ./loading.jl:1575
  [7] _require(pkg::Base.PkgId, env::String)
    @ Base ./loading.jl:1932
  [8] __require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:1806
  [9] #invoke_in_world#3
    @ Base ./essentials.jl:921 [inlined]
 [10] invoke_in_world
    @ Base ./essentials.jl:918 [inlined]
 [11] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:1797
 [12] macro expansion
    @ Base ./loading.jl:1784 [inlined]
 [13] macro expansion
    @ Base ./lock.jl:267 [inlined]
 [14] __require(into::Module, mod::Symbol)
    @ Base ./loading.jl:1747
 [15] #invoke_in_world#3
    @ Base ./essentials.jl:921 [inlined]
 [16] invoke_in_world
    @ Base ./essentials.jl:918 [inlined]
 [17] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:1740
during initialization of module FFTW
@stevengj
Copy link
Member

stevengj commented Jan 8, 2024

Works for me on a fresh install:

julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39b (2023-12-25 18:01 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 8 × Apple M1 Pro
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
  Threads: 1 on 6 virtual cores
Environment:
  JULIA_EDITOR = code
  JULIA_CXX_RTTI = 1

@giordano
Copy link
Member

giordano commented Jan 8, 2024

What's the output of

]st -m FFTW_jll FFTW

?

@mattsignorelli
Copy link
Author

(@v1.10) pkg>  st -m FFTW_jll FFTW
Status `~/.julia/environments/v1.10/Manifest.toml`
  [7a1cc6ca] FFTW v1.7.2
  [f5851436] FFTW_jll v3.3.10+0

@mattsignorelli
Copy link
Author

Here is what I get for grepping for fftw_init_threads from an nm on libfftw3.dylib in the artifact

 nm libfftw3.dylib | grep fftw_init_threads
00000000000db1e4 T _dfftw_init_threads_
00000000000db230 T _dfftw_init_threads__
00000000000d8a38 T _fftw_init_threads

So it seems like the symbol is there

@mattsignorelli
Copy link
Author

This is very strange... I wrote a C code mimicking the Julia and dlsym finds a lot of the symbols in FFTW, except it appears all of those involving threads. So that may be a clue

@mattsignorelli
Copy link
Author

Not sure if it helps but

julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39b (2023-12-25 18:01 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 24 × Apple M2 Ultra
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
  Threads: 1 on 16 virtual cores

@mattsignorelli
Copy link
Author

I completely deleted Julia, deleted .julia, reinstalled, and am getting the same error.

@mattsignorelli mattsignorelli changed the title Init error on Mac Init error on Mac M2 Jan 10, 2024
@mattsignorelli
Copy link
Author

I've narrowed down the problem to the --with-combined-threads flag in the compile, which is used in the build_tarballs.jl. This flag compiles everything into one library, instead of having a separate fftw_threads library to link to (see https://www.fftw.org/fftw3_doc/Installation-on-Unix.html). When I don't use this flag, and dlsym the symbol fftw_init_threads from the separate library generated libfftw3_threads.dylib, I can successfully load the symbol into Julia.

@stevengj
Copy link
Member

Weird that I am running on almost the same arch, with the same Julia and package versions, and I can't reproduce…

@giordano
Copy link
Member

I also couldn't reproduce on M1.

@giordano
Copy link
Member

@mattsignorelli what version of macOS are you using? I think I was on 12.6 (I don't have my macbook at hand right now).

@mattsignorelli
Copy link
Author

@giordano I'm on 14.2

@giordano
Copy link
Member

There's probably something weird in macOS 14, other projects had problems as well, for example neovim/neovim#25274 (pointed out by @mkitti). Frankly it looks odd to me that having everything in a single shared library is a problem.

@xlxs4
Copy link

xlxs4 commented Jan 10, 2024

Couldn't reproduce on fresh environment, M2 Pro, Sonoma 14.3

julia> using FFTW

julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39b (2023-12-25 18:01 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 10 × Apple M2 Pro
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
  Threads: 1 on 6 virtual cores

(bug) pkg> st -m FFTW_jll FFTW
Status `~/bug/Manifest.toml`
  [7a1cc6ca] FFTW v1.7.2
  [f5851436] FFTW_jll v3.3.10+0

@mattsignorelli
Copy link
Author

mattsignorelli commented Jan 10, 2024

There's probably something weird in macOS 14, other projects had problems as well, for example neovim/neovim#25274 (pointed out by @mkitti). Frankly it looks odd to me that having everything in a single shared library is a problem.

This seems to be the problem. If I run ../configure $FLAGS LDFLAGS="-Wl,-export_dynamic" , I can successfully dlsym fftw_init_threads in Julia.

@StefanKarpinski
Copy link
Contributor

Just as a data point, I'm on MacOS 14.2.1 on an M2 system and I can't repro this using Julia 1.10.0 and the exact same versions of FFTW and FFTW_jll. How did you install Julia?

@brenhinkeller
Copy link

brenhinkeller commented Jan 10, 2024

Looks ok here on macOS 13.5.1 (22G90)

   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.0 (2023-12-25)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

(@v1.10) pkg> add FFTW
   Resolving package versions...
    Updating `~/.julia/environments/v1.10/Project.toml`
  [7a1cc6ca] + FFTW v1.7.2
  No Changes to `~/.julia/environments/v1.10/Manifest.toml`

julia> using FFTW

julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39b (2023-12-25 18:01 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 10 × Apple M1 Max
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
  Threads: 1 on 8 virtual cores

@mattsignorelli
Copy link
Author

Just as a data point, I'm on MacOS 14.2.1 on an M2 system and I can't repro this using Julia 1.10.0 and the exact same versions of FFTW and FFTW_jll. How did you install Julia?

I tried with Julia v1.10 from Juliaup installed with the standard curl , and also a regular MacOS Julia install.

But right now, I am compiling the library manually outside of Julia (using the same flags in the build_tarballs.jl build script) and dlsym in even a C program is giving the result above. So for whatever reason dlsym itself is having problems finding the symbol unless the -export_dynamic flag is explicitly used.

@mattsignorelli
Copy link
Author

Ah, I have figured it out. There is a separate software in my .bash_profile which adds its own FFTW to the DYLD_LIBRARY_PATH. Adding to DYLD_LIBRARY_PATH instead of DYLD_FALLBACK_LIBRARY_PATH can cause this exact problem. It probably shouldn't be doing this. I modified it to instead add to DYLD_FALLBACK_LIBRARY_PATH and now I can do using FFTW.

Thanks for everyone's time. If someone else has a similar problem in the future with either FFTW or other common packages, this could be something to check for on Mac.

@mkitti
Copy link

mkitti commented Jan 10, 2024

We should make versioninfo() print these environment variables. I thought it did...

https://github.com/JuliaLang/julia/blob/0f7b598ad2a690cae4fe67b3f834e476a77399f4/stdlib/InteractiveUtils/src/InteractiveUtils.jl#L167

@stevengj
Copy link
Member

@mattsignorelli
Copy link
Author

Yes, I did

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

7 participants