okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
8f70a52cf
main
1// arena_rw: does a big device arena keep what is copied into it? The engine's expert-cache fill (pinned host batches of 2// 64 blobs, queue.memcpy into odd-sized slots, the arena zeroed by chunked kernels first) read back with 2 MiB pages of the 3// arena holding wrong bytes on an Arc Pro B70 (xe). This reproduces the shape without the engine. 4// arena_rw GIB [slot_bytes=1971200] [batch=64] [zero=1] [verify_after_fill=1] 5#include <sycl/sycl.hpp> 6#include <chrono> 7#include <cstdint> 8#include <cstdio> 9#include <cstdlib> 10#include <cstring> 11#include <vector> 12#include "strata/sycl_queue.hpp" 13 14static inline uint8_t pat (uint64_t off ) { 15uint64_t x = off * 0x9E3779B97F4A7C15ull ; 16x ^=x >>29 ; 17return (uint8_t ) (x >>11 ); 18} 19 20int main (int argc ,char ** argv ) { 21const double gib = argc > 1 ? std::atof (argv [1 ]) :4.0 ; 22const size_t slot = argc > 2 ? (size_t ) std::atoll (argv [2 ]) :1971200 ; 23const size_t batch = argc > 3 ? (size_t ) std::atoll (argv [3 ]) :64 ; 24const int zero = argc > 4 ? std::atoi (argv [4 ]) :1 ; 25const size_t total = (size_t ) (gib * 1073741824.0 ); 26const size_t n_slots = total / ((slot + 255 ) /256 * 256 ); 27const size_t stride = (slot + 255 ) /256 * 256 ; 28 sycl::queue q {sycl::gpu_selector_v , sycl::property::queue::in_order {}}; 29 std::printf ("device %s\n" ,q .get_device ().get_info < sycl::info::device::name > ().c_str ()); 30uint8_t * arena = (uint8_t * ) sycl::malloc_device (n_slots * stride + (2 <<20 ),q ); 31if (!arena ) { std::printf ("alloc failed\n" );return 1 ; } 32arena = (uint8_t * ) (((uintptr_t )arena + (2 <<20 )- 1 )& ~(uintptr_t ) ((2 <<20 )- 1 ));// as the engine's: 2 MiB aligned 33 std::printf ("arena %p, %zu slots of %zu (stride %zu)\n" , (void * )arena ,n_slots ,slot ,stride ); 34if (zero ) strata::big_fill_zero (q ,arena ,n_slots * stride ); 35uint8_t * pin = sycl::malloc_host < uint8_t > (2 * batch * stride ,q ); 36 sycl::event done [2 ]; 37size_t k = 0 ; 38for (size_t b0 = 0 ;b0 < n_slots ;b0 += batch ,++ k ) { 39const size_t n = std::min (batch ,n_slots - b0 ); 40uint8_t * set = pin + (k %2 )* batch * stride ; 41done [k %2 ].wait (); 42for (size_t j = 0 ;j < n ;++ j ) 43for (size_t x = 0 ;x < slot ;++ x )set [j * stride + x ]= pat ((b0 + j )* stride + x ); 44for (size_t j = 0 ;j < n ;++ j )done [k %2 ]= q .memcpy (arena + (b0 + j )* stride ,set + j * stride ,slot ); 45 } 46q .wait (); 47 std::vector < uint8_t > got (stride ); 48size_t bad = 0 ; 49for (size_t i = 0 ;i < n_slots ;++ i ) { 50q .memcpy (got .data (),arena + i * stride ,slot ).wait (); 51size_t nd = 0 ,fd = slot ; 52for (size_t x = 0 ;x < slot ;++ x ) 53if (got [x ]!= pat (i * stride + x )) {++ nd ;if (fd == slot )fd = x ; } 54if (nd ) { 55++ bad ; 56if (bad <=10 ) 57 std::printf ("slot %zu at %p (offset %zu MiB): %zu of %zu bytes differ, first at %zu\n" ,i , (void * ) (arena + i * stride ), 58 (i * stride ) >>20 ,nd ,slot ,fd ); 59 } 60 } 61 std::printf ("%zu of %zu slots differ\n" ,bad ,n_slots ); 62return bad ?3 :0 ; 63}