Intel® oneAPI Math Kernel Library
Intel® oneAPI Math Kernel Library (oneMKL) is a highly optimized, extensively threaded, and vectorized numerical library for mathematical functions. It provides a wide range of routines for linear algebra (BLAS, LAPACK, ScaLAPACK), fast Fourier transforms (FFT), vector math, and more. When used with Python libraries like NumPy and SciPy, it significantly accelerates numerical computations by providing highly optimized CPU-specific implementations. The `mkl` PyPI package, version 2025.3.1, typically provides the runtime components required for other Python packages to link against and utilize MKL, with updates usually following major oneAPI releases.
Warnings
- gotcha MKL can conflict with other BLAS/LAPACK implementations (e.g., OpenBLAS, BLIS) if multiple are installed or linked incorrectly. This can lead to unexpected performance, crashes, or incorrect results.
- gotcha It's common for users to `pip install mkl` but not verify that their numerical libraries (NumPy, SciPy) are actually using MKL, leading to no performance gains. MKL needs to be correctly linked by these libraries.
- gotcha The `mkl` package on PyPI provides MKL runtime components, but system-wide MKL installations (e.g., via Intel oneAPI base toolkit) or Conda environments with `mkl` (e.g., `conda install numpy scipy mkl`) can also provide MKL. Mixing these can lead to conflicts, library loading issues, or unstable behavior.
Install
-
pip install mkl
Imports
- get_version
import mkl; mkl.get_version()
- get_mkl_info
import mkl.service; mkl.service.get_mkl_info()
Quickstart
import mkl
import numpy as np
print("MKL Python package version:", mkl.get_version())
print("\nMKL Service info:")
print(mkl.service.get_mkl_info())
# Verify if NumPy is using MKL
print("\nNumPy configuration (look for 'mkl' or 'blas_mkl'):")
np.__config__.show()
# Perform a simple matrix multiplication which should be accelerated by MKL
a = np.random.rand(1000, 1000)
b = np.random.rand(1000, 1000)
print("\nPerforming a matrix multiplication (1000x1000) with NumPy...")
_ = a @ b
print("Operation complete. Check NumPy config above to see MKL linkage.")