Repository navigation
Description
Summary
On the CPU device (opencl:cpu), dpnp.matmul and other calls that go to oneMKL BLAS run 6-16x slower (median) when NumPy's BLAS in the same env is MKL (libblas=*_intelmkl); single calls take up to 35x longer. Both documented conda install commands (README "Conda" and "Installing the bleeding edge") give such an env. With MKL_THREADING_LAYER=TBB, or with NumPy on OpenBLAS, the same calls run at full speed.
Environment
- Release:
conda create -n t -c https://software.repos.intel.com/python/conda/ -c conda-forge --override-channels python=3.13 dpnpgives dpnp 0.21.0, dpctl 0.23.0, numpy 2.5.5 (conda-forge), andlibblas 3.2026.2 0_intelmkl+mkl 2026.2.1(Intel channel). - Bleeding edge: the same with
-c dppy/label/devfirst gives dpnp 0.22.0dev3, dpctl 0.24.0dev0, and the samelibblasandmkl. - Control: the bleeding-edge env with
"libblas=*=*openblas"added. - Linux (Ubuntu 24.04 and 26.04), OpenCL CPU runtime 2026.2 from the env, on an Intel Xeon Platinum 8480+ (112 cores) and on a 16-core Intel Panther Lake laptop CPU.
Reproducer
import os, statistics, time
import numpy, dpctl, dpnp
maps = open("/proc/self/maps").read()
print("MKL_THREADING_LAYER =", os.environ.get("MKL_THREADING_LAYER"))
print("loaded:", sorted({n for n in ("mkl_rt", "mkl_intel_thread", "mkl_tbb_thread", "iomp5", "openblas") if n in maps}))
q = dpctl.SyclQueue("cpu")
a = dpnp.asarray(numpy.random.default_rng(0).standard_normal((2048, 2048), dtype=numpy.float32), sycl_queue=q)
for _ in range(2):
dpnp.matmul(a, a)
q.wait()
ts = []
for _ in range(15):
t0 = time.perf_counter()
dpnp.matmul(a, a)
q.wait()
ts.append(1e3 * (time.perf_counter() - t0))
print(f"dpnp.matmul 2048x2048 float32 on {q.sycl_device.name}: median {statistics.median(ts):.1f} ms (min {min(ts):.1f}, max {max(ts):.1f})")Results
Median of 15 calls, in two separate processes per row:
| Env | Setting | Xeon 8480+ (112 cores) | Panther Lake (16 cores) |
|---|---|---|---|
0.21.0, MKL libblas |
default | 35-94 ms (single calls up to 200 ms) | 231-241 ms |
0.21.0, MKL libblas |
MKL_THREADING_LAYER=TBB |
5.9 ms | 24-31 ms |
0.21.0, MKL libblas |
KMP_BLOCKTIME=0 |
5.4-5.6 ms | 19-39 ms |
0.22.0dev3, MKL libblas |
default | 34-36 ms | 221-235 ms |
0.22.0dev3, MKL libblas |
MKL_THREADING_LAYER=TBB |
5.7-5.8 ms | 30-31 ms |
0.22.0dev3, OpenBLAS libblas |
default | 5.8-5.9 ms | 21-22 ms |
The loaded: line shows the difference:
- MKL
libblas, default:import dpnp(which imports NumPy) already loadslibmkl_rt,libmkl_intel_threadandlibiomp5, next to dpnp'slibmkl_tbb_thread. - With
MKL_THREADING_LAYER=TBB: onlylibmkl_rtandlibmkl_tbb_thread. - OpenBLAS NumPy: no
libmkl_rtat all.
Other calls:
- The oneMKL strided
trsm_batchthat dpnp uses for batcheddpnp.scipy.linalg.cho_solvebehaves the same. For float32, n = 4096 and 64 right-hand sides, one call takes 250-290 ms on the Xeon by default, against 2.2 ms withMKL_THREADING_LAYER=TBB(2.1 ms withKMP_BLOCKTIME=0). On the Panther Lake CPU it is 5.4-6.3 ms against 2.0-2.9 ms. dpnp.linalg.solve(2048 x 2048, 64 right-hand sides) was not affected: 23-27 ms on the Xeon in every env.
Likely cause
NumPy's MKL BLAS goes through libmkl_rt. When MKL_THREADING_LAYER is unset, libmkl_rt picks the Intel OpenMP threading layer, and MKL then runs dpnp's oneMKL CPU calls on that layer too, although dpnp is built against TBB threading (MKL_THREADING "tbb_thread" in CMakeLists.txt). The OpenMP threads keep spinning after each call (KMP_BLOCKTIME defaults to 200 ms) while the OpenCL CPU runtime runs the next kernels on its own TBB threads. That KMP_BLOCKTIME=0 removes most of the slowdown points that way. This is a reading of the observations above, not confirmed in MKL.
Who is affected
- Both documented conda install commands give
libblas=*_intelmkl(checked on 2026-11-24). - The GHA test jobs install with mamba and currently get conda-forge's OpenBLAS
libblas(e.g. the Linux py3.15 job of the latest masterconda-package.ymlrun), so CI doesn't show this. - In a venv with the pip install from Intel's index,
dpctl.SyclQueue("cpu")fails (no CPU device), so it can't show this either.
Possible fixes
- Set
MKL_THREADING_LAYER=TBBin an activation script of dpnp's conda package, when the user hasn't set it. Setting it insideimport dpnpwould likely come too late when NumPy was imported first, sincelibmkl_rtloads its threading layer at import (see theloaded:line). - Document the workaround (
MKL_THREADING_LAYER=TBB) in the install or performance notes.
Activity
antonwolfy commentedon Nov 25, 2026
A second way in: oneMKL VM on the CPU device, also with OpenBLAS NumPy
The OpenBLAS control above keeps
libmkl_rtout only until the first elementwise call that dpnp runs through oneMKL VM on the CPU device. At that call,libmkl_sycl_vm.so.6dlopenslibmkl_rt.so.3, andlibmkl_rtloadslibmkl_intel_threadandlibiomp5(seen withLD_DEBUG=files). A float32a - aon an 8 x 8 array is enough. The same calls on the GPU don't loadlibmkl_rt.With dpnp 0.22.0dev3 built from source, NumPy 2.5.5 with
libblas 3.11.0 *_openblas, and the OpenCL CPU runtime 2026.2, on Linux:The effect on speed was small, and it doesn't clearly come from the OpenMP layer. Each line below is one process, timing a float32
dpnp.scipy.linalg.solve_triangularfrom #3200 (one oneMKLtrsm_batchcall, n = 4096, 64 right-hand sides,check_finite=False) on the CPU device, median before and after onea - a:MKL_THREADING_LAYER=TBBSo the activation script proposed above would also keep the OpenMP layer out in this case, but it may not remove what slows the Panther Lake runs after the first VM call. Benchmarks on the CPU device should also keep in mind that a device-side residual such as
dpnp.linalg.norm(a @ x - b)makes this load, which changes the timings that follow it.