Skip to content

Optimize CPU sigmoid/SiLU with AVX512 rcp14 fast paths - #92

Closed
mingfeima wants to merge 2 commits into
mainfrom
cursor/vec-fast-sigmoid-rcp14-7180
Closed

mingfeima wants to merge 2 commits into
mainfrom
cursor/vec-fast-sigmoid-rcp14-7180

Conversation

@mingfeima

@mingfeima mingfeima commented Jul 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds merged AVX512 + at::vec::Vectorized<float> fast math helpers and applies them across CPU hot paths.

Primitives (vec.h)

  • _mm512_rcp14_sigmoid_ps / _mm512_rcp14_silu_ps / _mm512_rcp14_sigmoid_glu_ps
  • _mm512_deinterleave_ps for interleaved gate/linear layouts
  • fast_sigmoid / fast_silu / fast_sigmoid_glu fVec wrappers

Hot path optimizations

  • clamp_sigmoid_and_mul_stub: AVX512 BF16 fast path (MXFP4 swiglu), rcp14 + vectorized deinterleave; generic path uses fast_sigmoid_glu
  • silu_and_mul_stub, MoE tinygemm (moe.cpp, moe_int8.cpp), activation, topk, mamba conv/fla, gemm: replace vdivps sigmoid with fast_* / _mm512_rcp14_*

Bug fix

  • clamp_sigmoid_and_mul_stub loop bound corrected to 2 * size (interleaved input is 2× output width)

Next steps

  • Optional Half specialization for clamp_sigmoid_and_mul_stub
  • Benchmark MXFP4 CPU MoE swiglu path on Sapphire Rapids / Granite Rapids
Open in Web Open in Cursor 

CI States

Latest PR Test (Base): ❌ Run #29390969628
Latest PR Test (Extra): ❌ Run #29390969428

Introduce _mm512_rcp14_sigmoid_ps and _mm512_rcp14_silu_ps as AVX512
primitives, with fast_sigmoid/fast_silu fVec wrappers that delegate to them.
Reuse the sigmoid primitive in norm.cpp gated AVX512 apply_gate.

Co-authored-by: Ma Mingfei <[email protected]>
- Add fast_sigmoid_glu and _mm512_deinterleave_ps helpers in vec.h
- AVX512 BF16 specialization for clamp_sigmoid_and_mul_stub (MXFP4 swiglu)
- Replace vdivps sigmoid patterns with fast_sigmoid/fast_silu across MoE,
  activation, topk, norm, mamba, and gemm CPU kernels
- Fix clamp_sigmoid_and_mul_stub loop bound (2 * size input elements)

Co-authored-by: Ma Mingfei <[email protected]>
@cursor cursor Bot changed the title Add rcp14 sigmoid/silu primitives with fVec wrappers in vec.h Optimize CPU sigmoid/SiLU with AVX512 rcp14 fast paths Jul 15, 2026
@mingfeima mingfeima closed this Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants