Entry point for agent context in this repo.
mkl_umath exposes Intel® OneMKL-powered universal function loops for NumPy, originally part of Intel® Distribution for Python* and factored out per NEP-36 (Fair Play).
It provides:
mkl_umath._ufuncs— OneMKL-backed NumPy ufunc loopsmkl_umath._patch_numpy— runtime patching interface (patch_numpy_umathrestore_numpy_umath,is_patched())- Performance-optimized math operations (sin, cos, exp, log, etc.) using Intel MKL VM
- Python interface:
mkl_umath/__init__.py,_init_helper.py - Core C implementation:
mkl_umath/src/(ufuncsmodule.c, mkl_umath_loops.c.src) - Cython patch layer:
mkl_umath/src/_patch_numpy.pyx - Code generation:
generate_umath.py,generate_umath_doc.py - Build system: CMake (CMakeLists.txt) + scikit-build
Required:
- Compiler toolchain: Intel
icxorclang(with Intel-only flags gated when using clang) - Intel® OneMKL (mkl-devel)
- NumPy, Cython, scikit-build, cmake, ninja
Conda environment:
conda install -c https://software.repos.intel.com/python/conda \
mkl-devel dpcpp_linux-64 numpy-base \
cmake ninja cython scikit-build
export MKLROOT=$CONDA_PREFIX
CC=${CC:-icx} pip install --no-build-isolation --no-deps . # clang is also supported in CI- Platforms: Linux, Windows
- Python versions: 3.10, 3.11, 3.12, 3.13, 3.14
- Workflows:
.github/workflows/conda-package.yml— main build/test pipelinebuild_pip.yaml— PyPI wheel buildsbuild-with-clang.yml— Clang compatibility checkopenssf-scorecard.yml— security scorecard
- Conda:
https://software.repos.intel.com/python/conda - PyPI:
https://software.repos.intel.com/python/pypi - Requires Intel-optimized NumPy from Intel channels
import mkl_umath
mkl_umath.patch_numpy_umath() # Patch NumPy to use MKL loops
# ... perform NumPy operations (now accelerated) ...
mkl_umath.restore_numpy_umath() # Restore original NumPy loops- Performance: Changes should maintain or improve MKL VM utilization
- Compatibility: Must work with upstream NumPy APIs (NEP-36 compliance)
- Testing: Add tests to
mkl_umath/tests/test_basic.py - Build hygiene: CMake changes → verify Linux + Windows
- Docs: Update docstrings via
ufunc_docstrings_numpy{1,2}.py
- Generated code:
*.srcfiles are templates (conv_template.py processes them) - Precision flags: fp:precise, fimf-precision=high, fprotect-parens (non-negotiable)
- Security: Stack protection, FORTIFY_SOURCE, NX/DEP enforced in CMake
- NumPy source: Requires Intel-optimized NumPy from Intel channel (
software.repos.intel.com/python/conda). PyPI NumPy may cause runtime failures or incorrect results. - Precision flags:
fp:precise,fimf-precision=highenforce IEEE 754 compliance. Removing them breaks numerical correctness in scientific computing. - Patching order: If using multiple Intel patches (e.g.,
mkl_random+mkl_umath), applymkl_umathlast. Verify withis_patched()after each. - Compiler/toolchain:
icxandclangare both supported; when using clang, keep Intel-only flags behind compiler guards. - Build validation:
- After setup:
which ${CC:-icx}→ should resolve to the intended compiler toolchain - Verify:
echo $MKLROOT→ should be set - Check:
python -c "import numpy; print(numpy.__version__)"→ confirm Intel NumPy
- After setup:
_vendored/contains vendored NumPy code generation utilities- Version in
mkl_umath/_version.py(dynamic via setuptools) - Patching is runtime-only; no NumPy source modification
Below directories have local AGENTS.md for deeper context:
.github/AGENTS.md— CI/CD workflows and automationmkl_umath/AGENTS.md— Python API and code generationmkl_umath/src/AGENTS.md— C/Cython implementation layermkl_umath/tests/AGENTS.md— unit tests and validationconda-recipe/AGENTS.md— Intel channel conda packagingconda-recipe-cf/AGENTS.md— conda-forge compatible recipe_vendored/AGENTS.md— vendored NumPy utilities
For broader IntelPython ecosystem context, see:
dpnp(Data Parallel NumPy)mkl_random(MKL-based random number generation)numba-dpex(Numba + SYCL)