mstar.utils.threads#
Starting threads, and moving the threads a step passes through onto their CPUs.
A step passes between the worker’s main thread, its GPU thread and its plan
thread several times (submit, launch, done, commit, plan ready), and each
handoff blocks one thread and wakes another. On a host with deep idle states a
thread woken on another core first waits for that core to leave C6 (130-175 µs
on the B300 host this was measured on); woken on a core that is already
running, it starts at once. The API server’s result threads (the message
thread, and the Rust frontend’s bridge) hand every step’s tokens on the same
way. step_thread_core (mstar.utils.cpus) pins them.
A new thread starts with its creator’s CPU mask, so a thread or pool that a
pinned thread starts would share its CPU. Thread and ThreadPool start
theirs on the process mask; ruff refuses a bare threading.Thread or
ThreadPoolExecutor under mstar/ (banned-api in pyproject.toml).
Functions
|
Confine the calling thread to |
Classes
|
A |
|
A |
- class mstar.utils.threads.Thread(group=None, target=None, name=None, args=(), kwargs=None, *, daemon=None)[source]#
Bases:
ThreadA
threading.Threadthat runs on the process mask, whatever its creator’s and whatever itsrunis: a target, an override that doesn’t callsuper().run(), a mixin’s. Wrapped atstartso that callingrundirectly stays on the caller’s thread and mask.
- class mstar.utils.threads.ThreadPool(max_workers=None, thread_name_prefix='', initializer=None, initargs=())[source]#
Bases:
ThreadPoolExecutorA
ThreadPoolExecutorwhose threads run on the process mask beforeinitializer, whatever the mask of the thread that started them.
- mstar.utils.threads.pin_thread(cpus, process_mask)[source]#
Confine the calling thread to
cpus.A thread’s intra-op (OpenMP) pool is started by its first parallel op with the mask the thread has then, and a pool confined to one CPU runs a parallel op many times slower. So go back to the process mask first (the main thread, already confined, starts the GPU and plan threads), start the pool there with one op as wide as the pool, and only then move.
- Parameters:
cpus (Collection[int])
process_mask (Collection[int])
- Return type:
None