Intel® oneAPI Math Kernel Library Headers

2025.3.1 · active · verified Thu Apr 16

Intel® oneAPI Math Kernel Library (oneMKL) is a highly optimized, extensively threaded math library for high-performance computing. The `mkl-include` package provides the C and Data Parallel C++ (DPC++) programming language interfaces (header files) required for building applications and other libraries that link against oneMKL. It helps optimize numerical routines for Intel® CPUs and GPUs. The current version is 2025.3.1, with frequent releases aligning with the Intel oneAPI toolkit cadence.

Common errors

Warnings

Install

Imports

Quickstart

The `mkl-include` package itself is not directly used in Python code. Instead, it provides the necessary build-time headers for other Python libraries (like NumPy or SciPy) to be compiled and linked against the Intel oneMKL for performance acceleration. This quickstart demonstrates how to check if NumPy is utilizing MKL (e.g., via `mkl-service`) and how to use `mkl-service` for runtime control over MKL behavior within Python.

import numpy as np
import os

# --- Check if NumPy is linked against MKL (requires mkl-service or similar detection) ---
try:
    import mkl
    print(f"MKL-service is imported. MKL version: {mkl.get_version()}")
    print(f"MKL number of threads: {mkl.get_max_threads()}")
    print("NumPy is likely using MKL through the loaded mkl-service library.")
except ImportError:
    print("mkl-service not found. Checking numpy config.")

# A more direct way to check NumPy's backend (may not explicitly show MKL vs OpenBLAS, etc.)
print(f"\nNumPy config:\n{np.show_config()}")

# --- Example of using mkl-service to control MKL runtime (if installed) ---
if 'mkl' in locals():
    # Set MKL to use a specific number of threads for a domain
    mkl.set_num_threads(2)
    print(f"\nMKL threads set to: {mkl.get_max_threads()}")
    
    # Perform a computation that would benefit from MKL
    a = np.random.rand(1000, 1000)
    b = np.random.rand(1000, 1000)
    c = a @ b # Matrix multiplication, often MKL-accelerated
    print(f"Matrix multiplication completed. Shape: {c.shape}")

# To explicitly use MKL for a library like NumPy, you generally install a MKL-optimized build.
# Example (concept, exact command depends on source):
# pip install numpy scipy --index-url https://urob.github.io/numpy-mkl # For specific MKL wheels

view raw JSON →