unilab.base.cpu_runtime

Process-local CPU confinement for envs that own an explicit CPU block.

Multi-rank off-policy data-parallel runs partition host CPUs so each rank’s collector owns one contiguous block (training.dp_collector_cpu_ids, routed into EnvCfg.cpu_ids). The MuJoCo BatchEnvPool already pins its physics workers to that block, but the collector’s existing host-side native pools did not follow and could drift across rank boundaries to compete with sibling ranks’ pinned physics workers.

apply_cpu_confinement is the generic env-level counterpart, applied once on the env-construction cold path, before managers and backend materialization:

  • os.sched_setaffinity pins the calling thread to the block, and every already-running thread (e.g. BLAS pools spawned by a backend dependency) is pinned individually via /proc/self/task; threads spawned later inherit the mask.

The function is backend-agnostic: EnvCfg.cpu_ids is the single source of truth, so any backend whose env declares a block gets the same confinement.

Functions

apply_cpu_confinement(cpu_ids)

Confine this process's host-side compute to the env-owned CPU block.

unilab.base.cpu_runtime.apply_cpu_confinement(cpu_ids)[source]

Confine this process’s host-side compute to the env-owned CPU block.

Cold path only: call from env construction, before the backend pool or managers exist. None (the single-rank default) is a no-op so the default path keeps default OS scheduling.

Structural validation (non-empty, unique, non-negative ints) is owned by EnvCfg.validate; this function fails closed on CPU ids that are not available to the process.

Parameters:

cpu_ids (Sequence[int] | None)

Return type:

None