Skip to content

Repository files navigation

Conda package Build using pip and pre-release NumPy OpenSSF Scorecard

mkl_umath

mkl_umath._ufuncs exposes Intel® OneAPI Math Kernel Library (OneMKL) powered version of loops used in the patched version of NumPy, that used to be included in Intel® Distribution for Python*.

Patches were factored out per community feedback (NEP-36).

mkl_umath started as a part of Intel® Distribution for Python* optimizations to NumPy, and is now being released as a stand-alone package. It can be installed into conda environment using:

   conda install -c https://software.repos.intel.com/python/conda mkl_umath

To install mkl_umath PyPI package please use the following command:

   python -m pip install --index-url https://software.repos.intel.com/python/pypi --extra-index-url https://pypi.org/simple mkl_umath

If command above installs NumPy package from the PyPI, please use the following command to install Intel optimized NumPy wheel package from Intel PyPI Cloud:

   python -m pip install --index-url https://software.repos.intel.com/python/pypi --extra-index-url https://pypi.org/simple mkl_umath numpy==<numpy_version>

where <numpy_version> should be the latest version from https://software.repos.intel.com/python/conda/.


Patching Mechanisms

mkl_umath provides convenient patch methods to enable MKL-accelerated umath operations in NumPy with or without modifying your code.

CLI Quickstart

Persistent patch (all Python sessions)

# Install
python -m mkl_umath --patch install

# Status (exit code: 0 = installed, 1 = not installed)
python -m mkl_umath --patch status

# Remove
python -m mkl_umath --patch uninstall

Verify patch state

python -c "import mkl_umath; print(f'mkl_umath.is_patched(): {mkl_umath.is_patched()}')"

One-shot patch (single command only)

# Script
python -m mkl_umath --with-numpy-patch my_script.py

# Pytest
python -m mkl_umath --with-numpy-patch -m pytest tests/

# One-liner
python -m mkl_umath --with-numpy-patch -c "import mkl_umath; print(f\"mkl_umath.is_patched(): {mkl_umath.is_patched()}\")"

# Non-Python command
python -m mkl_umath --with-numpy-patch -- <command> [args...]

Programmatic Quickstart

import mkl_umath
import numpy

mkl_umath.patch_numpy_umath()
print(mkl_umath.is_patched())
# run your accelerated numpy workloads here!
mkl_umath.restore_numpy_umath()
import mkl_umath
import numpy
with mkl_umath.mkl_umath():
   # run your accelerated workloads here!
   pass

Building from source

A C compiler, Intel® oneAPI Math Kernel Library (oneMKL), and NumPy are required to build mkl_umath from source.

Executing

CC=icx python -m pip install .

will pull in the required build dependencies, including mkl-devel and numpy, and build mkl_umath.

If you already have mkl and numpy installed (from your system or a conda environment) and want to reuse them instead of pulling fresh copies into an isolated build, first install the build dependencies:

pip install meson-python ninja cmake cython numpy mkl-devel

then build against the existing installation with:

CC=icx pip install --no-build-isolation --no-deps .

About

Package implementing NumPy's UFuncs based on SVML and MKL VML

Topics

Resources

Security policy

Stars

7 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages