From e7e56d9941a9a30c65f15ea82da145ad05fc8a4d Mon Sep 17 00:00:00 2001 From: vchamarthi Date: Fri, 5 Jun 2026 10:41:30 -0500 Subject: [PATCH 1/2] Add requirements.txt, add missing patch, and minor updates --- benchmarks/asv.conf.json | 2 +- benchmarks/benchmarks/__init__.py | 5 +++ benchmarks/benchmarks/_patch_setup.py | 65 +++++++++++++++++++++++++++ benchmarks/requirements.txt | 2 + 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 benchmarks/benchmarks/_patch_setup.py create mode 100644 benchmarks/requirements.txt diff --git a/benchmarks/asv.conf.json b/benchmarks/asv.conf.json index 1e26be0d..19c9771c 100644 --- a/benchmarks/asv.conf.json +++ b/benchmarks/asv.conf.json @@ -19,6 +19,6 @@ "build_cache_size": 2, "default_benchmark_timeout": 500, "regressions_thresholds": { - ".*": 0.3 + ".*": 0.2 } } diff --git a/benchmarks/benchmarks/__init__.py b/benchmarks/benchmarks/__init__.py index 9b89c10b..556c4d9c 100644 --- a/benchmarks/benchmarks/__init__.py +++ b/benchmarks/benchmarks/__init__.py @@ -4,6 +4,8 @@ import psutil +from ._patch_setup import _apply_patches + _MIN_THREADS = 4 # minimum physical cores required for multi-threaded mode @@ -19,3 +21,6 @@ def _thread_count(): _THREADS = os.environ.get("MKL_NUM_THREADS", _thread_count()) os.environ["MKL_NUM_THREADS"] = _THREADS + +_apply_patches() +del _apply_patches diff --git a/benchmarks/benchmarks/_patch_setup.py b/benchmarks/benchmarks/_patch_setup.py new file mode 100644 index 00000000..cc3dfe42 --- /dev/null +++ b/benchmarks/benchmarks/_patch_setup.py @@ -0,0 +1,65 @@ +"""MKL patch setup — executed once per ASV worker process at import time. + +Patches NumPy FFT with the Intel MKL FFT implementation. +Hard-fails with a descriptive RuntimeError if mkl_fft is missing or the +patch does not take effect, so benchmarks never silently run on stock NumPy. +""" + +_PATCH_MAP = [ + ("mkl_fft", "patch_numpy_fft"), +] + + +def _apply_patches(): + import numpy as np + + patched = {} + + for mod_name, patch_fn_name in _PATCH_MAP: + try: + mod = __import__(mod_name) + except ImportError as exc: + raise RuntimeError( + f"[mkl-patch] Cannot import {mod_name}: {exc}\n" + f" Ensure the conda env contains {mod_name} " + f"from the Intel channel.\n" + " Required channels: " + "https://software.repos.intel.com/python/conda" + ) from exc + + patch_fn = getattr(mod, patch_fn_name, None) + if patch_fn is None: + raise RuntimeError( + f"[mkl-patch] {mod_name} has no {patch_fn_name}(). " + f"Upgrade {mod_name} to a version that exposes " + "the stock-numpy patch API." + ) + + try: + patch_fn() + except Exception as exc: + raise RuntimeError( + f"[mkl-patch] {mod_name}.{patch_fn_name}() raised: {exc!r}" + ) from exc + + is_patched_fn = getattr(mod, "is_patched", None) + if callable(is_patched_fn) and not is_patched_fn(): + raise RuntimeError( + f"[mkl-patch] {mod_name}.is_patched() returned False " + "after patching. NumPy may have been imported before " + "patching in a conflicting state." + ) + + patched[mod_name] = mod + + _attr_checks = { + "mkl_fft": lambda: np.fft.fft.__module__, + } + for mod_name in patched: + try: + attr = _attr_checks[mod_name]() + except Exception: + attr = "unknown" + print(f"[mkl-patch] {mod_name}: numpy.fft dispatch -> {attr}") + + print("[mkl-patch] ALL OK -- mkl_fft active") diff --git a/benchmarks/requirements.txt b/benchmarks/requirements.txt new file mode 100644 index 00000000..04566f48 --- /dev/null +++ b/benchmarks/requirements.txt @@ -0,0 +1,2 @@ +psutil +scipy From 34faf270c028fb8830d21ef032289177f53fe225 Mon Sep 17 00:00:00 2001 From: vchamarthi Date: Fri, 5 Jun 2026 11:10:48 -0500 Subject: [PATCH 2/2] Minor copilot fixes --- benchmarks/benchmarks/_patch_setup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/benchmarks/benchmarks/_patch_setup.py b/benchmarks/benchmarks/_patch_setup.py index cc3dfe42..54f02ca2 100644 --- a/benchmarks/benchmarks/_patch_setup.py +++ b/benchmarks/benchmarks/_patch_setup.py @@ -11,13 +11,15 @@ def _apply_patches(): + import importlib + import numpy as np patched = {} for mod_name, patch_fn_name in _PATCH_MAP: try: - mod = __import__(mod_name) + mod = importlib.import_module(mod_name) except ImportError as exc: raise RuntimeError( f"[mkl-patch] Cannot import {mod_name}: {exc}\n"