← Back to Pull requests

build(daal): include only the MKL headers DAAL calls #3903

Closed
unknown closed this pull request without merging on Oct 24, 2026 04:33 UTC
View on GitHub
unknown unknown commented on Oct 21, 2026 00:55 UTC
Author

Summary

Most of the CPU time in a DAAL compile goes to parsing headers, and most of that is MKL. Every TU that includes src/externals/config.h pulled in the whole <mkl.h> umbrella. That umbrella also brings in DFTI, PARDISO, DSS, the solvers, sparse QR and all of mkl_lapack.h, about 50k lines. DAAL calls 34 routines from it.

 src/externals/config.h -> config_mkl.h
   service_blas_mkl.h      -<mkl.h>  +<mkl_blas.h> <mkl_cblas.h> <mkl_service.h>
   service_lapack_mkl.h    -<mkl.h>  +service_lapack_decl_mkl.h <mkl_service.h>
   service_math_mkl.h      -<mkl.h>  +<mkl_vml.h> <mkl_service.h>
   service_rng_mkl.h       -<mkl.h>  +<mkl_vsl.h> <mkl_service.h>
   service_stat_mkl.h      -<mkl.h>  +<mkl_vsl.h> <mkl_service.h>
   service_spblas_mkl.h    -<mkl.h>  +<mkl_spblas.h> <mkl_service.h>
   service_service_mkl.h   -<mkl.h>  +<mkl_types.h>
+service_lapack_decl_mkl.h            # the 34 LAPACK prototypes DAAL calls, plus a list of their names
 library_version_info.cpp
   #include <mkl.h>
+  #define DAAL_CHECK_MKL_LAPACK_SUBSET
+  #include "src/externals/service_lapack_decl_mkl.h"   # drift guard

The PR has two commits, and either can be reverted on its own:
1. Per-domain MKL headers. Any missing declaration shows up as a compile error.
2. The LAPACK subset. If DAAL starts calling a new LAPACK routine, it fails to compile until one prototype line is added. If MKL changes a prototype, library_version_info.cpp sees both declarations and fails with conflicting declaration of C function. If MKL does not declare a listed name at all (a typo, or a routine MKL dropped), a static_assert there fails before the subset adds its own declaration.

Declarations generate no code, so the object files are unchanged.

Evidence

All 1550 DAAL compile actions of //cpp/daal:core_static (gcc 13.3, aquery command lines, usr+sys, best of 2, Linux 224-core box). Old and new headers were compiled side by side with the same flags. The old copy was shadowed through -iquote, with -fmacro-prefix-map so that __FILE__ matches.

| | DAAL compile CPU-s | vs main | object files vs main |
|---|---|---|---|
| main | 2409 | | |
| commit 1 (per-domain headers) | 2178 | -9.6% | 1550/1550 byte-identical |
| commit 2 (LAPACK subset) | 1906 | -20.9% | 1550/1550 byte-identical |

A single TU, zscore_dense_default_batch_fpt_cpu.cpp with -fsyntax-only: 2.67 s / 360 MB before, 1.53 s / 184 MB after. mkl_lapack.h alone takes 0.78 s / 103 MB.

The drift guard was checked by changing one parameter in the subset from const MKL_INT to MKL_INT, and by listing a name MKL does not have:

before: <mkl.h> + subset           -> compiles (-Werror, MKL_ILP64 and LP64)
after:  <mkl.h> + subset with drift -> error: conflicting declaration of C function 'void dgeqp3(...)'
name MKL does not declare (strtrsx) -> error: '::strtrsx' has not been declared

bazel test //cpp/oneapi/dal:tests --config=host: 118/118 pass.

CI wall time has not been measured yet. The 2-vCPU Azure agents are compile-bound, so about 500 CPU-s saved should mean roughly 4 min less per full DAAL build.

Merge Danger

Door: two-way

Header-only change with byte-identical objects. Reverting either commit restores the old include set.

Blast Radius: build

A compiler or MKL version that this PR's CI does not cover could still reject the subset: a Windows toolchain, or the Make build with a different MKL drop. That would show up as a compile error, not as a behaviour change. The subset uses noexcept directly rather than MKL's NOTHROW macro, so MSVC-mode __cplusplus cannot redefine it.

---

<details>
<summary>Checklist:</summary>

Completeness and readability

  • I have commented my code, particularly in hard-to-understand areas.

  • I have updated the documentation to reflect the changes or created a separate PR with updates and provided its number in the description, if necessary. _(no user-facing change)_

  • Git commit message contains an appropriate signed-off-by string _(see CONTRIBUTING.md for details)_.

  • I have resolved any merge conflicts that might occur with the base branch.
  • Testing

  • I have run it locally and tested the changes extensively.

  • All CI jobs are green or I have provided justification why they aren't.

  • I have extended testing suite if new functionality was introduced in this PR. _(no new functionality; drift guard is compile-time)_
  • Performance

  • I have measured performance for affected algorithms using scikit-learn_bench and provided at least a summary table with measured data, if performance change is expected. _(not expected: object files are byte-identical)_

  • I have provided justification why performance and/or quality metrics have changed or why changes are not expected.

  • I have extended the benchmarking suite and provided a corresponding scikit-learn_bench PR if new measurable functionality was introduced in this PR. _(n/a)_
  • </details>

    🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: ethanglaser Review duration: 4537m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3903"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%