Skip to main content

Module rope

Module rope 

Source
Expand description

Rotary Position Embedding (RoPE) kernel.

Matches rope-kernel-v1.yaml. Rotate pairs of dimensions by position-dependent angles. theta_k = base^(-2k/d), apply 2D rotation matrix per pair.

RoPE(x, m){2k} = x{2k} * cos(m * theta_k) - x_{2k+1} * sin(m * theta_k) RoPE(x, m){2k+1} = x{2k} * sin(m * theta_k) + x_{2k+1} * cos(m * theta_k)

Each function provides one of three backends:

  • fn rope_scalar(...) — Pure Rust scalar reference (ground truth)
  • unsafe fn rope_avx2(...) — AVX2 SIMD implementation
  • fn rope_ptx() -> &'static str — PTX assembly source string

Functions§

rope_avx2
AVX2 RoPE — delegates to scalar (no hardware sin/cos in AVX2).
rope_ptx
PTX assembly for the RoPE kernel (1 thread per dimension pair).
rope_scalar
Apply Rotary Position Embedding to input vector x.