okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
5a90e36cb
main
1// Test paired mapped transfers, odd tails, unaligned scalar fallback, and 2// the checksum contracts of all three publish variants over repeated rings. 3#include <sycl/sycl.hpp> 4#include <dpct/dpct.hpp> 5#include "strata/sycl_queue.hpp" 6#include "strata/kernels/elementwise.hpp" 7#include <cstdio> 8#include <cstring> 9#include <vector> 10 11int main () { 12auto & q = * strata::q_of (nullptr ); 13using namespace strata::kernels ; 14constexpr int capacity = 2560 ,k = 10 ,experts = 64 ; 15auto * hx = (float * )strata::host_malloc_polled ((capacity + 4 )* sizeof (float ),q ); 16auto * hi = (int32_t * )strata::host_malloc_polled (k * sizeof (int32_t ),q ); 17auto * hw = (float * )strata::host_malloc_polled (k * sizeof (float ),q ); 18auto * seq = (uint32_t * )strata::host_malloc_polled (64 ,q ); 19auto * dx = sycl::malloc_device < float > (capacity ,q ); 20auto * di = sycl::malloc_device < int32_t > (k ,q ); 21auto * dw = sycl::malloc_device < float > (k ,q ); 22auto * dr = sycl::malloc_device < int32_t > (experts ,q ); 23 std::vector < float > x (capacity ),weights (k ),copied (capacity ); 24 std::vector < int32_t > ids (k ); 25for (int j = 0 ;j < capacity ;++ j )x [j ]= (j %123 - 61 )* 0.25f ; 26for (int j = 0 ;j < k ;++ j ) {ids [j ]= j * 3 ;weights [j ]= (j + 1 )* 0.03125f ; } 27q .memcpy (dx ,x .data (),x .size ()* sizeof (float )); 28q .memcpy (di ,ids .data (),k * sizeof (int32_t )); 29q .memcpy (dw ,weights .data (),k * sizeof (float )); 30q .memset (dr ,0 ,experts * sizeof (int32_t )); 31q .wait_and_throw (); 32int failed = 0 ; 33for (int n : {1 ,3 ,17 ,2559 ,2560 }) 34for (int offset : {0 ,1 }) 35for (int variant = 0 ;variant < 3 ;++ variant ) { 36 std::memset (seq ,0 ,64 ); 37for (uint32_t ring = 1 ;ring <=12 ;++ ring ) { 38 std::memset (hx ,0x7f , (capacity + 4 )* sizeof (float )); 39 std::memset (hi ,0 ,k * sizeof (int32_t )); 40 std::memset (hw ,0 ,k * sizeof (float )); 41if (variant == 0 )doorbell_publish (dx ,di ,dw ,n ,k ,hx + offset ,hi ,hw ,seq ,& q ); 42else if (variant == 1 )doorbell_publish_res (dx ,di ,dr ,experts ,n ,k ,hx + offset ,hi ,seq ,& q ); 43else doorbell_publish_value (dx ,di ,dw ,n ,k ,hx + offset ,hi ,hw ,seq ,ring ,& q ); 44q .wait_and_throw (); 45bool ok = seq [0 ]== ring && !std::memcmp (hx + offset ,x .data (),n * sizeof (float ))&& 46 !std::memcmp (hi ,ids .data (),k * sizeof (int32_t ))&& 47doorbell_payload_ready (seq ,hx + offset ,n ,hi ,hw ,k ,ring ); 48if (variant != 1 )ok = ok && !std::memcmp (hw ,weights .data (),k * sizeof (float )); 49if (!ok ) {++ failed ; std::printf ("FAIL n=%d offset=%d variant=%d ring=%u\n" ,n ,offset ,variant ,ring ); } 50 } 51 } 52 std::memcpy (hx ,x .data (),x .size ()* sizeof (float )); 53copy_from_mapped (dx ,hx ,capacity ,& q ); 54q .memcpy (copied .data (),dx ,capacity * sizeof (float )).wait (); 55if (std::memcmp (copied .data (),x .data (),capacity * sizeof (float )))++ failed ; 56for (void * p : {static_cast < void *> (hx ),static_cast < void *> (hi ),static_cast < void *> (hw ),static_cast < void *> (seq )}) 57 strata::host_free_polled (p ,q ); 58for (void * p : {static_cast < void *> (dx ),static_cast < void *> (di ),static_cast < void *> (dw ),static_cast < void *> (dr )}) sycl::free (p ,q ); 59 std::printf ("paired payload and mapped read: %d failures\n" ,failed ); 60return failed != 0 ; 61}