|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +Entry point for agent context in this repo. |
| 4 | + |
| 5 | +## What this repository is |
| 6 | +`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). |
| 7 | + |
| 8 | +It provides: |
| 9 | +- `mkl_umath._ufuncs` — OneMKL-backed NumPy ufunc loops |
| 10 | +- `mkl_umath._patch` — runtime patching interface (`use_in_numpy()`, `restore()`, `is_patched()`) |
| 11 | +- Performance-optimized math operations (sin, cos, exp, log, etc.) using Intel MKL VM |
| 12 | + |
| 13 | +## Key components |
| 14 | +- **Python interface:** `mkl_umath/__init__.py`, `_init_helper.py` |
| 15 | +- **Core C implementation:** `mkl_umath/src/` (ufuncsmodule.c, mkl_umath_loops.c.src) |
| 16 | +- **Cython patch layer:** `mkl_umath/src/_patch.pyx` |
| 17 | +- **Code generation:** `generate_umath.py`, `generate_umath_doc.py` |
| 18 | +- **Build system:** CMake (CMakeLists.txt) + scikit-build |
| 19 | + |
| 20 | +## Build dependencies |
| 21 | +**Required:** |
| 22 | +- Intel® C Compiler (icx) |
| 23 | +- Intel® OneMKL (mkl-devel) |
| 24 | +- Intel® TBB (tbb-devel) |
| 25 | +- NumPy, Cython, scikit-build, cmake, ninja |
| 26 | + |
| 27 | +**Conda environment:** |
| 28 | +```bash |
| 29 | +conda install -c https://software.repos.intel.com/python/conda \ |
| 30 | + mkl-devel tbb-devel dpcpp_linux-64 numpy-base \ |
| 31 | + cmake ninja cython scikit-build |
| 32 | +export MKLROOT=$CONDA_PREFIX |
| 33 | +CC=icx pip install --no-build-isolation --no-deps . |
| 34 | +``` |
| 35 | + |
| 36 | +## CI/CD |
| 37 | +- **Platforms:** Linux, Windows |
| 38 | +- **Python versions:** 3.10, 3.11, 3.12, 3.13 |
| 39 | +- **Workflows:** `.github/workflows/` |
| 40 | + - `conda-package.yml` — main build/test pipeline |
| 41 | + - `build_pip.yaml` — PyPI wheel builds |
| 42 | + - `build-with-clang.yml` — Clang compatibility check |
| 43 | + - `openssf-scorecard.yml` — security scorecard |
| 44 | + |
| 45 | +## Distribution |
| 46 | +- **Conda:** `https://software.repos.intel.com/python/conda` |
| 47 | +- **PyPI:** `https://software.repos.intel.com/python/pypi` |
| 48 | +- Requires Intel-optimized NumPy from Intel channels |
| 49 | + |
| 50 | +## Usage |
| 51 | +```python |
| 52 | +import mkl_umath |
| 53 | +mkl_umath.use_in_numpy() # Patch NumPy to use MKL loops |
| 54 | +# ... perform NumPy operations (now accelerated) ... |
| 55 | +mkl_umath.restore() # Restore original NumPy loops |
| 56 | +``` |
| 57 | + |
| 58 | +## How to work in this repo |
| 59 | +- **Performance:** Changes should maintain or improve MKL VM utilization |
| 60 | +- **Compatibility:** Must work with upstream NumPy APIs (NEP-36 compliance) |
| 61 | +- **Testing:** Add tests to `mkl_umath/tests/test_basic.py` |
| 62 | +- **Build hygiene:** CMake changes → verify Linux + Windows |
| 63 | +- **Docs:** Update docstrings via `ufunc_docstrings_numpy{1,2}.py` |
| 64 | + |
| 65 | +## Code structure |
| 66 | +- **Generated code:** `*.src` files are templates (conv_template.py processes them) |
| 67 | +- **Precision flags:** fp:precise, fimf-precision=high, fprotect-parens (non-negotiable) |
| 68 | +- **Security:** Stack protection, FORTIFY_SOURCE, NX/DEP enforced in CMake |
| 69 | + |
| 70 | +## Notes |
| 71 | +- `_vendored/` contains vendored NumPy code generation utilities |
| 72 | +- Version in `mkl_umath/_version.py` (dynamic via setuptools) |
| 73 | +- Patching is runtime-only; no NumPy source modification |
| 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_umath/AGENTS.md` — Python API and code generation |
| 79 | +- `mkl_umath/src/AGENTS.md` — C/Cython implementation layer |
| 80 | +- `mkl_umath/tests/AGENTS.md` — unit tests and validation |
| 81 | +- `conda-recipe/AGENTS.md` — Intel channel conda packaging |
| 82 | +- `conda-recipe-cf/AGENTS.md` — conda-forge compatible recipe |
| 83 | +- `_vendored/AGENTS.md` — vendored NumPy utilities |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +For broader IntelPython ecosystem context, see: |
| 88 | +- `dpnp` (Data Parallel NumPy) |
| 89 | +- `mkl_random` (MKL-based random number generation) |
| 90 | +- `numba-dpex` (Numba + SYCL) |
0 commit comments