Repository navigation
Conversation
Three random permutations of the form perm[i] = f(i) for a keyed pseudorandom bijection f, ported from the random-permutations paper: - FeistelPerm: balanced Feistel network (triple32 or multiply-shift round function), cycle-walked to [0, n) - SwapOrNotPerm: Hoang, Morris and Rogaway's swap-or-not cipher - MitchellPerm: Mitchell et al. as in Thrust's thrust::shuffle; "scan" mode (count, DLDFScan, write) gives Thrust's output, "walk" mode cycle-walks in one kernel They share a base class, BijectionPerm: a subclass supplies the WGSL bijection, its bit-exact JS mirror, round keys and a parameters struct; the base provides buffers, the cycle-walking kernel, gather (out[i] = in[f(i)], 64-bit values by default), reference() and validate(). Output is bit-identical to the paper's modules (lavapipe, n from 1 to 2^20, both round functions, gather, both Mitchell modes). random.mjs exports MULHI_WGSL and mulhiJS (the 32x32 high product, which Philox and Mitchell's bijection share). benchmark_node gains feistel, swapornot and mitchell; regression tests and docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015kfNC6id65zEHzuAAH4jtJ
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports the paper's three keyed-bijection permutations (
perm[i] = f(i)) to Gridwise primitives, afterMultisplitPermandShunPerm.FeistelPerm: a balanced Feistel network with atriple32or multiply-shift round function, cycle-walked to[0, n).SwapOrNotPerm: Hoang, Morris and Rogaway's swap-or-not cipher, directly on[0, n).MitchellPerm: Mitchell et al. (ACM TOPC 2022), as NVIDIA Thrust'sthrust::shuffledoes it.mode: "scan"(default) gives Thrust's output in three steps: count, thenDLDFScan, then write. Thrust's single-pass version needs forward progress, which WebGPU doesn't promise.mode: "walk"cycle-walks in one kernel.Shared base class. All three extend a small
BijectionPermclass. A subclass supplies:fn bijection(x);UniformStructthat starts withn.The base provides the buffers, the cycle-walking kernel, gather (
out[i] = in[f(i)], 64-bit values by default),reference()andvalidate().Smaller changes
random.mjsexportsMULHI_WGSLandmulhiJS, which Philox and Mitchell's bijection share.benchmark_node.mjsaddsfeistel,swapornotandmitchell.docs/random-permutations.md.Verification (lavapipe)
Separately: without subgroups on lavapipe,
DLDFScangives wrong output from element 128 on, for example at 256 or 1024 elements. That affectsMitchellPerm's scan mode and the old paper module alike. It looks like the emulated subgroups depending on spin-waits that lavapipe doesn't support. The macOS emulated CI job covers that path.Generated by Claude Code