diff options
| author | Jay Kwak <82421531+jkwak-work@users.noreply.github.com> | 2025-05-01 00:14:24 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-01 00:14:24 -0700 |
| commit | 15fce7c8f11985be5ac1fdb1f180a30150e9db89 (patch) | |
| tree | dc801f723860b852a7fb8966de8e8d22bb825723 /tests/wasm/smoke/rand_float.slang | |
| parent | a8d7bb9f781fd77080f07bfaab54fbbcf3a3686d (diff) | |
Smoke test WASM as a part of CI (#6969)
* Simplify build of slang-wasm
* Add smoke-test for slang-wasm in ci
* Avoid git-clone playground
Diffstat (limited to 'tests/wasm/smoke/rand_float.slang')
| -rw-r--r-- | tests/wasm/smoke/rand_float.slang | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/wasm/smoke/rand_float.slang b/tests/wasm/smoke/rand_float.slang new file mode 100644 index 000000000..732cff093 --- /dev/null +++ b/tests/wasm/smoke/rand_float.slang @@ -0,0 +1,63 @@ +// Hybrid Tausworthe PRNG +// +// Code adapted from: https://indico.cern.ch/event/93877/papers/2118070/files/4416-acat3.pdf (See document for license) +// + +uniform float seed; +RWStructuredBuffer<float> outputBuffer; + +uint seedPerThread(uint idx) +{ + return ((uint)idx + (uint)(seed * 1000000)) * 1099087573UL; +} + +uint tauStep(uint z, uint s1, uint s2, uint s3, uint M) +{ + uint b = (((z << s1) ^ z) >> s2); + return (((z & M) << s3) ^ b); +} + +[shader("compute")] +[numthreads(64, 1, 1)] +void computeMain(uint2 dispatchThreadId : SV_DispatchThreadID) +{ + uint idx = dispatchThreadId.x; + uint val = ((uint)idx) * 1099087573UL + ((uint)seed) * 12003927; + + uint z = tauStep(val, 13, 19, 12, 4294967294); + z = tauStep(z, 2, 25, 4, 4294967288); + z = tauStep(z, 3, 11, 17, 4294967280); + + uint z1, z2, z3, z4; + uint r0, r1, r2, r3; + + // STEP 1 + uint _seed = seedPerThread(idx); + z1 = tauStep(_seed, 13, 19, 12, 429496729UL); + z2 = tauStep(_seed, 2, 25, 4, 4294967288UL); + z3 = tauStep(_seed, 3, 11, 17, 429496280UL); + z4 = (1664525 * _seed + 1013904223UL); + r0 = (z1 ^ z2 ^ z3 ^ z4); + // STEP 2 + z1 = tauStep(r0, 13, 19, 12, 429496729UL); + z2 = tauStep(r0, 2, 25, 4, 4294967288UL); + z3 = tauStep(r0, 3, 11, 17, 429496280UL); + z4 = (1664525 * r0 + 1013904223UL); + r1 = (z1 ^ z2 ^ z3 ^ z4); + // STEP 3 + z1 = tauStep(r1, 13, 19, 12, 429496729UL); + z2 = tauStep(r1, 2, 25, 4, 4294967288UL); + z3 = tauStep(r1, 3, 11, 17, 429496280UL); + z4 = (1664525 * r1 + 1013904223UL); + r2 = (z1 ^ z2 ^ z3 ^ z4); + // STEP 4 + z1 = tauStep(r2, 13, 19, 12, 429496729UL); + z2 = tauStep(r2, 2, 25, 4, 4294967288UL); + z3 = tauStep(r2, 3, 11, 17, 429496280UL); + z4 = (1664525 * r2 + 1013904223UL); + r3 = (z1 ^ z2 ^ z3 ^ z4); + + float u4 = r3 * 2.3283064365387e-10; + + outputBuffer[idx] = u4; +}
\ No newline at end of file |
