/dstack-performance:cpu-kernel-authoringfrom DStack Performance
Writes, optimizes, and benchmarks C++ CPU kernels with AVX2/AVX512 intrinsics for the Hugging Face kernels ecosystem against a PyTorch baseline.
Ships in DStack Performance. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
You write, optimize, or benchmark a C++ CPU kernel with AVX2 or AVX512 intrinsics for the Hugging Face kernels ecosystem, measured against a PyTorch baseline. This skill is not for CUDA kernels.
The work has two phases. The correctness phase builds the tiers in order (generic ATen fallback, optional AVX2, AVX512), and each tier must pass correctness before the next starts. The performance phase iterates on the AVX512 tier through the trial tree until max_trials is exhausted or early_stop_speedup is exceeded. You are done when the kernel passes the correctness check in scripts/benchmark_cpu.py, every trial up to max_trials has run or the speedup exceeded early_stop_speedup, and the best trial is finalized into output/ with its final measurement. Otherwise you report the failure class and the recovery step taken.
You write locally and reversibly: C++ kernel sources, build.toml, and torch_binding.cpp under the kernel directory, a wheel under dist/, the installed kernel package in the active Python environment, and trial state under trials/<kernel_name>/ and output/. Rollback is version control for the sources, pip uninstall <package> for the package, and removal of dist/, trials/<kernel_name>/, and output/. No remote mutation.
Required inputs:
my_rmsnorm. trial_manager.py accepts it only as a single directory name under trials/, never a path.baseline.py defining get_inputs() and either get_reference_output() or a Model class (with optional get_init_inputs()). It is the ground truth for correctness and the speed reference.analyze_op.py --op looks up, for example rms_norm.analyze_op.py --shapes, for example "1024x4096,2048x8192".my_kernel, and its callable as package.function, for example my_kernel.rms_norm. benchmark_cpu.py and cpu_profiler.py take this path as their --op; it is not the operation name above.validate_cpu_kernel.py parses build.toml with the standard-library tomllib), kernel-builder, pip, PyYAML (imported by scripts/config.py), numactl (used by the pinned benchmark in step 8), a C++ compiler with AVX512 support, and PyTorch. perf is required only when perf_stat_enabled is true.Modify only .cpp and .hpp files, torch_binding.cpp, and build.toml. Do not write new benchmark or timing scripts; scripts/benchmark_cpu.py is the only timing source. When a script fails, report the error rather than working around it.
scripts/config.yaml and note max_trials, early_stop_speedup, perf_stat_enabled, vtune_enabled, build_command, and install_command. Use those two commands wherever this procedure builds or installs. If the config file is missing, stop and report; never assume trial counts.python scripts/analyze_op.py --op <op_name> --shapes <shapes> and read the compute and memory characteristics and the suggested SIMD strategy. Read references/workflow_details.md for the analysis and design steps. The script recognizes norm, softmax, gemm, linear, matmul, attention, gelu, silu, relu, moe, and megablocks by name and classifies anything else as plain element-wise; when it reports no matmul, reduction, or activation for your op, classify the kernel type by hand from the baseline (element-wise, reduction, GEMM, or attention) and continue at step 3.python scripts/trial_manager.py init <kernel_name> <baseline_file>, which creates trials/<kernel_name>/ and records the baseline.<kernel>_cpu/cpu_features.hpp in the kernel's own namespace, the dispatcher <kernel>_cpu/<kernel>_cpu.cpp with an ATen-only fallback, the bridge <kernel>_cpu/<kernel>_cpu_torch.cpp, torch-ext/torch_binding.cpp using the registration.h macros, and build.toml with one [kernel.*] section per tier and include = ["<kernel>_cpu"] in every section. Read references/runtime_dispatch.yaml, references/build_system.md, references/implementation_reference.md, and references/correctness.yaml while writing. Run python scripts/validate_cpu_kernel.py <kernel_dir> and fix the named file or build.toml section until validation reports no error. A validation fix does not count as a trial.kernel-builder build --release then pip install dist/*.whl --force-reinstall --no-deps. When the build fails, read the compiler output, fix the source or the section's cxx-flags, and rebuild. You are done when python -c "import <package>" succeeds.python scripts/benchmark_cpu.py <baseline_file> --kernel-package <package> --op <package>.<function>. The correctness check walks tuples, lists, and dicts element-wise, requires equal structure, dtype, and shape, and compares each tensor leaf in its own dtype: half an ulp relative for bf16 and fp16, atol=1e-6, rtol=1e-5 for fp32, atol=1e-12, rtol=1e-9 for fp64, exact for integer and bool. Widen with --atol and --rtol only when the kernel's accumulation order legitimately differs from the reference, and record the reason in the trial's --strategy. On correctness failure, read the leaf path, dtype, and worst-element values in the benchmark output: a wrong second output or a dtype or shape change is a binding or dispatcher bug; a one-ulp bf16 difference on many elements is a rounding-mode or conversion bug; a tail-only difference is missing tail handling; a large scattered difference is an alignment bug. Fix on the same branch, rebuild, re-benchmark. Never enter the performance phase with a failing kernel.<kernel>_cpu/<kernel>_avx512.cpp with its own cxx-flags section (-mavx512f -mavx512bf16 -mavx512vl for element-wise kernels; GEMM kernels add -mavx512dq -mavx512bw -mavx512vbmi -mamx-tile -mamx-bf16 -mamx-int8), with -fopenmp in every SIMD section. Add an AVX2 tier only when it gives an element-wise kernel a measurable benefit; GEMM kernels dispatch AVX512 to fallback. Repeat steps 4 to 6, then run python scripts/trial_manager.py save <kernel_name> <kernel_dir> --strategy "<description>" and record the numbers with python scripts/trial_manager.py result <kernel_name> <trial_id> --correctness pass --speedup <x> --baseline_us <us> --kernel_us <us>. This ends the correctness phase with the AVX512 tier correct and trial t0 recorded.numactl --cpunodebind=0 --membind=0 python scripts/benchmark_cpu.py ... --baseline-us <cached>, where the cached value comes from python scripts/trial_manager.py baseline-us <kernel_name>.perf_stat_enabled is true, run python scripts/cpu_profiler.py --kernel-package <package> --op <package>.<function> once after the first benchmarked trial. Read IPC together with the L1 and LLC miss rates: a pure AVX512 FMA loop has low IPC by design, so claim a memory bound only when a miss rate is also high. If perf is unavailable or perf stat returns no counters, continue without profiling, report it, and choose the next trial from references/optimization_levels.yaml. Either way, choose the next change from references/optimization_strategies.md.max_trials, change one thing in the AVX512 tier (blocking, prefetch, unrolling, threading, or a different algorithm from references/simd_optimization_patterns.yaml, references/memory_patterns.yaml, references/threading_patterns.yaml, references/dtype_optimizations.yaml, references/brgemm_patterns.yaml, references/quantized_gemm_patterns.yaml, and references/optimization_levels.yaml), then validate, build, benchmark, save with --parent <best_or_current_id>, and result. A regression branches back to the best trial (find its id with python scripts/trial_manager.py best <kernel_name>). A kernel slower than baseline on small tensors gets a num_tokens threshold below which the dispatcher calls the ATen fallback; see references/threading_patterns.yaml. A plateau after two trials changes the algorithm, data layout, or fusion instead of sweeping the same knobs. Stop early only when the speedup exceeds early_stop_speedup. When max_trials is reached below early_stop_speedup, finalize the best trial and report the speedup reached and the trial tree from trial_manager.py status.python scripts/trial_manager.py finalize <kernel_name> output/, then re-run the pinned benchmark_cpu.py without --baseline-us for the final measurement. Read references/huggingface-kernels-integration.md if the kernel is to be published to the Hub. You are done when output/ holds the best trial's sources with final correctness and speedup recorded.<kernel>_cpu/ with cpu_features.hpp, the dispatcher, the bridge, the AVX512 implementation, and any AVX2 implementation, plus torch-ext/torch_binding.cpp and build.toml.dist/ and the installed <package>.trials/<kernel_name>/ with each saved trial, its parent, strategy, correctness, and timing.benchmark_cpu.py output naming per-dtype tolerances and, on failure, the leaf path of each mismatch.output/ holding the best trial's sources and its final measurement.agents/openai.yaml (opens in a new tab)references/brgemm_patterns.yaml (opens in a new tab)references/build_system.md (opens in a new tab)references/correctness.yaml (opens in a new tab)references/dtype_optimizations.yaml (opens in a new tab)references/huggingface-kernels-integration.md (opens in a new tab)references/implementation_reference.md (opens in a new tab)references/memory_patterns.yaml (opens in a new tab)references/optimization_levels.yaml (opens in a new tab)references/optimization_strategies.md (opens in a new tab)references/quantized_gemm_patterns.yaml (opens in a new tab)references/runtime_dispatch.yaml (opens in a new tab)references/simd_optimization_patterns.yaml (opens in a new tab)references/threading_patterns.yaml (opens in a new tab)references/workflow_details.md (opens in a new tab)scripts/analyze_op.py (opens in a new tab)scripts/benchmark_cpu.py (opens in a new tab)scripts/config.py (opens in a new tab)scripts/config.yaml (opens in a new tab)scripts/cpu_profiler.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub gosuda/dstack-skills --plugin dstack-performance8 skills in this plugin
/decoded-memo-retentionUse when a query-scoped decoded-block cache is bounded only by serialized work bytes, or when fallback paths retain many decoded blocks. Not for total-process memory promises: this skill never claims a process-wide bound./fastoptUse when a suspected hot path needs read-only hypotheses and benchmark designs, without waiting for benchmarks and without a code change. Not for a single measured fix: use optimize. Not for estimated hot and cold analysis: use fastopt-extreme. Not for measured-floor campaigns: use optimize-extremely./fastopt-extremeUse when estimating hot paths and proposing complexity-neutral cold simplifications while refusing complexity theater. Not for hypothesis-only hot paths: use fastopt. Not for measured-floor campaigns: use optimize-extremely.Other plugins' skills for the same job