JuliaLinearAlgebra / AppleAccelerate.jl

Julia interface to the macOS Accelerate framework
Other
96 stars 18 forks source link

Fixes for macos 11 and later (Big Sur onwards, including current Monterey) #43

Closed daviehh closed 1 year ago

daviehh commented 2 years ago

Attempting to fix https://github.com/JuliaMath/AppleAccelerate.jl/issues/42: starting with Big Sur, release note, esp. 62986286, the system libraries are now removed to a cache and the corresponding dylib/frameworks used here are now no longer working: right now, using this package fails with

ERROR: LoadError: Accelerate framework not found at /System/Library/Frameworks/Accelerate.framework/Accelerate

This changes ccall to use function handle provided dlopen and dlsym.

Alternatively, just commenting out https://github.com/JuliaMath/AppleAccelerate.jl/blob/1767883f594f25024cd41d46abe912611e8d0ce5/src/AppleAccelerate.jl#L6-L8

also works

mcabbott commented 2 years ago

Does this work locally, and on what machine?

I was hoping it might fix things on M1, but it does not seem to:

julia> AppleAccelerate.exp!(rand(100), rand(100))
ERROR: could not load symbol "vvexp":
invalid handle passed to dlsym()
Stacktrace:
 [1] dlsym(hnd::Ptr{Nothing}, s::String; throw_error::Bool)
   @ Base.Libc.Libdl ./libdl.jl:59
 [2] dlsym
   @ ./libdl.jl:57 [inlined]
 [3] get_fptr
   @ ~/.julia/packages/AppleAccelerate/VdzWL/src/AppleAccelerate.jl:12 [inlined]
 [4] exp!(out::Vector{Float64}, X::Vector{Float64})
   @ AppleAccelerate ~/.julia/packages/AppleAccelerate/VdzWL/src/Array.jl:30

julia> versioninfo()
Julia Version 1.8.0-DEV.1063
Commit aeab8a2a16 (2021-11-24 18:46 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin20.6.0)
  CPU: Apple M1
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, cyclone)
daviehh commented 2 years ago

@mcabbott I've tested this locally on julia 1.7.0 official lease binaries, both the native m1 and the intel running over rosetta works,

image

and ]test also passed

image

tested on macbook pro 14", macos 12.0.1 if this matters.

Incidentally, what does AppleAccelerate.libacc return on your end? And dlsym(AppleAccelerate.libacc, "vvexp") or dlsym(AppleAccelerate.libacc, :vvexp)

mcabbott commented 2 years ago

Ah that's great. These commands give me:

julia> AppleAccelerate.libacc
Ptr{Nothing} @0x00000001548093e0

julia> AppleAccelerate.dlsym(AppleAccelerate.libacc, "vvexp")
ERROR: could not load symbol "vvexp":
invalid handle passed to dlsym()
Stacktrace:
 [1] dlsym(hnd::Ptr{Nothing}, s::String; throw_error::Bool)
   @ Base.Libc.Libdl ./libdl.jl:59
 [2] dlsym(hnd::Ptr{Nothing}, s::String)
   @ Base.Libc.Libdl ./libdl.jl:57
 [3] top-level scope
   @ REPL[13]:1

julia> AppleAccelerate.dlsym(AppleAccelerate.libacc, :vvexp)
ERROR: could not load symbol "vvexp":

This is a 13" macbook pro with Big Sur 11.6.1. I will try with the official 1.7 in a bit. Same results from the official 1.7 binary. Perhaps the MacOS version matters?

mcabbott commented 2 years ago

I tried this again, M1 with MacOS 12.0.1, Julia 1.9.0-DEV.357, and now it seems to work.

However, the things I tried seem substantially slower than Julia's: because they were too small, I think.

# 1 thousand:

julia> @btime AppleAccelerate.log!($(rand(1000)), $(rand(1000)));
  8.472 μs (0 allocations: 0 bytes)

julia> @btime $(rand(1000)) .= log.($(rand(1000)));
  4.500 μs (0 allocations: 0 bytes)

# 1 million:

julia> @btime AppleAccelerate.log!($(rand(10^6)), $(rand(10^6)));
  1.519 ms (0 allocations: 0 bytes)

julia> @btime $(rand(10^6)) .= log.($(rand(10^6)));
  4.706 ms (0 allocations: 0 bytes)