Conversation
There was a problem hiding this comment.
Pull request overview
Fixes Julia 1.13-alpha/nightly compilation failures in src/mkl.jl by avoiding @ccall with a non-literal library expression and instead resolving MKL symbols dynamically at runtime.
Changes:
- Added
Libdldependency to enable dynamic symbol lookup. - Replaced
@ccall mkl_fullpath().…usages withdlopen/dlsym+ccallformkl_get_dynamicandmkl_set_dynamic.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| function mkl_get_dynamic() | ||
| sym = Libdl.dlsym(Libdl.dlopen(mkl_fullpath()), :mkl_get_dynamic) | ||
| ccall(sym, Cint, ()) |
There was a problem hiding this comment.
Libdl.dlopen(mkl_fullpath()) is executed on every call, and the resulting handle is never explicitly closed or cached. This can add overhead and may temporarily increase the dlopen refcount until GC runs. Consider caching the handle (e.g., a const Ref initialized once) or using the Libdl.dlopen(path) do lib ... end form to ensure timely dlclose.
| function mkl_set_dynamic(flag::Integer) | ||
| @ccall mkl_fullpath().MKL_Set_Dynamic(flag::Cint)::Cvoid | ||
| sym = Libdl.dlsym(Libdl.dlopen(mkl_fullpath()), :MKL_Set_Dynamic) | ||
| ccall(sym, Cvoid, (Cint,), flag) |
There was a problem hiding this comment.
This opens the MKL shared library and resolves the symbol on every call. To avoid repeated dlopen/dlsym work (and accumulating handles until GC), cache the dlopen handle/symbol in module-level const refs, or wrap the call in a Libdl.dlopen(...) do lib ... end block so the handle is closed immediately.
|
Superseded by #116. But thank you anyway!! |
Fixes #112
I tried various forms of
ccall()and ran into the same kinds of errors. Explicit dynamic resolution seems to work.