cpp-hpc-optimization
Evidence-driven C++ high-performance computing design, profiling, and optimization across algorithmic time/space complexity, data layout, cache and memory…
by archibate★ 42 GitHub stars
Install cpp-hpc-optimization in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
About this skill
C++ HPC Optimization
Optimize the measured data path, not the code that merely looks low-level. Preserve a simple reference implementation and make every optimization earn its complexity with correctness evidence and a representative benchmark.
Non-negotiable rules
- Define the contract first. Record inputs, sizes, distributions, target hardware, accuracy, determinism, memory, latency, and throughput objectives.
- Pass the complexity gate. Compare the best practical algorithmic families for the actual size range before tuning constants inside one family.
- Profile before kernel redesign. Identify the hot path with end-to-end evidence.
- Keep an oracle. Retain a scalar or otherwise obviously-correct reference implementation and compare every optimized path against it.
- Model before tuning. Estimate useful operations, bytes transferred, working set, dependency depth, synchronization, and launch overhead.
- Change one axis at a time. Measure after each transformation and revert changes that do not win on the target workload.
- Never encode a benchmark accident as a law. Cache sizes, SIMD width, thread count, tile size, padding, and crossover thresholds are target- and workload-dependent.
- Make ISA requirements explicit. Use feature dispatch and a compatible fallback when targets vary, or a verified fixed ISA for controlled deployments. Both require tail handling and equivalence tests.
Workflow
1. Frame the performance contract
Write down:
- the semantic result and accepted numerical error;
- representative and adversarial input shapes and distributions;
- steady-state throughput, single-item latency, tail latency, or deadline;
- memory-footprint and allocation constraints;
- target CPUs, accelerators, compilers, build flags, and deployment topology;
- whether batching, reordering, nondeterministic reductions, or preprocessing are permitted.
Do not optimize an unspecified target. Throughput and latency often demand opposite choices: batching and deep queues improve throughput but add waiting.
2. Pass the algorithmic time/space complexity gate
Before applying cache, SIMD, threading, or instruction-level techniques:
- identify lower bounds and the best mature practical algorithm families for the declared sizes, distributions, sparsity, dimensionality, accuracy, update/query ratio, and number of timesteps or solves;
- compare total time, peak/live space, preprocessing, communication, numerical behavior, worst/expected cases, and implementation maturity;
- benchmark crossover regions and retain a size/shape-dependent portfolio when different algorithms win in different regimes.
An asymptotically better method may lose at small n; an asymptotically worse
regular kernel may exploit the target exceptionally well. Conversely, no amount
of constant-factor kernel tuning rescues an avoidable complexity class at scale.
Choose the industrially useful family for the declared range first, then use the
rest of this skill to reduce its realized cost. Preserve the declared semantic or
numerical contract; optimization need not be bit-exact when the contract permits
an approximate, reordered, or mixed-precision algorithm.
3. Establish correctness and measurement baselines
- Build a readable reference path before intrinsics, lossy precision, relaxed math, or concurrency.
- Create correctness tests covering empty, tiny, tail, misaligned, extreme, NaN/Inf, sparse/dense, and aliasing cases that the contract permits.
- Benchmark the actual hot operation with realistic data. Warm up, prevent dead-code elimination, report distribution rather than one lucky sample, and retain end-to-end measurements beside microbenchmarks.
- Inspect generated code and compiler optimization remarks before assuming the compiler failed.
Read references/profiling-and-cost-model.md before profiling, benchmarking,
or declaring a bottleneck.
4. Classify the limiting resource
Calculate at least an approximate per-item model:
- useful operations and transcendental/divide cost;
- compulsory input, output, metadata, and intermediate bytes;
- working-set size at each reuse distance;
- independent operations versus loop-carried dependency chains;
- tasks, locks, atomics, barriers, launches, copies, and queue transitions;
- scaling versus threads, vector width, batch size, and problem size.
Classify the current regime as memory-bandwidth, cache-capacity/latency, compute/issue, dependency-latency, synchronization, task-granularity, launch, or transfer bound. A kernel can move between regimes after each optimization.
5. Evaluate change scope and ROI
Record the currently authorized edit boundary, but do not mistake it for the root-cause boundary. When evidence places the limiting work upstream or in data representation, ownership, or construction, compare:
- the best optimization inside the current boundary;
- the smallest upstream
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
- LICENSE
- agents/openai.yaml
- references/accelerator-throughput.md
- references/allocation-and-memory-resources.md
- references/data-layout-and-memory.md
- references/hotpath-polymorphism.md
- references/numerics-and-quantization.md
- references/parallel101-case-studies.md
- references/parallel101/course/04/3_pointers/01_pointer_aliasing/main.cpp
- references/parallel101/course/04/3_pointers/02_restrict_pointer/main.cpp
- references/parallel101/course/04/5_loops/01_worry_pointer_aliasing/main.cpp
- references/parallel101/course/04/5_loops/02_no_pointer_aliasing/main.cpp
- references/parallel101/course/04/5_loops/04_no_pointer_aliasing_ivdep/main.cpp
- references/parallel101/course/04/5_loops/06_loop_with_external_call/main.cpp
- references/parallel101/course/04/5_loops/07_loop_with_inlineable_call/main.cpp
- references/parallel101/course/04/5_loops/08_loop_with_random_access/main.cpp
- references/parallel101/course/04/5_loops/09_loop_with_skip_access/main.cpp
- references/parallel101/course/04/5_loops/10_loop_with_ordered_access/main.cpp
- references/parallel101/course/04/5_loops/11_loop_invariant_motion/main.cpp
- references/parallel101/course/04/5_loops/12_loop_invariant_failed/main.cpp
- references/parallel101/course/04/5_loops/13_loop_unrolling/main.cpp
- references/parallel101/course/04/6_structs/01_vec2_simd_ok/main.cpp
- references/parallel101/course/04/6_structs/02_vec3_simd_fail/main.cpp
- references/parallel101/course/04/6_structs/03_vec3_with_padding_ok/main.cpp
- references/parallel101/course/04/6_structs/04_vec3_with_alignas_ok/main.cpp
- references/parallel101/course/04/6_structs/05_vec3_aos/main.cpp
- references/parallel101/course/04/6_structs/06_vec3_soa/main.cpp
- references/parallel101/course/04/6_structs/07_vec3_aosoa/main.cpp
- references/parallel101/course/04/6_structs/08_benchmark/aos.cpp
- references/parallel101/course/04/6_structs/08_benchmark/aos_aligned.cpp
- references/parallel101/course/04/6_structs/08_benchmark/aos_parallel.cpp
- references/parallel101/course/04/6_structs/08_benchmark/aosoa.cpp
- references/parallel101/course/04/6_structs/08_benchmark/common.h
- references/parallel101/course/04/6_structs/08_benchmark/main.cpp
- references/parallel101/course/04/6_structs/08_benchmark/profile.h
- references/parallel101/course/04/6_structs/08_benchmark/soa.cpp
- references/parallel101/course/04/6_structs/08_benchmark/soa_parallel.cpp
- references/parallel101/course/04/6_structs/08_benchmark/soa_simd.cpp
- references/parallel101/course/04/6_structs/08_benchmark/soa_size_t.cpp
- references/parallel101/course/04/6_structs/08_benchmark/soa_unroll.cpp
FAQ
What does the cpp-hpc-optimization skill do?
Evidence-driven C++ high-performance computing design, profiling, and optimization across algorithmic time/space complexity, data layout, cache and memory behavior, numerics, SIMD, multicore scheduling, and CPU/accelerator pipelines. Use before designing or changing computation-intensive kernels, high-throughput data structures, performance-critical loops, SIMD/OpenMP/TBB/CUDA code, mixed-precision or sparse representations, or when investigating throughput, latency, scaling, cache, bandwidth, compiler-vectorization, or profiling problems.
How do I install the cpp-hpc-optimization skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the cpp-hpc-optimization skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
skill-creator
AnthropicCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
discernment-nudge
AnthropicAfter you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
data-consolidate
AnthropicJoins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
inspection-to-capa
AnthropicRuns the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…