Skip to content

Load MKL only from the environment bartorch is installed in - #155

Merged
mcencini merged 1 commit into
mainfrom
claude/finufft-avx2-crash-kcx6w7
Oct 19, 2026
Merged

mcencini merged 1 commit into
mainfrom
claude/finufft-avx2-crash-kcx6w7

Conversation

@mcencini

Copy link
Copy Markdown
Collaborator

Requested by Matteo · project thread

Before: in a venv made from an Anaconda Python, bartorch loaded the base interpreter's libmkl_rt.so.2 (oneAPI MKL 2023.1) although the venv never installed MKL, and FINUFFT/BLAS calls died with SIGILL or a segmentation fault on an AVX2-only i7-13700H. Precedence between roots followed the path string, so a venv under /workspace would pick the base MKL even with its own mkl wheel.

After: _mkl_library() searches sys.prefix, then the install data path, in that order, and never sys.base_prefix. Without an MKL in the environment, bartorch falls back to torch's BLAS / SciPy as it does elsewhere.

How: one ordered root list in _backend._mkl_library, plus two tests that fake a base interpreter carrying MKL and an environment whose data path sorts first.

The FINUFFT CPU dispatch itself was checked in an earlier thread (emulated AVX2-only CPU picks the v3 module and runs linop.NUFFT), so no build change is needed.

Fixes #149


Generated by Claude Code

A virtual environment made from an interpreter that carries its own MKL
(an Anaconda base, for instance) loaded that MKL even though the venv never
installed it, and an old one crashes FINUFFT and BLAS calls with SIGILL or
a segmentation fault. sys.base_prefix is no longer searched, and sys.prefix
is searched before the install data path rather than in path-string order.

Fixes #149

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MVoFBs7CDGDmiw1VFRD22
@mcencini mcencini self-assigned this Oct 19, 2026
@mcencini
mcencini merged commit cf1b470 into main Oct 19, 2026
17 checks passed
@codecov

codecov Bot commented Oct 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

Successfully merging this pull request may close these issues.

_mkl_library loads the base interpreter's MKL into a virtual environment

2 participants