Gale v2 Refactor - Working Discipline

VerifiedSafe

Consolidate GPU optimization into clean building blocks while preserving performance. Discipline rules to avoid recurring mistakes.

Sby Skills Guide Bot
DevelopmentAdvanced
7/23/2026
Claude Code
#gpu-performance#refactoring#cuda#benchmarking#multigrid

Recommended for

Automated summary

Governs the gale v2 consolidation refactor, folding accumulated CPU+GPU DG optimization work behind src/sim/'s Sim/Device abstraction while protecting the measured performance gains.

Strengths

  • Turns real corrections from optimization sessions into working rules (never cross-compare iteration counts across different algorithms; a prototype is faithful only if its algorithmic structure matches production)
  • Requires an ncu number (DRAM%, occupancy, bytes moved) before any kernel is declared "at the floor"
  • Demands A/B tests in the production device-resident while-graph path, measured in wall-clock rather than API/launch counts
  • Points to the design and benchmark ledger in docs/gale-v2-refactor.md and pairs with the gale-gpu-perf skill for the profiling gate

Limitations

  • Tightly coupled to the gale repository and its reference document, so it is largely non-reusable elsewhere
  • Provides discipline and direction but no concrete commands or code snippets
  • Assumes GPU hardware and ncu access, so its verification steps cannot be followed on a machine without a GPU
When to use it

Use it when consolidating gale v2's DG optimization work into Sim/Device building blocks or when you need to defend its measured performance edge.

When not to use it

Skip it for GPU kernel tuning outside the gale project, or for any refactor lacking the benchmark ledger and resident while-graph production path.

Security analysis

Safe
Quality score78/100

The skill is a pure working-discipline/lessons document for a GPU multigrid refactor. It contains no executable payloads, no shell one-liners beyond legitimate developer commands it merely references (cargo oxide build, ncu, nsys, env vars like RVP_NOGRAPH), no credential/secret handling, no network exfiltration, and no instructions to disable safety controls or touch destructive paths. The only execution surface is building and profiling the user's own project, which is ordinary and low-risk.

No concerns found

How this analysis is made

Examples

A/B a smoother change in the production path
I want to fold the mixed-precision op_cheby smoother into the Sim/Device abstraction. Before I claim a 1.5x win, help me set up an A/B in the device-resident while-graph path measured in wall-clock, and run ncu to show whether it's actually BW-bound on the smoother fields.
Sanity-check an iteration count claim
The Rust cuda-oxide run converges in 24 iterations while the C++ prototype gave 16 — is cuda-oxide slow here, or am I comparing different algorithms? Walk me through the discipline rules for cross-comparing iteration counts.
Justify an architecture fork
The measured win seems to require h-multigrid, which is a separate solver. Help me write up the fork honestly with the measurements that motivate it, instead of projecting the prototype's percentage onto production.

name: gale-v2-refactor description: > Use when working on the gale v2 consolidation/refactor — folding the accumulated CPU+GPU DG optimization work into user-friendly building blocks behind src/sim/'s Sim/Device abstraction while defending the measured performance edge. Carries the working-discipline rules distilled from the optimization sessions (the mistakes that got corrected repeatedly), the measurement gotchas, and the v2 design rails. Pair with the gale-gpu-perf skill for the profiling gate. Read docs/gale-v2-refactor.md for the full design + benchmark ledger.

gale v2 refactor — discipline, tools, direction

This is a serious refactor: consolidate the perf work into clean building blocks without losing the numbers. The design + the benchmark baselines live in docs/gale-v2-refactor.md — read it first. This skill exists mostly to stop the recurring mistakes. Take the working-discipline section literally.

Working discipline — the mistakes that kept happening (don't repeat them)

These are real corrections from the optimization sessions. Each cost time. Internalize the rule, not just the example.

  1. Iteration counts are language-independent. NEVER cross-compare them across implementations unless the ALGORITHM is identical. A correct Chebyshev-MG-PCG converges in the same iterations in CUDA or cuda-oxide; if a C++ prototype gives 16 and the Rust gives 24, that is not a language/cuda-oxide effect — it's a different algorithm (here: h-MG vs p-MG) or a bug. Comparing C++-iters to Rust-iters and blaming the backend wasted a whole analysis. Compare ms/step (same language, same hardware) for perf; compare iters only within one algorithm.

  2. A prototype is a "faithful model" only if it runs the SAME algorithm — a coincidental scalar match does not prove it. A C++ h-multigrid prototype was called a faithful model of the production p-multigrid because their Jacobi iteration counts happened to match (29≈28); its 45% win was projected onto production, which actually got ~6%. One matching number ≠ same algorithm. Before projecting a prototype's win, confirm the prototype's structure matches production.

  3. Never say a kernel is "at the floor" / "nothing left" without an ncu number showing the bound and what's moving the bytes. Claiming op_cheby was "at the bandwidth floor" was wrong — it was BW-bound on the smoother fields (b/dinv/dvec), not the matvec, and mixed precision was a ~1.5× lever. "It works" ≠ done. "It works + here are the profile numbers (DRAM%, occupancy, the bytes)" = done. If you're about to write "we're near optimal," profile it instead.

  4. Measure; don't project. And measure WALL-CLOCK, not API/launch counts. Don't hedge with "this is probably ~X%." Run it. And note: a while-graph A/B that changed API counts showed no wall-clock win — API counts are not performance. An ncu --graph-profiling graph number on a while-graph kernel is a measurement artifact, not a measurement (§ below).

  5. A/B in the PRODUCTION path (the device-resident while-graph), not standalone. The arith matvec was bit-perfect in the standalone op_profile but broke the Neumann pressure solve (46× slower) only in the resident path — the arithmetic-neighbour opt had silently dropped the per-face BC metadata. A standalone win can be a production regression. Validate where it ships.

  6. For GPU perf work, "C++" means CUDA/C++ (GPU). When asked to prototype "in C++", prototype on the GPU. The CPU is only the cheap way to answer an algorithm/iteration-count question (e.g. "does FP32 smoothing hold the iteration count?") — not a perf prototype.

  7. Push to the measured answer; but surface genuine forks honestly with the data. Don't stop short or checkpoint to avoid work. Do surface a real architecture fork (e.g. "the win needs h-multigrid, a separate solver") with the measurement that motivates it — that's not hedging, it's the user's call to make. The test: are you stopping because you're unsure (then measure) or because there's a genuine large speculative investment with a real decision (then present the data + recommend)?

  8. Be honest about what a commit bundles and what you left alone. poisson.rs carried prior uncommitted work mixed in-file; say so. Don't sweep unrelated WIP into a feature commit silently.

Build & measurement gotchas (these bite every session)

  • cargo oxide build --arch sm_70 for the Titan V, OR CUDA_OXIDE_TARGET=sm_70 when running the bare binary. cuda-oxide embeds kernels as NVVM-IR and JIT-links the cubin at runtime for CUDA_OXIDE_TARGET (defaults to sm_120). A plain cargo oxide build + running target/release/<bin> directly → DriverError(209) "no kernel image available" — that's the wrong-arch cubin, not a perms/CUPTI problem. cargo oxide run auto-detects and injects sm_70; the bare binary (what profilers run) does not.
  • ncu CANNOT profile kernels inside conditional (while/if) CUDA graphs — its per-kernel numbers are artifacts. To profile a solve kernel: take it out of the graph (RVP_NOGRAPH=1 / GpuResidentVe::with_while_graph(false), or op_profile) and ncu the plain launch. Use nsys --cuda-graph-trace=node for the in-situ which-kernel-dominates breakdown (timing only, no HW counters). See the gale-gpu-perf skill for the full gate.
  • Run cargo oxide, not cargo-oxide (env/cache differ — a stale backend is used silently).
  • The mandatory gate before calling GPU work done (from gale-gpu-perf): RULE ZERO (no per-step host↔dev sync — nsys memcpy/sync counts must NOT scale with steps×stages), the kernel's bound via ncu, before/after ms reported as a number, correctness regression still green.

v2 design rails (the direction — full detail in docs/gale-v2-refactor.md)

  • Three residency levels. L0 CPU (host loop, oracle). L1 GPU host-orchestrated (device-resident state, host calls step() per step — a prototype; any per-step readback violates RULE ZERO). L2 GPU fully device-resident (whole step a captured graph, whole loop a while-graph, no host per-step work — the production bar for sweeps). GpuDualSplitting is L1 via StateIntegrator; GpuResidentVe/Ns is L2 and cannot be a per-step StateIntegrator.
  • Sim-as-spec, Device-as-compiler. Sim is a declarative physics spec; Device::plan(spec) picks the backend + the highest residency level the spec supports. Add a ResidentIntegrator seam (run_resident(state, nsteps, io_every, writers)) for L2 alongside the StateIntegrator seam for L1.
  • Dual-impl building blocks. Each Term/StageHook/Updater/Writer carries a CPU impl + optionally a device-resident (kernel) impl. Closure-only blocks cap a sim at L1; giving them kernel twins is what lets a sim reach L2.
  • gpu cargo feature (default-on). Gates the optional gale-gpu dep + every Cuda arm. Without it: CPU-only, no cuda-oxide. With it: the user builds via cuda-oxide (like nvcc). No silent CPU fallback for Device::Cuda.
  • The Device enum exists but is currently dormant (never read by Simulation::run); the real seam today is StateIntegrator, and GPU is reached by manually constructing GpuDualSplitting. The refactor makes Device the compiler that resolves this.

Order of operations (don't skip step 1)

  1. Freeze the §4 baselines into benches/ first (the ms/step·ms/kernel·ms/iter triplet + the RULE-ZERO check). Refactoring without a regression baseline is how the perf edge silently dies.
  2. Feature-flag the GPU. 3. Device::plan + integrator factory (L1, already exists). 4. The ResidentIntegrator seam (L2 — where the ~1.5× lives). 5. Dual-impl the hooks/updaters. 6. examples/benches/tests reorg. 7. Autotuning hooks (swappable scalar type + launch configs).

Each step ends green on the regression triplet. A >~5% move without an explanation is a bug.

Magic-number levers worth autotuning (don't hand-tune per GPU)

block-size / elements-per-block (biggest knob, hardware-specific), mixed-precision toggle (FP32 vs FP64 smoother), coarse-iteration count + Krylov tolerance, the hp hierarchy balance, graph-vs-no-graph. Make the scalar type and launch configs swappable so an autotuner has something to turn. The algorithm (hp-MG + Chebyshev + restructured matvec + residency) is portable and good; new-hardware work is mostly autotuning + two measured investigations (FP64 tensor-core contractions on A100+, mixed-precision iterative refinement for FP64-weak parts).

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/gale-v2-refactor-working-discipline-mrx3xwni/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/gale-v2-refactor-working-discipline-mrx3xwni' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/gale-v2-refactor-working-discipline-mrx3xwni/download' --output '.skill-downloads/gale-v2-refactor-working-discipline-mrx3xwni/SKILL.md.part' && mv '.skill-downloads/gale-v2-refactor-working-discipline-mrx3xwni/SKILL.md.part' '.skill-downloads/gale-v2-refactor-working-discipline-mrx3xwni/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/gale-v2-refactor-working-discipline-mrx3xwni/SKILL.md' && test -s '.skill-downloads/gale-v2-refactor-working-discipline-mrx3xwni/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/gale-v2-refactor' && cp -R '.skill-downloads/gale-v2-refactor-working-discipline-mrx3xwni' '.claude/skills/gale-v2-refactor'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/gale-v2-refactor-working-discipline-mrx3xwni'

openskills read 'gale-v2-refactor-working-discipline-mrx3xwni'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/gale-v2-refactor-working-discipline-mrx3xwni/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills