|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +Entry point for agent context in this repo. |
| 4 | + |
| 5 | +## What this repository is |
| 6 | +`mkl-service` provides a Python API for runtime control of Intel® oneMKL (Math Kernel Library). It exposes support functions for: |
| 7 | +- Threading control (set/get number of threads, domain-specific threading) |
| 8 | +- Version information (MKL version, build info) |
| 9 | +- Memory management (peak memory usage, memory statistics) |
| 10 | +- Conditional Numerical Reproducibility (CNR) |
| 11 | +- Timing functions (get CPU/wall clock time) |
| 12 | +- Miscellaneous utilities (MKL_VERBOSE control, etc.) |
| 13 | + |
| 14 | +Originally part of Intel® Distribution for Python*, now a standalone package available via conda-forge and Intel channels. |
| 15 | + |
| 16 | +## Key components |
| 17 | +- **Python interface:** `mkl/__init__.py` — public API surface |
| 18 | +- **Cython wrapper:** `mkl/_mkl_service.pyx` — wraps MKL support functions |
| 19 | +- **C init module:** `mkl/_mklinitmodule.c` — Linux-side MKL runtime preloading / initialization |
| 20 | +- **Helper:** `mkl/_init_helper.py` — Windows venv DLL loading helper |
| 21 | +- **Build system:** setuptools + Cython |
| 22 | + |
| 23 | +## Build dependencies |
| 24 | +**Required:** |
| 25 | +- Intel® oneMKL |
| 26 | +- Cython |
| 27 | +- Python 3.10+ |
| 28 | + |
| 29 | +**Conda environment:** |
| 30 | +```bash |
| 31 | +conda install -c conda-forge mkl-devel cython |
| 32 | +python setup.py install |
| 33 | +``` |
| 34 | + |
| 35 | +## CI/CD |
| 36 | +- **Platforms in CI workflows:** Linux, Windows |
| 37 | +- **Python versions:** 3.10, 3.11, 3.12, 3.13, 3.14 |
| 38 | +- **Workflows:** `.github/workflows/` |
| 39 | + - `conda-package.yml` — main conda build/test pipeline |
| 40 | + - `build-with-clang.yml` — Linux Clang compatibility |
| 41 | + - `pre-commit.yml` — code quality checks |
| 42 | + - `openssf-scorecard.yml` — security scanning |
| 43 | + |
| 44 | +## Distribution |
| 45 | +- **Conda:** `conda-forge` and `https://software.repos.intel.com/python/conda` |
| 46 | +- **PyPI:** `python -m pip install mkl-service` |
| 47 | + |
| 48 | +## Usage |
| 49 | +```python |
| 50 | +import mkl |
| 51 | +mkl.set_num_threads(4) # Set global thread count |
| 52 | +mkl.domain_set_num_threads(1, "fft") # FFT functions run sequentially |
| 53 | +mkl.get_version_string() # MKL version info |
| 54 | +``` |
| 55 | + |
| 56 | +## How to work in this repo |
| 57 | +- **API stability:** Preserve existing function signatures (widely used in ecosystem) |
| 58 | +- **Threading:** Changes to threading control must be thread-safe |
| 59 | +- **CNR:** Conditional Numerical Reproducibility flags require careful documentation |
| 60 | +- **Testing:** Add tests to `mkl/tests/test_mkl_service.py` |
| 61 | +- **Docs:** MKL support functions documented in [Intel oneMKL Developer Reference](https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-c/2025-2/support-functions.html) |
| 62 | + |
| 63 | +## Code structure |
| 64 | +- **Cython layer:** `_mkl_service.pyx` + `_mkl_service.pxd` (C declarations) |
| 65 | +- **C init:** `_mklinitmodule.c` handles Linux preloading (`dlopen(..., RTLD_GLOBAL)`) for MKL runtime |
| 66 | +- **Windows loading helper:** `_init_helper.py` handles DLL path setup in Windows venv |
| 67 | +- **Python wrapper:** `__init__.py` imports `_py_mkl_service` (generated from `.pyx`) |
| 68 | +- **Version:** `_version.py` (dynamic via setuptools) |
| 69 | + |
| 70 | +## Notes |
| 71 | +- RTLD_GLOBAL preloading is required on Linux (handled by `RTLD_for_MKL` context manager) |
| 72 | +- MKL must be available at runtime (conda: mkl, pip: relies on system MKL) |
| 73 | +- Threading functions affect NumPy, SciPy, and other MKL-backed libraries |
| 74 | + |
| 75 | +## Directory map |
| 76 | +Below directories have local `AGENTS.md` for deeper context: |
| 77 | +- `.github/AGENTS.md` — CI/CD workflows and automation |
| 78 | +- `mkl/AGENTS.md` — Python/Cython implementation |
| 79 | +- `mkl/tests/AGENTS.md` — unit tests |
| 80 | +- `conda-recipe/AGENTS.md` — conda packaging |
| 81 | +- `examples/AGENTS.md` — usage examples |
| 82 | + |
| 83 | +--- |
| 84 | + |
| 85 | +For broader IntelPython ecosystem context, see: |
| 86 | +- `mkl_umath` (MKL-backed NumPy ufuncs) |
| 87 | +- `mkl_random` (MKL-based random number generation) |
| 88 | +- `dpnp` (Data Parallel NumPy) |
0 commit comments