Documentation

Hesper.WGSL.Exp

Type-safe WGSL expressions using GADTs (Generalized Algebraic Data Types). The type parameter ensures that operations are only valid for compatible types.

Type-safe WGSL expressions. The type parameter t : WGSLType ensures compile-time type safety.

Instances For

    Convert Float to WGSL literal string with full precision. Uses scientific notation (e.g. 1.0e-7) when needed to preserve significant digits. FP32 has ~7 significant decimal digits.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      partial def Hesper.WGSL.Exp.toWGSL {t : WGSLType} :
      Exp tString

      Code generation: convert expression to WGSL string

      Operator overloading for ergonomic Exp construction #

      These instances let kernel code use +, -, *, /, %, <, ==, &&& (bit-and), ||| (bit-or), <<< (shift-left), >>> (shift-right) on Exp ty values directly, instead of Exp.add, Exp.mul, etc. Closes one of the major cognitive gaps when porting kernels from CUDA C++: q + k * scale reads the same in CUDA and ShaderM.

      Exp.add q k style still works — the operator is sugar, not a replacement.

      Numeric literals in Exp context: (0 : Exp (.scalar .u32)) becomes Exp.litU32 0, (0 : Exp (.scalar .i32)) becomes Exp.litI32 0. For f32 / f16 literals use Exp.litF32 0.0 directly (Lean's OfScientific interaction with Float-typed Exp is fragile; explicit wrapper avoids surprises).

      Equations

      Bit ops: &&& = bitwise AND, ||| = bitwise OR. Names match Lean's standard &&& / ||| for u32/i32.

      Equations

      Mixed-arity arithmetic with Lean literals. Allows pos + 1 instead of Exp.add pos (Exp.litU32 1), 2 * dPair instead of Exp.mul (Exp.litU32 2) dPair, x * 0.5 (f32) instead of Exp.mul x (Exp.litF32 0.5), etc. Available for u32 + Nat (both directions) and f32 + Float (both directions). Matches the Hesper convention that kernel arithmetic keeps the typed Exp _ wrapper visible at every site so PTX lowering can pick the right instruction.

      Equations

      Allow shifting by a Lean Nat literal: x >>> 3 instead of x >>> Exp.litU32 3. Same for <<<.

      Equations
      • One or more equations did not get rendered due to their size.
      Equations
      • One or more equations did not get rendered due to their size.

      Sentinel constants (Step 9f) #

      Common literals that appear repeatedly in attention / softmax kernels. Centralising them makes intent explicit and prevents typos like -1.0e30 vs -3.4e38 differing across files.

      Two negInf flavours are exposed:

      u32 literal helpers — for slot-index and lane-mask constants that show up at every call site.

      Equations
      Instances For

        Comparison operators on Exp. Cannot reuse Lean's < / == because those resolve to Bool, not Exp (.scalar .bool). Unicode suffix ("e" for Exp) keeps the operator visually similar to CUDA C++ while signalling that the result is an Exp Bool, not a Lean Bool.

        Usage: kPos <ᵉ splitEnd instead of Exp.lt kPos splitEnd.

        Equations
        Instances For