Skip to content

Add parallel CuTeDSL tuning - #246

Merged
drisspg merged 1 commit into
mainfrom
drisspg/stack/39
Aug 8, 2026
Merged

Add parallel CuTeDSL tuning#246
drisspg merged 1 commit into
mainfrom
drisspg/stack/39

Conversation

@drisspg

@drisspg drisspg commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Stacked PRs:


Add parallel CuTeDSL tuning

Human Note

Agent note
A CUDA-owning process cannot safely fork workers that rediscover the device or inherit CuTeDSL
compiler state. Add a fresh interpreter driver that receives only static, pickleable compile calls
and parent-discovered target metadata, imports the cached compile function once, then forks bounded
workers to populate distinct disk artifacts. The parent loads those artifacts and benchmarks each
candidate sequentially with Inductor's CUDA benchmarker.

Expose run_tunable as the author-facing boundary. An op owns a conservative default, an
input-aware typed config generator, a projection from runtime tensors to positional static compile
arguments, and a launch adapter. Runtime tensors never cross the compiler-process boundary, and a
fully warm tune starts no compiler process.

Test Plan:

~/.venvs/nightly/bin/python -m pytest -q test/test_cute_cache.py
gpu-run 0 -- ~/.venvs/nightly/bin/python -m pytest -q test/test_cute_cache_gpu.py
~/.venvs/dev/bin/ruff check attn_gym/_backends/cute test/test_cute_cache.py test/test_cute_cache_gpu.py

Human Note

Agent note
A CUDA-owning process cannot safely fork workers that rediscover the device or inherit CuTeDSL
compiler state. Add a fresh interpreter driver that receives only static, pickleable compile calls
and parent-discovered target metadata, imports the cached compile function once, then forks bounded
workers to populate distinct disk artifacts. The parent loads those artifacts and benchmarks each
candidate sequentially with Inductor's CUDA benchmarker.

Expose `run_tunable` as the author-facing boundary. An op owns a conservative default, an
input-aware typed config generator, a projection from runtime tensors to positional static compile
arguments, and a launch adapter. Runtime tensors never cross the compiler-process boundary, and a
fully warm tune starts no compiler process.

Test Plan:

```bash
~/.venvs/nightly/bin/python -m pytest -q test/test_cute_cache.py
gpu-run 0 -- ~/.venvs/nightly/bin/python -m pytest -q test/test_cute_cache_gpu.py
~/.venvs/dev/bin/ruff check attn_gym/_backends/cute test/test_cute_cache.py test/test_cute_cache_gpu.py
```

stack-info: PR: #246, branch: drisspg/stack/39
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 8, 2026
@drisspg
drisspg marked this pull request as draft August 8, 2026 01:17
@drisspg
drisspg changed the base branch from drisspg/stack/38 to main August 8, 2026 01:17
@drisspg
drisspg changed the base branch from main to drisspg/stack/38 August 8, 2026 01:18
@drisspg
drisspg marked this pull request as ready for review August 8, 2026 01:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0dd6382c76

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

target=target,
timeout=timeout,
)
return [fn(*args) for args in call_args]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep the requested target active while loading artifacts

When two host threads call compile_many() or tune() concurrently with different explicit targets, each call sets the process-global target before blocking in its compiler subprocess, so the later call can overwrite it before the first reaches this load loop. The first call then keys fn(*args) using the other thread's target, potentially returning a kernel for the wrong GPU architecture or compiling that variant in the CUDA-owning parent; target selection must remain scoped or synchronized through the complete artifact-loading phase.

Useful? React with 👍 / 👎.

Comment on lines +149 to +151
text=True,
env={**os.environ, "TORCH_WARM_POOL": "0"},
timeout=timeout,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Terminate compiler workers when the timeout expires

If compilation exceeds timeout, subprocess.run kills only the fresh driver process; the forked ProcessPoolExecutor workers are grandchildren and remain orphaned, continuing expensive compilation and cache writes after precompile_many() has raised. Launch the driver in a managed process group and terminate the entire group on timeout so the advertised bound also applies to its workers.

Useful? React with 👍 / 👎.

@drisspg
drisspg changed the base branch from drisspg/stack/38 to main August 8, 2026 03:19
@drisspg
drisspg merged commit c4e905d into main Aug 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant