Source/Packages

Realization.Nvidia.SM86.StreamingAttentionSM86

packages/realizations/cooperative/nvidia-sm86/src/Realization/Nvidia/SM86/StreamingAttentionSM86.alpha

3,230 lines493 declarations193.3 KiBSHA-256 cc0366b3d857

def · lines 2018–2045

sqdCopyTile

Full file
A tile's copies into stage `buffer`: chunk j < 4 K's row r + 16 j, j >= 4 dS^T's row r + 16 (j - 4) (the tile's keys, this block's 64 queries), chunk c, thread 8 r + c (rows 16 apart share the swizzle r % 8), each through pointer pair j % 2 formed just before it, each copy after the previous one's reads; predicated on P1 when `guarded`; then the next tile's offsets, 64 keys on.
2018def sqdCopyTile = (lambda unrestricted seq : Nat . (lambda unrestricted buffer : Nat . (lambda unrestricted guarded : Nat .
2019  (lambda unrestricted tail : (family SM86Program) .
2020  (saFor 8 (lambda unrestricted j : Nat .
2021    (let unrestricted m = (naturalModuloUnchecked j 4) in
2022    (let unrestricted body =
2023          (constructor SM86InstructionBody SM86LoadGlobalToShared (saR sqdStore)
2024            (saU (naturalAdd buffer
2025              (naturalAdd (naturalSelect (naturalLess j 4) 0 sqdTileBytes)
2026                (naturalMultiply m (naturalMultiply 16 sqdRowBytes)))))
2027            (saR (sqdPair (naturalModuloUnchecked j 2))) (saU 0)
2028            (constructor SM86Control SM86ControlValue (byte 15) (constructor SM86YieldMode SM86Continue)
2029              saNone saSB5 (nat-to-byte saWait5) (byte 0))) in
2030    (lambda unrestricted rest : (family SM86Program) .
2031      (saOp (constructor SM86InstructionBody SM86IntegerMultiplyAddWideConstant
2032          (saR (sqdPair (naturalModuloUnchecked j 2)))
2033          (saR (naturalSelect (naturalLess j 4) (sqdKeyOffset m) (sqdScoreOffset m))) (saR saOne)
2034          (byte 0) (saU (naturalSelect (naturalLess j 4) (saArgument 1) (saArgument streamingAttentionQueryFromScoresArgument)))
2035          saPlain)
2036        (nat-eliminate (lambda unrestricted mode : Nat . (family SM86Program))
2037          (saOp body rest)
2038          (lambda unrestricted predecessor : Nat . (lambda unrestricted induction : (family SM86Program) .
2039            (saWhen saP1 body rest)))
2040          guarded))))))
2041  (saFor 4 (lambda unrestricted m : Nat .
2042    (saAddImm (sqdKeyOffset m) (sqdKeyOffset m) (naturalMultiply saTile (naturalMultiply saHeadWidth saHalfBytes))))
2043  (saFor 4 (lambda unrestricted m : Nat .
2044    (saAddImm (sqdScoreOffset m) (sqdScoreOffset m) (naturalMultiply saTile sksScoreGradientRowBytes)))
2045  (sfCommit tail))))))))

The compiler supplied declaration spans and resolved links from this source snapshot. This page does not assert that this file belongs to a checked closure.