Skip to content

[META] scalability problems on hybrid CPUs #34128

Open

Description

@ogrisel

Warning

This issue is not yet ready for a PR. If you are interested in contributing to scikit-learn, please have a look at our contributing guidelines, and in particular the sections for new contributors and the "Needs triage" label.

Modern CPUs such as Intel Core Ultra Series 3 processors and Apple M1/M2/... series have different core speeds (P-cores, E-cores, LP-cores...).

joblib and native libraries such as OpenMP or BLAS libraries will often start one thread per core. However, thread scheduling overhead can cause performance degradation compared to using fewer threads on those architectures, especially when iterating on many small data problems, for instance when bagging or grid searching models on small data.

The purpose of this issue is to assess how frequent and how bad is this problem in practice and track coordinate remediation efforts.

Concrete cases of this problem

Possible remediation strategies

  • Refactor parallel sections to group more work per parallel task (possibly dynamically based on the data size)
  • Dynamically adjust the number of threads based on a cost model informed by CPU architecture, data shape or benchmark: this sounds complex
  • Limit the number of threads on hybrid GPUs (e.g. either 1 thread per performance core, or 1 thread per performance core and 1 additional thread per two efficiency core for instance):

Activity

  1. added
    Parallelism and scalability
    on May 26, 2026
  2. itamarst commented on Jun 5, 2026

    @itamarst
    Contributor

    Here is an idea, expanding on mention of benchmarking above:

    1. Run 1% of the data with a single thread.
    2. Run 5% of the data with configured N threads, i.e. whatever the default is now (typically, # of CPU cores, or maybe algorithmically limited level of parallelism).
    3. Do some simple math to figure out which is plausibly faster, and use that for the remaining 94%.

    The smaller amount with single thread is to reduce the slowdown if N threads are significantly faster, especially important when you have large amounts of data; the higher amount with N threads is to amortize overhead of starting thread pool.

    Variations:

    • Only do this for potentially problematic amounts of data; if you're above a very unambiguous works-everywhere threshold just use N threads.
    • Do multiple experiments with number of threads; perhaps N/2 is faster than N threads.
  3. itamarst commented on Jun 5, 2026

    @itamarst
    Contributor

    For macOS specifically it appears there is an additional problem. macOS has a QoS setting for threads, and OpenMP not doing this (or using the wrong setting) may be part of the problem; long-running threads might be auto-migrated to efficiency cores.

    https://www.reddit.com/r/HPC/comments/1t0aaf3/openmp_coding_on_mac_os_x_and_efficiency_e_cores/ talks about this and some solutions.

    More discussion, where they actually used a lower QoS level to get faster results: https://jmmv.dev/2019/03/macos-threads-qos-and-bazel.html (the linked patch provides a solution for process pools, but not threads.)

  4. itamarst commented on Nov 5, 2026

    @itamarst
    Contributor

    A relevant piece of information that might explain some of this: I'm pretty sure OpenBLAS specifically works by breaking a chunk of work into a number of chunks equal to the number of cores, and then has to wait until all jobs are done. So if you have mixture of fast and slow cores, actual speed is that of slow cores. (Compare to OpenMP, which can use smaller chunks and so can break up work in way that adapts better to different workloads on different cores.)

    So for OpenBLAS specifically setting the limit to number of performance cores only should be a win, so long as they are the majority (or if equal in number, if performance cores are at least twice as fast as slow cores).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Parallelism and scalability

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions