/dstack-performance:simd-intrinsicsfrom DStack Performance
Guides SIMD work: reading GCC/Clang vectorization reports, writing SSE2/AVX2/NEON intrinsics, and adding runtime CPU dispatch with scalar fallbacks.
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: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Let the compiler vectorize first and write intrinsics where it cannot. Every intrinsic code path needs a runtime feature check and a scalar fallback, because the binary runs on CPUs the build machine never saw.
This skill explains and drafts. It is read-only: edits land through the normal coding path, and nothing touches remote. The job is done when the vector path is guarded by a compile-time target and a runtime feature check, the scalar fallback exists, and the speedup is measured on the target machine.
-Rpass, -Rpass-missed, and -Rpass-analysis; GCC prints with -fopt-info-vec, -fopt-info-vec-missed, and -fopt-info-vec-optimized. Move on once the loop has a verdict with the reason.clang -O2 -march=native -Rpass-missed=loop-vectorize src.c
gcc -O2 -march=native -fopt-info-vec-missed src.c
| Blocker | Fix |
|---|---|
| Loop-carried dependency | Restructure so iteration i reads only i-1 or earlier |
| Early exit or data-dependent break | Move the exit into a mask or split the loop |
| Non-contiguous memory | Gather, scatter, or restructure to stride one |
| Possible aliasing | Add __restrict to the pointers |
| Unknown trip count | Keep a scalar tail loop |
void addf(float *__restrict dst,
const float *__restrict a, const float *__restrict b, size_t n) {
for (size_t i = 0; i < n; i++)
dst[i] = a[i] + b[i];
}
#include <stdbool.h>
bool have_avx2(void) {
return __builtin_cpu_supports("avx2");
}
For finer control, use __cpuid with __builtin_cpu_supports covering the common cases, and check xgetbv state through the compiler builtin for OS AVX support rather than reading registers by hand.
__m128; AVX2 moves eight per __m256. Unaligned loads on modern x86 cost little, so use them unless profiling proves otherwise. Move on once each path compiles under its own feature guard and the tail stays correct.#include <immintrin.h>
#ifdef __AVX2__
void sum8_avx2(float *dst, const float *a, const float *b, int n) {
int i = 0;
for (; i + 8 <= n; i += 8) {
__m256 va = _mm256_loadu_ps(a + i);
__m256 vb = _mm256_loadu_ps(b + i);
__m256 vc = _mm256_add_ps(va, vb);
_mm256_storeu_ps(dst + i, vc);
}
for (; i < n; i++)
dst[i] = a[i] + b[i];
}
#endif
FMA combines multiply and add and needs its own feature, so guard it:
#if defined(__FMA__)
__m256 vsum = _mm256_fmadd_ps(va, vb, vacc);
#endif
Compile the AVX2 translation unit with -mavx2 -mfma, or mark the single function:
__attribute__((target("avx2,fma")))
void kernel_avx2(float *dst, const float *a, const float *b, int n) { }
aarch64 and the 128-bit vector shape matches.#include <arm_neon.h>
void sum4_neon(float *dst, const float *a, const float *b, int n) {
for (int i = 0; i + 4 <= n; i += 4) {
float32x4_t va = vld1q_f32(a + i);
float32x4_t vb = vld1q_f32(b + i);
vst1q_f32(dst + i, vaddq_f32(va, vb));
}
}
__builtin_popcount for element-wise arithmetic. Move on once the choice is written next to the kernel.aligned_alloc(32, ...) for AVX2, and posix_memalign covers POSIX builds. Unaligned loads are correct everywhere and nearly free on recent x86, so pay for alignment only with a measurement. Move on once alignment claims carry the measurement that justifies them.-mavx2. Restore the dispatch and scope the flag to the function.aarch64 types only under __aarch64__ and provide an AArch32 variant.The guarded vector kernel with its scalar fallback, the dispatch check, and the measured speedup with the build flags and machine named. The intrinsic lookup tables, type maps, and feature guard reference live in references/intel-intrinsics-guide.md.
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
/cpu-kernel-authoringUse when writing, optimizing, or benchmarking a C++ CPU kernel with AVX2 or AVX512 intrinsics for the Hugging Face kernels ecosystem. Not for CUDA kernels./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./heaptrackUse when tracking heap allocations on Linux with heaptrack: allocation hotspots, peak heap, temporary allocations, leaks, or a diff of two runs via heaptrack_print. Not for heap errors./optimizeUse when one named path or performance symptom needs a single measured fix. Not for read-only hot-path hypotheses: use fastopt. Not for a full measured-floor campaign: use optimize-extremely.Other plugins' skills for the same job