okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
150c2394f
main
1// seeds.cpp - TEST-ONLY (OWN-5): strata_noise.hpp against stable-diffusion.cpp's PhiloxRNG over many seeds. 2// seeds <first> <count> <n> [threads] prints one line per seed: seed, fnv64(ours), fnv64(ref), equal 3// Build with -DWITH_REF and -I<dir with sd.cpp's core/rng_philox.hpp> to include the reference; without it only 4// our hashes are printed (for platforms whose own sd.cpp stream differs, compare with the x86 reference list). 5#include <atomic> 6#include <cinttypes> 7#include <cstdio> 8#include <cstdlib> 9#include <thread> 10#include <vector> 11 12#include "strata_noise.hpp" 13#ifdef WITH_REF 14#include "core/rng_philox.hpp" 15#endif 16 17static uint64_t fnvb (const std::vector < float >& v ) { 18const unsigned char * p = (const unsigned char * )v .data (); 19uint64_t h = 1469598103934665603ull ; 20for (size_t i = 0 ;i < v .size ()* 4 ;++ i )h = (h ^p [i ])* 1099511628211ull ; 21return h ; 22} 23 24int main (int argc ,char ** argv ) { 25 std::fprintf (stderr ,"sin exception table (compiled in): %zu entries\n" , strata_noise::sin_exc ().keys .size ()); 26const uint64_t first = std::strtoull (argv [1 ],nullptr ,10 ); 27const uint32_t count = (uint32_t ) std::strtoul (argv [2 ],nullptr ,10 ); 28const uint32_t n = (uint32_t ) std::strtoul (argv [3 ],nullptr ,10 ); 29const int T = argc > 4 ? std::atoi (argv [4 ]) : (int ) std::thread::hardware_concurrency (); 30 std::vector < uint64_t > seeds ; 31for (uint32_t i = 0 ;i < count ;++ i )seeds .push_back (first + i ); 32// edge seeds: the 2^31 random default range end, a 64-bit seed (both key words used), the API maximum 2^62 33for (uint64_t s : {2147483647ull ,4294967295ull ,4294967296ull ,0x123456789abcdefull , (1ull <<62 )})seeds .push_back (s ); 34 std::vector < uint64_t > ho (seeds .size ()),hr (seeds .size ()); 35 std::vector < uint32_t > ndiff (seeds .size ()); 36 std::atomic < size_t > next {0 }; 37 std::vector < std::thread > th ; 38for (int t = 0 ;t < T ;++ t )th .emplace_back ([& ] { 39for (size_t k ; (k = next ++ )< seeds .size ();) { 40 std::vector < float > o = strata_noise::randn (seeds [k ],n ); 41ho [k ]= fnvb (o ); 42#ifdef WITH_REF 43PhiloxRNG r ; 44r .manual_seed (seeds [k ]); 45 std::vector < float > f = r .randn (n ); 46hr [k ]= fnvb (f ); 47uint32_t d = 0 ; 48for (uint32_t i = 0 ;i < n ;++ i )d += strata_noise::fbits (o [i ])!= strata_noise::fbits (f [i ]); 49ndiff [k ]= d ; 50#endif 51 } 52 }); 53for (auto & t :th )t .join (); 54uint64_t all = 1469598103934665603ull ,bad = 0 ; 55for (size_t k = 0 ;k < seeds .size ();++ k ) { 56 std::printf ("%" PRIu64 " %016" PRIx64 " %016" PRIx64 " %u\n" ,seeds [k ],ho [k ],hr [k ],ndiff [k ]); 57for (int b = 0 ;b < 8 ;++ b )all = (all ^ ((ho [k ] >> (8 * b ))& 0xff ))* 1099511628211ull ; 58bad += ndiff [k ]!= 0 ; 59 } 60 std::printf ("SEEDS %zu n %u hash-of-hashes %016" PRIx64 " seeds-with-differences %" PRIu64 "\n" ,seeds .size (),n ,all ,bad ); 61return 0 ; 62}