Skip to content

fix(runtime,backend): bound device compile fan-out; configurable ptoas timeout#1928

Open
Little-oil wants to merge 2 commits into
hw-native-sys:mainfrom
Little-oil:ci-system-tests-runtime-fix
Open

fix(runtime,backend): bound device compile fan-out; configurable ptoas timeout#1928
Little-oil wants to merge 2 commits into
hw-native-sys:mainfrom
Little-oil:ci-system-tests-runtime-fix

Conversation

@Little-oil

Copy link
Copy Markdown
Contributor

What

Runtime/backend half of the system-tests (a2a3) compile-stability work,
split out from #1926 per review. The paired CI workflow tuning
(--precompile-workers, step timeout-minutes) lives in a separate PR.

Under the system-tests job, each case's per-kernel compile fan-out spun up
many ccec subprocesses, and heavy kernels could be killed by a hardcoded 60s
ptoas wall-clock under high compile-pool concurrency (spurious timeouts, not
real work limits).

Changes

  • device_runner.py — cap per-case device compile fan-out at
    min(16, available_cpus) (overridable via PYPTO_DEVICE_COMPILE_WORKERS) so
    it composes with the outer precompile pool instead of multiplying into
    process/thread exhaustion (libgomp thread-creation failures / segfaults). The
    affinity probe also tolerates OSError (restricted containers/sandboxes),
    falling back to os.cpu_count().
  • pto_backend.py — make the per-kernel ptoas compile timeout configurable
    via PYPTO_PTOAS_TIMEOUT, default raised 60s → 120s.

Test

Python-only; no behavior change on the default (unset-env) local path other
than the higher default timeout. Validated end-to-end alongside the CI tuning
PR (system-tests a2a3 stabilized).

Youhezhen added 2 commits July 2, 2026 11:37
…austion

Each test case compiled its kernels + orchestration with up to 64 threads,
each spawning a libgomp-parallel ccec subprocess. Under the precompile pool
this fan-out multiplies with the outer concurrency and exhausts process/
thread limits, surfacing as libgomp thread-creation failures and segfaults
during compilation. Cap the per-case fan-out at min(16, available_cpus),
overridable via PYPTO_DEVICE_COMPILE_WORKERS.
…to 120s

Heavy kernels (multi-stage pipelines, looped scatter) can push a single
ptoas invocation past the old hardcoded 60s wall-clock under high
compile-pool concurrency, surfacing as spurious PartialCodegenError
timeouts. Read the per-kernel timeout from PYPTO_PTOAS_TIMEOUT (default
120s) so CI can tune it without affecting local runs.
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b1bb89de-6afd-4515-859e-69eb899dbed2

📥 Commits

Reviewing files that changed from the base of the PR and between 80bac77 and de4e9e1.

📒 Files selected for processing (2)
  • python/pypto/backend/pto_backend.py
  • python/pypto/runtime/device_runner.py

📝 Walkthrough

Walkthrough

This PR adds environment-variable-based configuration for two compilation resource limits: a per-kernel ptoas subprocess timeout (PYPTO_PTOAS_TIMEOUT) in the backend, and a device compilation thread pool worker cap (PYPTO_DEVICE_COMPILE_WORKERS) bounded by CPU count in the runtime.

Changes

Compilation Resource Limits

Layer / File(s) Summary
Configurable ptoas timeout
python/pypto/backend/pto_backend.py
Adds _get_ptoas_timeout() to read PYPTO_PTOAS_TIMEOUT, defaulting to 120s, validating input, warning on invalid values, and clamping to a minimum of 1s; replaces the previous hardcoded 60s subprocess.run timeout with this computed value.
Device compile worker cap
python/pypto/runtime/device_runner.py
Adds _available_cpus() and _device_compile_workers(n_units) to cap thread pool workers using PYPTO_DEVICE_COMPILE_WORKERS, CPU availability, and a fixed cap constant; replaces the fixed min(64, 1 + len(kernels)) ThreadPoolExecutor sizing in compile_and_assemble with the new bounded calculation.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A rabbit tunes the clocks and threads,
No more fixed sixty, no more dread,
CPUs counted, workers capped tight,
Compiles hum steady from morning to night. 🐇⏱️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the two main runtime/backend changes: bounded compile fan-out and configurable ptoas timeout.
Description check ✅ Passed The description matches the changeset and accurately describes the runtime/backend compile-stability updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces configurable timeouts and worker limits for compilation processes. It adds the PYPTO_PTOAS_TIMEOUT environment variable to customize the ptoas compilation timeout and dynamically calculates the thread count for kernel compilation based on available CPUs, capped by the PYPTO_DEVICE_COMPILE_WORKERS environment variable. The review feedback suggests capping the worker count by the number of compilation units even when the environment variable override is active to ensure resource efficiency.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +84 to +86
if env_val:
try:
return max(1, int(env_val))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When PYPTO_DEVICE_COMPILE_WORKERS is set to a value larger than the number of compilation units (n_units), the returned worker count is not capped by n_units. While ThreadPoolExecutor only spawns threads as tasks are submitted, it is cleaner and more resource-efficient to cap the maximum workers at n_units even when the environment variable override is active.

Suggested change
if env_val:
try:
return max(1, int(env_val))
if env_val:
try:
return max(1, min(int(env_val), n_units))

lyfne123 pushed a commit that referenced this pull request Jul 2, 2026
…eout 15->20min) (#1929)

## What

CI workflow half of the `system-tests` (a2a3) compile-stability work,
split out
from #1926 per review. The paired runtime/backend changes (per-case
fan-out cap,
configurable ptoas timeout) are in #1928.

## Changes

`.github/workflows/ci.yml`, `Test system tests` step:

- `--precompile-workers` 128 → 64 — the outer precompile pool multiplied
with
each case's kernel-compile fan-out to spawn ~100 concurrent ccec
subprocesses,
exhausting process/thread limits and segfaulting mid-compile. Halving it
lets
  the outer pool compose with the per-case cap in #1928.
- `timeout-minutes` 15 → 20 — the lower concurrency reduces compile
throughput,
  so the ~440-case suite crosses the old 15min budget; give it headroom.

## Test

Validated on this branch's own CI run — `system-tests` (a2a3) completed
green
within the 20min budget.

## Note

Best paired with #1928: `--precompile-workers=64` is calibrated to
compose with
that PR's per-case fan-out cap. Landing this alone still lowers
concurrency
safely, but the two are designed to work together.

---------

Co-authored-by: Youhezhen <youhezhen@huawei.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant