okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
86bed1c92
main
1// src/kernels/cuda/kv_stream.cu - see include/strata/kernels/kv_stream.hpp. 2#define DPCT_PROFILING_ENABLED 3#include <sycl/sycl.hpp> 4#include "strata/kprof.hpp" 5#include <dpct/dpct.hpp> 6#include "strata/sycl_queue.hpp" 7#include "strata/kernels/kv_stream.hpp" 8#include "strata/kernels/kv_q4.hpp" 9#include "strata/kernels/kv_q8.hpp" 10 11#include <algorithm> 12#include <cstdio> 13#include <cstdlib> 14#include <cmath> 15 16namespace strata::kernels { 17namespace { 18 19void check (const char * what ) { 20/* 21DPCT1010: SYCL uses exceptions to report errors and does not use the 22error codes. The cudaGetLastError function call was replaced with 0. You 23need to rewrite this code. 24*/ 25const dpct::err0 e = 0 ; 26} 27 28constexpr int RT = 1024 ;// the resolve block 29 30// The per-block byte runs of the (up to four) pool arrays: block b of array i is bytes [b * len, (b + 1) * len). 31struct Runs { 32const uint8_t * src [4 ]; 33uint8_t * dst [4 ]; 34int len [4 ]; 35int n ; 36}; 37 38Runs runs_of (const QsaAttnPools & slots ,const KvHostPools & host ,int fmt ,const QsaShapes & s ) { 39const int rows = (int ) (s .n_head_kv * s .page_size ); 40Runs r {}; 41if (fmt == kKvHybrid ) {// K8V4: int8 K codes, their scales, rotated q4_0 V 42const int codes = rows * (int )s .head_dim ,scales = rows * (int ) (s .head_dim /KV_Q8_GROUP )* 2 ; 43const int v = rows * (int )kv_q4_bytes_per_head ((int )s .head_dim ); 44r .src [0 ]= (const uint8_t * )host .k_q ;r .dst [0 ]= (uint8_t * )slots .k_q ;r .len [0 ]= codes ; 45r .src [1 ]= (const uint8_t * )host .k_scale ;r .dst [1 ]= (uint8_t * )slots .k_scale ;r .len [1 ]= scales ; 46r .src [2 ]= (const uint8_t * )host .v_q4 ;r .dst [2 ]= (uint8_t * )slots .v_q4 ;r .len [2 ]= v ; 47r .n = 3 ; 48 }else if (fmt == kKvQ4 ) { 49const int bytes = rows * (int )kv_q4_bytes_per_head ((int )s .head_dim ); 50r .src [0 ]= (const uint8_t * )host .k_q4 ;r .dst [0 ]= (uint8_t * )slots .k_q4 ;r .len [0 ]= bytes ; 51r .src [1 ]= (const uint8_t * )host .v_q4 ;r .dst [1 ]= (uint8_t * )slots .v_q4 ;r .len [1 ]= bytes ; 52r .n = 2 ; 53 }else if (fmt == kKvInt8 ) { 54const int codes = rows * (int )s .head_dim ,scales = rows * (int ) (s .head_dim /KV_Q8_GROUP )* 2 ; 55r .src [0 ]= (const uint8_t * )host .k_q ;r .dst [0 ]= (uint8_t * )slots .k_q ;r .len [0 ]= codes ; 56r .src [1 ]= (const uint8_t * )host .v_q ;r .dst [1 ]= (uint8_t * )slots .v_q ;r .len [1 ]= codes ; 57r .src [2 ]= (const uint8_t * )host .k_scale ;r .dst [2 ]= (uint8_t * )slots .k_scale ;r .len [2 ]= scales ; 58r .src [3 ]= (const uint8_t * )host .v_scale ;r .dst [3 ]= (uint8_t * )slots .v_scale ;r .len [3 ]= scales ; 59r .n = 4 ; 60 }else { 61const int bytes = rows * (int )s .head_dim * 2 ; 62r .src [0 ]= (const uint8_t * )host .k_pool ;r .dst [0 ]= (uint8_t * )slots .k_pool ;r .len [0 ]= bytes ; 63r .src [1 ]= (const uint8_t * )host .v_pool ;r .dst [1 ]= (uint8_t * )slots .v_pool ;r .len [1 ]= bytes ; 64r .n = 2 ; 65 } 66return r ; 67} 68 69// Block-wide exclusive prefix sum of one int per thread (RT threads); `total` is the sum over the block. 70inline int block_scan (int v ,int * warp_sums ,int & total ) { 71auto item_ct1 = sycl::ext::oneapi::this_work_item::get_nd_item < 3 > (); 72const int lane = item_ct1 .get_local_id (2 )& 31 , 73w = item_ct1 .get_local_id (2 ) >>5 ; 74int x = v ; 75for (int o = 1 ;o < 32 ;o <<=1 ) { 76/* 77DPCT1108: '__shfl_up_sync' was migrated with the experimental feature 78masked sub_group function which may not be supported by all compilers or 79runtimes. You may need to adjust the code. 80*/ 81const int y = dpct::experimental::shift_sub_group_right ( 820xffffffffu , sycl::ext::oneapi::this_work_item::get_sub_group (),x , 83o ); 84if (lane >=o )x += y ; 85 } 86if (lane == 31 )warp_sums [w ]= x ; 87/* 88DPCT1065: Consider replacing sycl::nd_item::barrier() with 89sycl::nd_item::barrier(sycl::access::fence_space::local_space) for better 90performance if there is no access to global memory. 91*/ 92item_ct1 .barrier (); 93if (w == 0 ) { 94int t = warp_sums [lane ]; 95for (int o = 1 ;o < 32 ;o <<=1 ) { 96/* 97DPCT1108: '__shfl_up_sync' was migrated with the experimental 98feature masked sub_group function which may not be supported by all 99compilers or runtimes. You may need to adjust the code. 100*/ 101const int y = dpct::experimental::shift_sub_group_right ( 1020xffffffffu , sycl::ext::oneapi::this_work_item::get_sub_group (), 103t ,o ); 104if (lane >=o )t += y ; 105 } 106warp_sums [lane ]= t ; 107 } 108/* 109DPCT1065: Consider replacing sycl::nd_item::barrier() with 110sycl::nd_item::barrier(sycl::access::fence_space::local_space) for better 111performance if there is no access to global memory. 112*/ 113item_ct1 .barrier (); 114total = warp_sums [31 ]; 115const int excl = x - v + (w > 0 ?warp_sums [w - 1 ] :0 ); 116/* 117DPCT1065: Consider replacing sycl::nd_item::barrier() with 118sycl::nd_item::barrier(sycl::access::fence_space::local_space) for better 119performance if there is no access to global memory. 120*/ 121item_ct1 .barrier (); 122return excl ; 123} 124 125__dpct_inline__ void resolve_kernel (KvStreamMap m , 126const int32_t * __restrict__ids , 127const int32_t * __restrict__steps ,int n_q , 128int cap ,int page_size ) { 129auto item_ct1 = sycl::ext::oneapi::this_work_item::get_nd_item < 3 > (); 130auto & s_nmiss = * sycl::ext::oneapi::group_local_memory_for_overwrite < int > ( 131 sycl::ext::oneapi::this_work_item::get_work_group < 3 > ()); 132auto & s_lookups = * sycl::ext::oneapi::group_local_memory_for_overwrite < int > ( 133 sycl::ext::oneapi::this_work_item::get_work_group < 3 > ()); 134auto & s_cut = * sycl::ext::oneapi::group_local_memory_for_overwrite < int > ( 135 sycl::ext::oneapi::this_work_item::get_work_group < 3 > ()); 136auto & warp_sums = 137* sycl::ext::oneapi::group_local_memory_for_overwrite < int [32 ]> ( 138 sycl::ext::oneapi::this_work_item::get_work_group < 3 > ()); 139const int epoch = m .ctl [0 ]+ 1 ; 140if (item_ct1 .get_local_id (2 )== 0 ) {s_nmiss = 0 ;s_lookups = 0 ; } 141/* 142DPCT1065: Consider replacing sycl::nd_item::barrier() with 143sycl::nd_item::barrier(sycl::access::fence_space::local_space) for better 144performance if there is no access to global memory. 145*/ 146item_ct1 .barrier (); 147// 1. hits take this epoch and their reference bit; a missing block is claimed exactly once (-1 -> -2) 148int lookups = 0 ; 149for (int q = 0 ;q < n_q ;++ q ) { 150const int width = steps [q * kStepCount + kStepWidth ]; 151const int32_t * qi = ids + (long long )q * cap ; 152for (int i = item_ct1 .get_local_id (2 );i < width ;i += RT ) { 153const int b = qi [i ] /page_size ; 154if (i > 0 && qi [i - 1 ] /page_size == b )continue ;// ids are ascending: one lookup per block 155++ lookups ; 156const int sl = m .page_table [b ]; 157if (sl >=0 ) { 158m .slot_stamp [sl ]= epoch ; 159m .slot_ref [sl ]= 1 ; 160 }else if (sl == -1 && 161 dpct::atomic_compare_exchange_strong < 162 sycl::access::address_space::generic_space > ( 163& m .page_table [b ],-1 ,-2 )== -1 ) { 164m .miss_block [dpct::atomic_fetch_add < 165 sycl::access::address_space::generic_space > (& s_nmiss ,1 )]= 166b ; 167 } 168 } 169 } 170if (lookups > 0 ) 171 dpct::atomic_fetch_add < sycl::access::address_space::generic_space > ( 172& s_lookups ,lookups );// (#783, stuchapin909) most threads see none: 173// skip the shared atomic 174/* 175DPCT1065: Consider replacing sycl::nd_item::barrier() with 176sycl::nd_item::barrier(sycl::access::fence_space::local_space) for better 177performance if there is no access to global memory. 178*/ 179item_ct1 .barrier (); 180// 2. one victim per miss: a clock sweep from the hand. A slot this call uses (stamp == epoch) is never taken; 181// a referenced one loses its bit as the hand passes it and is taken on the next pass. 182const int need = s_nmiss ,n = (int )m .n_slots ; 183int hand = m .ctl [1 ],got = 0 ; 184for (int scanned = 0 ;got < need && scanned < 3 * n ;scanned += RT ) { 185const int j = (int )(((long long )hand + item_ct1 .get_local_id (2 )) %n ); 186const bool mine = m .slot_stamp [j ]== epoch ; 187const bool cand = !mine && (m .slot_block [j ]< 0 || m .slot_ref [j ]== 0 ); 188int total = 0 ; 189const int rank = block_scan (cand ?1 :0 ,warp_sums ,total ); 190const int want = need - got ; 191if (item_ct1 .get_local_id (2 )== 0 )s_cut = RT ; 192/* 193DPCT1118: SYCL group functions and algorithms must be encountered in 194converged control flow. You may need to adjust the code. 195*/ 196/* 197DPCT1065: Consider replacing sycl::nd_item::barrier() with 198sycl::nd_item::barrier(sycl::access::fence_space::local_space) for 199better performance if there is no access to global memory. 200*/ 201item_ct1 .barrier (); 202if (cand && rank == want - 1 )s_cut = 203item_ct1 .get_local_id (2 )+ 2041 ;// the hand stops just past the last slot taken 205/* 206DPCT1118: SYCL group functions and algorithms must be encountered in 207converged control flow. You may need to adjust the code. 208*/ 209/* 210DPCT1065: Consider replacing sycl::nd_item::barrier() with 211sycl::nd_item::barrier(sycl::access::fence_space::local_space) for 212better performance if there is no access to global memory. 213*/ 214item_ct1 .barrier (); 215const int cut = s_cut ; 216if (cand && rank < want ) { 217m .miss_slot [got + rank ]= j ; 218m .slot_stamp [j ]= epoch ;// taken: a sweep that wraps around must not take it twice 219 }else if (item_ct1 .get_local_id (2 )< cut && !mine ) { 220m .slot_ref [j ]= 0 ; 221 } 222got += total < want ?total :want ; 223hand = (int ) (((long long )hand + cut ) %n ); 224/* 225DPCT1118: SYCL group functions and algorithms must be encountered in 226converged control flow. You may need to adjust the code. 227*/ 228/* 229DPCT1065: Consider replacing sycl::nd_item::barrier() with 230sycl::nd_item::barrier(sycl::access::fence_space::local_space) for 231better performance if there is no access to global memory. 232*/ 233item_ct1 .barrier (); 234 } 235// 3. re-point the table; the copy kernel fills the slots 236const int placed = got < need ?got :need ; 237for (int k = item_ct1 .get_local_id (2 );k < need ;k += RT ) { 238const int b = m .miss_block [k ]; 239if (k >=placed ) {m .page_table [b ]= -1 ;continue ; }// overflow: never happens with a legal n_slots 240const int sl = m .miss_slot [k ]; 241const int old = m .slot_block [sl ]; 242if (old >=0 )m .page_table [old ]= -1 ; 243m .slot_block [sl ]= b ; 244m .slot_stamp [sl ]= epoch ; 245m .slot_ref [sl ]= 1 ; 246m .page_table [b ]= sl ; 247 } 248if (item_ct1 .get_local_id (2 )== 0 ) { 249m .ctl [0 ]= epoch ; 250m .ctl [1 ]= hand ; 251m .ctl [2 ]= placed ; 252if (placed < need )m .ctl [3 ]= 1 ; 253unsigned long long * c = reinterpret_cast < unsigned long long *> (m .ctl + 4 ); 254c [0 ]+= (unsigned long long )placed ; 255c [1 ]+= (unsigned long long )s_lookups ; 256c [2 ]+= 1ull ; 257 } 258} 259 260// One block per missed block (grid-stride): copy its runs from the host copy into its slot, 16 B per thread. 261__dpct_inline__ void copy_kernel (KvStreamMap m ,Runs r ) { 262auto item_ct1 = sycl::ext::oneapi::this_work_item::get_nd_item < 3 > (); 263const int need = m .ctl [2 ]; 264for (int k = item_ct1 .get_group (2 );k < need ; 265k += item_ct1 .get_group_range (2 )) { 266const long long b = m .miss_block [k ],sl = m .miss_slot [k ]; 267for (int a = 0 ;a < r .n ;++ a ) { 268const sycl::uint4 * src = 269reinterpret_cast < const sycl::uint4 *> (r .src [a ]+ b * r .len [a ]); 270 sycl::uint4 * dst = 271reinterpret_cast < sycl::uint4 *> (r .dst [a ]+ sl * r .len [a ]); 272#pragma unroll 273for (int i = item_ct1 .get_local_id (2 );i < r .len [a ] /16 ; 274i += item_ct1 .get_local_range (2 ))dst [i ]= src [i ]; 275 } 276 } 277} 278 279__dpct_inline__ void reset_kernel (KvStreamMap m ) { 280auto item_ct1 = sycl::ext::oneapi::this_work_item::get_nd_item < 3 > (); 281const long long i0 = (long long )item_ct1 .get_group (2 )* 282item_ct1 .get_local_range (2 )+ 283item_ct1 .get_local_id (2 ), 284st = (long long )item_ct1 .get_group_range (2 )* 285item_ct1 .get_local_range (2 ); 286#pragma unroll 287for (long long i = i0 ;i < m .n_blocks ;i += st )m .page_table [i ]= -1 ; 288#pragma unroll 289for (long long i = i0 ;i < m .n_slots ;i += st ) { 290m .slot_block [i ]= -1 ; 291m .slot_stamp [i ]= -1 ; 292m .slot_ref [i ]= 0 ; 293 } 294if (i0 < kKvCtlInts )m .ctl [i0 ]= 0 ; 295} 296 297__dpct_inline__ void ring_kernel (int32_t * table ,long long n_blocks , 298long long n_slots ) { 299auto item_ct1 = sycl::ext::oneapi::this_work_item::get_nd_item < 3 > (); 300#pragma unroll 301for (long long i = 302 (long long )item_ct1 .get_group (2 )* item_ct1 .get_local_range (2 )+ 303item_ct1 .get_local_id (2 ); 304i < n_blocks ;i += (long long )item_ct1 .get_group_range (2 )* 305item_ct1 .get_local_range (2 )) 306table [i ]= (int32_t ) (i %n_slots ); 307} 308 309}// namespace 310 311uint64_t kv_block_bytes (const QsaShapes & s ,int fmt ) { 312const uint64_t rows = (uint64_t ) (s .n_head_kv * s .page_size ); 313if (fmt == kKvHybrid ) 314return rows * (uint64_t )s .head_dim + rows * (uint64_t ) (s .head_dim /KV_Q8_GROUP )* 2 + 315rows * kv_q4_bytes_per_head ((int )s .head_dim ); 316if (fmt == kKvQ4 )return rows * kv_q4_bytes_per_head ((int )s .head_dim )* 2 ; 317return fmt == kKvInt8 ?rows * (uint64_t )s .head_dim * 2 + rows * (uint64_t ) (s .head_dim /KV_Q8_GROUP )* 2 * 2 318 :rows * (uint64_t )s .head_dim * 2 * 2 ; 319} 320 321void kv_stream_reset (const KvStreamMap & m ,void * stream ) { 322 { 323auto exp_props = sycl::ext::oneapi::experimental::properties { 324 sycl::ext::oneapi::experimental::use_root_sync }; 325 326 strata::kprof::kp (strata::q_of (stream ),__FILE__ ,__func__ ,__LINE__ ) 327-> template parallel_for < dpct_kernel_name < class reset_kernel_f02a82 >> ( 328 sycl::nd_range < 3 > (sycl::range (1 ,1 ,128 )* 329 sycl::range (1 ,1 ,256 ), 330 sycl::range (1 ,1 ,256 )), 331exp_props , [= ](sycl::nd_item < 3 > item_ct1 ) { 332reset_kernel (m ); 333 }); 334 } 335check ("reset" ); 336} 337 338void kv_stream_resolve (const KvStreamMap & m ,const QsaAttnPools & slots ,const KvHostPools & host ,int fmt , 339const int32_t * ids ,const int32_t * steps ,int64_t n_q ,int64_t cap ,const QsaShapes & s , 340void * stream ) { 341if (n_q <=0 )return ; 342if (s .n_head_kv * s .page_size * (s .head_dim /KV_Q8_GROUP )* 2 %16 != 0 ) { 343 std::fprintf (stderr ,"kv_stream: a block's scale run must be a multiple of 16 bytes\n" ); 344 std::exit (1 ); 345 } 346// one sweep step looks at RT consecutive slots `(hand + thread) % n_slots`; with fewer slots than RT two 347// threads see the same slot and may both take it for two different misses. The engine never streams with fewer 348// than qsa_kv_resident_min() / page_size = 5,120 slots, so this is a guard, not a limit. 349if (m .n_slots < RT ) { 350 std::fprintf (stderr ,"kv_stream: %lld slots is fewer than the resolve block (%d): the clock sweep would take a " 351"slot twice\n" , (long long )m .n_slots ,RT ); 352 std::exit (1 ); 353 } 354/* 355DPCT1049: The work-group size passed to the SYCL kernel may exceed the 356limit. To get the device limit, query info::device::max_work_group_size. 357Adjust the work-group size if needed. 358*/ 359 { 360auto exp_props = sycl::ext::oneapi::experimental::properties { 361 sycl::ext::oneapi::experimental::use_root_sync }; 362 363 strata::kprof::kp (strata::q_of (stream ),__FILE__ ,__func__ ,__LINE__ ) 364-> template parallel_for < dpct_kernel_name < class resolve_kernel_148a81 >> ( 365 sycl::nd_range < 3 > (sycl::range (1 ,1 ,RT ), sycl::range (1 ,1 ,RT )), 366exp_props , 367 [= ](sycl::nd_item < 3 > item_ct1 ) 368 [[sycl ::reqd_sub_group_size (32 )]] { 369resolve_kernel (m ,ids ,steps , (int )n_q , (int )cap , 370 (int )s .page_size ); 371 }); 372 } 373check ("resolve" ); 374 { 375auto exp_props = sycl::ext::oneapi::experimental::properties { 376 sycl::ext::oneapi::experimental::use_root_sync }; 377 378 strata::kprof::kp (strata::q_of (stream ),__FILE__ ,__func__ ,__LINE__ ) 379-> submit ([& ](sycl::handler & cgh ) { 380auto runs_of_slots_host_fmt_s_ct1 = 381runs_of (slots ,host ,fmt ,s ); 382 383cgh .parallel_for < dpct_kernel_name < class copy_kernel_4bb253 >> ( 384 sycl::nd_range < 3 > (sycl::range (1 ,1 ,96 )* 385 sycl::range (1 ,1 ,128 ), 386 sycl::range (1 ,1 ,128 )), 387exp_props , [= ](sycl::nd_item < 3 > item_ct1 ) { 388copy_kernel (m ,runs_of_slots_host_fmt_s_ct1 ); 389 }); 390 }); 391 } 392check ("copy" ); 393} 394 395void kv_ring_table (int32_t * page_table ,int64_t n_blocks ,int64_t n_slots ,void * stream ) { 396 { 397auto exp_props = sycl::ext::oneapi::experimental::properties { 398 sycl::ext::oneapi::experimental::use_root_sync }; 399 400 strata::kprof::kp (strata::q_of (stream ),__FILE__ ,__func__ ,__LINE__ ) 401-> template parallel_for < dpct_kernel_name < class ring_kernel_f9df1d >> ( 402 sycl::nd_range < 3 > (sycl::range (1 ,1 ,64 )* 403 sycl::range (1 ,1 ,256 ), 404 sycl::range (1 ,1 ,256 )), 405exp_props , [= ](sycl::nd_item < 3 > item_ct1 ) { 406ring_kernel (page_table ,n_blocks ,n_slots ); 407 }); 408 } 409check ("ring table" ); 410} 411 412void kv_ring_restore (const QsaAttnPools & slots ,const KvHostPools & host , 413int fmt ,int64_t b0 ,int64_t b1 ,int64_t n_slots , 414const QsaShapes & s ,void * stream )try { 415const Runs r = runs_of (slots ,host ,fmt ,s ); 416for (int64_t b = b0 ;b < b1 ;) { 417const int64_t sl = b %n_slots ,run = std::min < int64_t > (b1 - b ,n_slots - sl );// up to the ring's end 418for (int a = 0 ;a < r .n ;++ a ) 419/* 420DPCT1124: cudaMemcpyAsync is migrated to asynchronous memcpy 421API. While the origin API might be synchronous, it depends on the 422type of operand memory, so you may need to call wait() on event 423return by memcpy API to ensure synchronization behavior. 424*/ 425if (DPCT_CHECK_ERROR (strata::q_of (stream )-> memcpy ( 426r .dst [a ]+ sl * r .len [a ],r .src [a ]+ b * r .len [a ], 427 (size_t )(run * r .len [a ])))!= 0 ) 428check ("ring restore" ); 429b += run ; 430 } 431} 432catch (sycl::exception const & exc ) { 433 std::cerr <<exc .what () <<"Exception caught at file:" <<__FILE__ 434 <<", line:" <<__LINE__ << std::endl ; 435 std::exit (1 ); 436} 437 438void kv_stage_from_host (const QsaAttnPools & stage ,const KvHostPools & host , 439int fmt ,int64_t n_blocks ,const QsaShapes & s , 440void * stream )try { 441if (n_blocks <=0 )return ; 442const Runs r = runs_of (stage ,host ,fmt ,s ); 443for (int a = 0 ;a < r .n ;++ a ) 444/* 445DPCT1124: cudaMemcpyAsync is migrated to asynchronous memcpy API. 446While the origin API might be synchronous, it depends on the type of 447operand memory, so you may need to call wait() on event return by memcpy 448API to ensure synchronization behavior. 449*/ 450if (DPCT_CHECK_ERROR (strata::q_of (stream )-> memcpy ( 451r .dst [a ],r .src [a ], (size_t )(n_blocks * r .len [a ])))!= 0 ) 452check ("stage" ); 453} 454catch (sycl::exception const & exc ) { 455 std::cerr <<exc .what () <<"Exception caught at file:" <<__FILE__ 456 <<", line:" <<__LINE__ << std::endl ; 457 std::exit (1 ); 458} 459 460void kv_unstage_to_host (const QsaAttnPools & stage ,const KvHostPools & host , 461int fmt ,int64_t b0 ,int64_t b1 ,const QsaShapes & s , 462void * stream )try { 463if (b1 <=b0 )return ; 464const Runs r = runs_of (stage ,host ,fmt ,s );// src: the host copy, dst: the staging pool (identity layout both) 465for (int a = 0 ;a < r .n ;++ a ) 466/* 467DPCT1124: cudaMemcpyAsync is migrated to asynchronous memcpy API. 468While the origin API might be synchronous, it depends on the type of 469operand memory, so you may need to call wait() on event return by memcpy 470API to ensure synchronization behavior. 471*/ 472if (DPCT_CHECK_ERROR (strata::q_of (stream )-> memcpy ( 473 (void * )(r .src [a ]+ b0 * r .len [a ]),r .dst [a ]+ b0 * r .len [a ], 474 (size_t )((b1 - b0 )* r .len [a ])))!= 0 ) 475check ("unstage" ); 476} 477catch (sycl::exception const & exc ) { 478 std::cerr <<exc .what () <<"Exception caught at file:" <<__FILE__ 479 <<", line:" <<__LINE__ << std::endl ; 480 std::exit (1 ); 481} 482 483KvStreamCounters kv_stream_counters (const KvStreamMap & m )try { 484int32_t c [kKvCtlInts ]= {}; 485KvStreamCounters r ; 486if (m .ctl == nullptr || 487DPCT_CHECK_ERROR ( 488 dpct::get_in_order_queue ().memcpy (c ,m .ctl ,sizeof (c )).wait ())!= 4890 )return r ; 490const unsigned long long * u = reinterpret_cast < const unsigned long long *> (c + 4 ); 491r .misses = u [0 ]; 492r .lookups = u [1 ]; 493r .calls = u [2 ]; 494r .overflow = c [3 ]!= 0 ; 495return r ; 496} 497catch (sycl::exception const & exc ) { 498 std::cerr <<exc .what () <<"Exception caught at file:" <<__FILE__ 499 <<", line:" <<__LINE__ << std::endl ; 500 std::exit (1 ); 501} 502 503}// namespace strata::kernels