okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
3fb23b146
main
1// doorbell_store: does the host see a device's store to host USM while the kernel is still running? This is the 2// ring publish of Strata's decode handshake (the GPU rings a sequence number the host polls, and the host answers a 3// flag the GPU spins on). A `volatile`/atomic store is served from the GPU's cache on an Arc (xe) and reaches the 4// host only when the kernel ends; the uncached L1+L3 write hint (strata::sys_store, sycl_doorbell.hpp) reaches memory 5// at once. Build twice and compare: 6// icpx -fsycl -I sycl/include sycl/probe/doorbell_store.cpp -o /tmp/db # uncached write (the fix) 7// icpx -fsycl -DSTRATA_DOORBELL_ATOMIC_STORE -I sycl/include ... -o /tmp/db_atomic # old atomic store 8// On an Arc A770 (xe) the first prints "SAW ... at ~0.2 s" with the kernel running to ~2 s; the second prints 9// "NEVER SAW" and the value appears only at the kernel's end. Exit 0 when the store was seen mid-kernel. 10#include <sycl/sycl.hpp> 11#include <cstdio> 12#include <chrono> 13#include "strata/sycl_doorbell.hpp" 14 15int main () { 16 sycl::queue q {sycl::gpu_selector_v }; 17uint32_t * flag = (uint32_t * ) sycl::malloc_host (sizeof (uint32_t ),q ); 18* flag = 0 ; 19const auto t0 = std::chrono::steady_clock::now (); 20q .submit ([& ](sycl::handler & h ) { 21h .single_task ([= ]() { 22for (volatile long i = 0 ;i < 1000000 ;i ++ ) {}// ~0.2 s before the publish 23 strata::sys_store (flag ,12345u ); 24for (volatile long i = 0 ;i < 10000000 ;i ++ ) {}// ~2 s more running after the publish 25 }); 26 }); 27uint32_t v = 0 ; 28double seen_ms = -1.0 ; 29while (std::chrono::steady_clock::now ()- t0 < std::chrono::seconds (6 )) { 30v = * flag ; 31if (v == 12345u ) {seen_ms = std::chrono::duration < double , std::milli > (std::chrono::steady_clock::now ()- t0 ).count ();break ; } 32 } 33q .wait (); 34const double end_ms = std::chrono::duration < double , std::milli > (std::chrono::steady_clock::now ()- t0 ).count (); 35#ifdef STRATA_DOORBELL_ATOMIC_STORE 36const char * label = "ATOMIC_STORE " ; 37#else 38const char * label = "UNCACHED_WRITE" ; 39#endif 40 std::printf ("%s: host %s flag=%u at %.1f ms; kernel ended at %.1f ms\n" ,label , 41seen_ms >=0 ?"SAW" :"NEVER SAW" ,v ,seen_ms ,end_ms ); 42return (seen_ms >=0 && seen_ms < end_ms - 100.0 ) ?0 :3 ;// seen well before the kernel ended 43}