okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
5af104b51
main
1// src/core/weights.cpp - the dense-weight loader. See the header for the engine-vs-pack distinction. 2#define DPCT_PROFILING_ENABLED 3#include <sycl/sycl.hpp> 4#include <dpct/dpct.hpp> 5#include "strata/core/weights.hpp" 6 7#include "strata/kernels/f16_bits.hpp" 8#include "strata/platform/memory.hpp" 9 10#include <chrono> 11#include <algorithm> 12#include <cstdio> 13#include <cstdlib> 14#include <cstring> 15 16#if defined(_WIN32 ) 17#include <io.h> 18#else 19#include <unistd.h> 20#endif 21 22namespace strata::core { 23namespace { 24 25constexpr uint64_t CHUNK = 8ull <<20 ;// 8 MiB of SOURCE per staging round 26 27double now_ms () { 28using namespace std::chrono ; 29return duration < double , std::milli > (steady_clock::now ().time_since_epoch ()).count (); 30} 31 32struct IndexRow { 33 std::string name ; 34int file = 0 ; 35WeightKind kind = WeightKind ::Verbatim ; 36uint64_t src_off = 0 ,src_bytes = 0 ,dst_off = 0 ,dst_bytes = 0 ; 37int64_t ne0 = 0 ,ne1 = 0 ; 38int code_bits = 0 ,code_bias = 0 ,group_elems = 0 ,codebook = 0 ,has_offset = 0 ; 39uint64_t codes_bytes = 0 ,scales_bytes = 0 ,offset_bytes = 0 ; 40int scales_fp16 = 0 ; 41int act_kind = 0 ; 42bool raw16 = false;///< plan v0.3 P6: already 16-bit in the file (kinds 4/5) 43}; 44 45/// How a segment's bytes must be transformed on the way from the pack to the arena. 46enum class Conv :int { 47Copy = 0 ,///< the bytes are already the engine form 48Bf16High = 1 ,///< f32 container holding a bf16 value: take the high 16 bits 49ToF16 = 2 ,///< f32 container holding an f16 value: a real round-to-nearest-even conversion 50WidenF16 = 3 ,///< fp16 bits to be held as f32: EXACT, and the reason this path exists at all 51}; 52 53/// One contiguous run of a tensor's source span with a single destination range and one transform. 54/// 55/// THE SEGMENT LIST IS WHY THIS LOADER CAN CHANGE WIDTHS PLANE BY PLANE. A quantized tensor used to be one 56/// verbatim span, which is only correct when every plane is already in engine form - and for 90 of the 303 57/// quantized tensors the scale plane is fp16 in the pack and must be f32 in the arena. 58struct Seg { 59uint64_t src_off = 0 ;///< relative to the row's src_off 60uint64_t src_bytes = 0 ; 61uint64_t dst_off = 0 ;///< relative to the row's dst_off 62uint64_t dst_bytes = 0 ; 63Conv conv = Conv ::Copy ; 64}; 65 66const char * file_name (int id ) { 67switch (id ) { 68case 0 :return "dense.bin" ; 69case 1 :return "embd.bin" ; 70case 2 :return "experts.bin" ; 71case 3 :return "extra.bin" ;// plan v0.3 P6: a native pack's float tensors that the base pack quantized 72default :return nullptr ; 73 } 74} 75 76/// UTF-16 path for CreateFile-free portability: the loader uses `std::fopen`, which on Windows takes an ANSI 77/// path. The pack lives beside the executable in practice, but a pack under a user directory with a 78/// non-ASCII name would silently fail to open, so the caller gets the errno rather than a null pointer. 79bool read_at (std::FILE * f ,uint64_t off ,void * dst ,size_t n , std::string & err ,const char * what ) { 80#if defined(_WIN32 ) 81if (_fseeki64 (f , (long long )off ,SEEK_SET )!= 0 ) {err = std::string (what )+ ": seek failed" ;return false; } 82#else 83if (fseeko (f , (off_t )off ,SEEK_SET )!= 0 ) {err = std::string (what )+ ": seek failed" ;return false; } 84#endif 85if (std::fread (dst ,1 ,n ,f )!= n ) {err = std::string (what )+ ": short read" ;return false; } 86return true; 87} 88 89}// namespace 90 91bool WeightTable ::pool_bytes (const std::string & pack_dir ,uint64_t & out , std::string & err , 92const std::set < std::string >* skip ) { 93const std::string path = pack_dir + "/index.txt" ; 94 std::FILE * f = std::fopen (path .c_str (),"rb" ); 95if (!f ) {err = "cannot open " + path ;return false; } 96char line [1024 ]; 97out = 0 ; 98uint64_t pool = 0 ,compact = 0 ; 99int align = 0 ; 100while (std::fgets (line ,sizeof line ,f )) { 101if (line [0 ]== '#' ) { 102unsigned long long p = 0 ; 103int a = 0 ,tensors = 0 ; 104if (std::sscanf (line ,"# align %d pool %llu tensors %d" ,& a ,& p ,& tensors )== 3 ) {pool = p ;align = a ; } 105continue ; 106 } 107if (skip == nullptr )continue ; 108char name [256 ]= {0 }; 109unsigned long long dst_bytes = 0 ,dummy = 0 ; 110int i1 = 0 ,i2 = 0 ; 111if (std::sscanf (line ,"%255s %d %d %llu %llu %llu %llu" ,name ,& i1 ,& i2 ,& dummy ,& dummy ,& dummy ,& dst_bytes )!= 7 ) 112continue ; 113if (skip -> count (name ))continue ; 114const uint64_t a = align > 0 ? (uint64_t )align :256 ; 115compact += (dst_bytes + a - 1 ) /a * a ; 116 } 117 std::fclose (f ); 118if (pool == 0 ) {err = "no '# align ... pool ...' header in " + path ;return false; } 119out = skip ?compact :pool ; 120return true; 121} 122 123bool WeightTable ::index_code_bits (const std::string & pack_dir ,const std::string & name ,int & code_bits , 124 std::string & err ) { 125const std::string path = pack_dir + "/index.txt" ; 126 std::FILE * f = std::fopen (path .c_str (),"rb" ); 127if (!f ) {err = "cannot open " + path ;return false; } 128char line [1024 ]; 129code_bits = -1 ; 130while (std::fgets (line ,sizeof line ,f )) { 131if (line [0 ]== '#' )continue ; 132char row [256 ]= {0 }; 133unsigned long long dummy = 0 ; 134long long ne = 0 ; 135int i1 = 0 ,i2 = 0 ,bits = 0 ; 136// the first ten fields of the row `load` parses: name file kind src_off src_bytes dst_off dst_bytes ne0 ne1 code_bits 137if (std::sscanf (line ,"%255s %d %d %llu %llu %llu %llu %lld %lld %d" ,row ,& i1 ,& i2 ,& dummy ,& dummy ,& dummy , 138& dummy ,& ne ,& ne ,& bits )!= 10 ) 139continue ; 140if (name == row ) {code_bits = bits ;break ; } 141 } 142 std::fclose (f ); 143return true; 144} 145 146bool WeightTable ::load (const std::string & pack_dir ,void * arena_base , 147uint64_t arena_bytes , std::string & err , 148const std::set < std::string > * skip )try { 149const std::string path = pack_dir + "/index.txt" ; 150 std::FILE * idx = std::fopen (path .c_str (),"rb" ); 151if (!idx ) {err = "cannot open " + path + " (run tools/pack_index.py)" ;return false; } 152 153uint64_t pool = 0 ; 154int align = 0 ; 155 std::vector < IndexRow > rows ; 156char line [1024 ]; 157while (std::fgets (line ,sizeof line ,idx )) { 158if (line [0 ]== '#' ) { 159unsigned long long p = 0 ; 160int a = 0 ,t = 0 ; 161if (std::sscanf (line ,"# align %d pool %llu tensors %d" ,& a ,& p ,& t )== 3 ) {pool = p ;align = a ; } 162continue ; 163 } 164IndexRow r ; 165char name [256 ]= {0 }; 166int kind = 0 ; 167// The format is written by tools/pack_index.py and is space-separated with no quoting; a name with a 168// space in it would break the parse, which is why the parser REFUSES rather than taking what it got. 169const int n = std::sscanf (line , 170"%255s %d %d %llu %llu %llu %llu %lld %lld %d %d %d %d %d %llu %llu %llu %d %d" , 171name ,& r .file ,& kind ,& r .src_off ,& r .src_bytes ,& r .dst_off ,& r .dst_bytes , 172& r .ne0 ,& r .ne1 ,& r .code_bits ,& r .code_bias ,& r .group_elems ,& r .codebook , 173& r .has_offset ,& r .codes_bytes ,& r .scales_bytes ,& r .offset_bytes , 174& r .scales_fp16 ,& r .act_kind ); 175if (n != 19 ) { 176// A malformed index line is a WRONG BYTE OFFSET waiting to happen, and a wrong offset decodes to 177// a plausible weight. Refuse loudly instead of loading the rows that happened to parse. 178err = "index.txt: could not parse a row (" + std::to_string (n )+ " of 19 fields)" ; 179 std::fclose (idx ); 180return false; 181 } 182r .name = name ; 183// plan v0.3 P6: a standalone native pack (tools/iq_pack.py) stores 16-bit floats as they are in the GGUF: 184// index kinds 4 (BF16) and 5 (F16) are copied and take the engine forms of kinds 1 and 3 185if (kind == 4 || kind == 5 ) { 186r .raw16 = true; 187kind = kind == 4 ? (int )WeightKind ::Bf16InF32 : (int )WeightKind ::F16InF32 ; 188 } 189r .kind = (WeightKind )kind ; 190rows .push_back (r ); 191 } 192 std::fclose (idx ); 193 194if (pool == 0 || rows .empty ()) {err = "index.txt has no header or no rows" ;return false; } 195// Plan v0.3 P1: a skip set compacts the arena. Kept rows are re-placed in index order at the index's 196// alignment; skipped rows keep their metadata and get no bytes. 197 std::vector < bool > skipped (rows .size (), false); 198if (skip != nullptr ) { 199const uint64_t a = align > 0 ? (uint64_t )align :256 ; 200uint64_t at = 0 ; 201for (size_t i = 0 ;i < rows .size ();++ i ) { 202if (skip -> count (rows [i ].name )) {skipped [i ]= true;continue ; } 203rows [i ].dst_off = at ; 204at += (rows [i ].dst_bytes + a - 1 ) /a * a ; 205 } 206pool = at ; 207 } 208if (arena_bytes < pool ) { 209err = "arena is " + std::to_string (arena_bytes )+ " B but the index needs " + std::to_string (pool ); 210return false; 211 } 212 213// Two pinned staging buffers, both reused. Pinned because a 5 GB pageable upload spends its time in the 214// driver copying through a bounce buffer, and bounded by CHUNK rather than by the largest tensor. 215// 216// STAGE_OUT IS NOT OPTIONAL. The first version of this loop converted the values straight into the 217// destination pointer - which is DEVICE memory - from host code. A host write to a device address is 218// undefined behaviour, and on this driver it does not fault: it corrupts whatever the address maps to in 219// the host's own space, which is nothing at all, so the tensor would have loaded as the UNCONVERTED pack 220// bytes and every BF16 weight would have been read as 32-bit garbage. Converted data goes to a host 221// buffer and crosses the bus once. 222// 223// STAGE_OUT IS TWICE STAGE_IN because a conversion can now GROW: widening an fp16 scale plane to f32 224// doubles it. Sized at CHUNK it would have written 8 MiB past the end of a pinned allocation for every 225// one of the 90 widened tensors - a heap corruption that would have been blamed on whatever ran next. 226void * stage_in = nullptr ; 227void * stage_out = nullptr ; 228/* 229DPCT1048: The original value cudaHostAllocDefault is not meaningful in the 230migrated code and was removed or replaced with 0. You may need to check the 231migrated code. 232*/ 233if (DPCT_CHECK_ERROR (stage_in = (void * )sycl::malloc_host ( 234CHUNK , dpct::get_in_order_queue ()))!= 0 || 235/* 236DPCT1048: The original value cudaHostAllocDefault is not meaningful in 237the migrated code and was removed or replaced with 0. You may need to 238check the migrated code. 239*/ 240DPCT_CHECK_ERROR (stage_out = (void * )sycl::malloc_host ( 241CHUNK * 2 , dpct::get_in_order_queue ()))!= 0 ) { 242err = "cudaHostAlloc for the staging buffers failed" ; 243if (stage_in ) sycl::free (stage_in , dpct::get_in_order_queue ()); 244if (stage_out ) sycl::free (stage_out , dpct::get_in_order_queue ()); 245return false; 246 } 247 248uint8_t * dst_base = (uint8_t * )arena_base ; 249 std::FILE * cur = nullptr ; 250int cur_file = -1 ; 251table_ .clear (); 252report_ = LoadReport {}; 253 254const double t_read0 = now_ms (); 255double upload_ms = 0 ; 256for (size_t row_i = 0 ;row_i < rows .size ();++ row_i ) { 257const IndexRow & r = rows [row_i ]; 258if (skipped [row_i ]) { 259WeightRef wr ; 260wr .data = nullptr ; 261wr .resident = false; 262wr .bytes = r .dst_bytes ; 263wr .ne0 = r .ne0 ; 264wr .ne1 = r .ne1 ; 265wr .elements = r .ne0 * (r .ne1 > 0 ?r .ne1 :1 ); 266wr .kind = r .kind ; 267wr .code_bits = r .code_bits ; 268wr .code_bias = r .code_bias ; 269wr .group_elems = r .group_elems ; 270wr .codebook_iq4nl = r .codebook != 0 ; 271wr .has_offset = r .has_offset != 0 ; 272wr .codes_bytes = r .codes_bytes ; 273wr .scales_bytes = r .scales_bytes ; 274wr .offset_bytes = r .offset_bytes ; 275wr .src_off = r .src_off ; 276wr .src_bytes = r .src_bytes ; 277wr .file_id = r .file ; 278wr .scales_fp16 = r .scales_fp16 != 0 ; 279wr .act_kind = r .act_kind ; 280table_ [r .name ]= wr ; 281++ report_ .tensors ; 282continue ; 283 } 284if (r .code_bits != 0 && r .dst_bytes == 0 ) { 285// plan v0.3 P6: a native pack's row that carries a shape only - the GGUF form must serve it 286err = r .name + ": this pack holds the tensor only in its GGUF form (run with --native SHARD1)" ; 287 sycl::free (stage_in , dpct::get_in_order_queue ()); 288 sycl::free (stage_out , dpct::get_in_order_queue ()); 289return false; 290 } 291if (r .file != cur_file ) { 292if (cur ) std::fclose (cur ); 293const char * fn = file_name (r .file ); 294const std::string p = pack_dir + "/" + (fn ?fn :"?" ); 295cur = std::fopen (p .c_str (),"rb" ); 296if (!cur ) { 297err = "cannot open " + p ; 298 sycl::free (stage_in , dpct::get_in_order_queue ()); 299 sycl::free (stage_out , dpct::get_in_order_queue ()); 300return false; 301 } 302cur_file = r .file ; 303#if !defined(_WIN32 ) 304// ask for this file's remaining rows up front so their reads overlap 305for (size_t j = row_i ;j < rows .size ();++ j ) 306if (rows [j ].file == r .file && !skipped [j ]) 307 strata::platform::advise_willneed (fileno (cur ),rows [j ].src_off ,rows [j ].src_bytes ); 308#endif 309 } 310 311// ---- the segment list: what this tensor's bytes are, plane by plane, in both forms 312Seg segs [3 ]; 313int n_segs = 0 ; 314bool bad = false; 315uint64_t sum_src = 0 ,sum_dst = 0 ; 316if (r .codes_bytes != 0 ) { 317// A quantized tensor: codes, then scales, then the optional offset plane, each contiguous in the 318// source span in that order (pack_index.py verifies the contiguity and refuses otherwise). 319segs [n_segs ++ ]= Seg {0 ,r .codes_bytes ,0 ,r .codes_bytes ,Conv ::Copy }; 320if (r .scales_bytes ) { 321const uint64_t src_scale_bytes = r .scales_fp16 ?r .scales_bytes /2 :r .scales_bytes ; 322if (r .scales_fp16 && (r .scales_bytes %2 || src_scale_bytes * 2 != r .scales_bytes )) { 323err = r .name + ": an fp16 scale plane of an odd byte count" ; 324bad = true; 325 } 326segs [n_segs ++ ]= Seg {r .codes_bytes ,src_scale_bytes ,r .codes_bytes ,r .scales_bytes , 327r .scales_fp16 ?Conv ::WidenF16 :Conv ::Copy }; 328 } 329if (r .offset_bytes ) { 330const uint64_t after = r .codes_bytes + (r .scales_fp16 ?r .scales_bytes /2 :r .scales_bytes ); 331segs [n_segs ++ ]= Seg {after ,r .offset_bytes ,r .codes_bytes + r .scales_bytes ,r .offset_bytes , 332Conv ::Copy }; 333 } 334 }else { 335// Everything else is one run whose transform is the row's kind. The two promoted types shrink 336// 4 B/elem to 2; the rest are already the engine form. 337Conv c = Conv ::Copy ; 338if (r .raw16 )c = Conv ::Copy ; 339else if (r .kind == WeightKind ::Bf16InF32 )c = Conv ::Bf16High ; 340else if (r .kind == WeightKind ::F16InF32 )c = Conv ::ToF16 ; 341const uint64_t elems = (uint64_t )r .ne0 * (uint64_t ) (r .ne1 > 0 ?r .ne1 :1 ); 342if (c != Conv ::Copy && (r .src_bytes != elems * 4 || r .dst_bytes != elems * 2 )) { 343// A promoted type is 4 B/elem in and 2 B/elem out, and nothing else. If those two numbers do 344// not say so, the shape and the byte counts disagree and the element count this loop would 345// use to walk the source is not the element count the pack wrote. 346char buf [320 ]; 347 std::snprintf (buf ,sizeof buf , 348"%s: a promoted tensor of %llu elements is %llu B in and %llu B out, not %llu/%llu" , 349r .name .c_str (), (unsigned long long )elems , (unsigned long long )r .src_bytes , 350 (unsigned long long )r .dst_bytes , (unsigned long long ) (elems * 4 ), 351 (unsigned long long ) (elems * 2 )); 352err = buf ; 353bad = true; 354 } 355segs [n_segs ++ ]= Seg {0 ,r .src_bytes ,0 ,r .dst_bytes ,c }; 356 } 357for (int i = 0 ;i < n_segs ;++ i ) {sum_src += segs [i ].src_bytes ;sum_dst += segs [i ].dst_bytes ; } 358// The segment list is this loop's own idea of the layout, and it is the ONLY thing standing between a 359// mis-sized plane and a wrong byte offset. It is checked against both recorded totals, not trusted. 360if (!bad && (sum_src != r .src_bytes || sum_dst != r .dst_bytes )) { 361char buf [360 ]; 362 std::snprintf (buf ,sizeof buf , 363"%s: the segments cover %llu/%llu B but the index says %llu/%llu - the plane layout " 364"this loader built is not the one the index describes" , 365r .name .c_str (), (unsigned long long )sum_src , (unsigned long long )sum_dst , 366 (unsigned long long )r .src_bytes , (unsigned long long )r .dst_bytes ); 367err = buf ; 368bad = true; 369 } 370if (bad ) { 371 sycl::free (stage_in , dpct::get_in_order_queue ()); 372 sycl::free (stage_out , dpct::get_in_order_queue ()); 373return false; 374 } 375 376for (int si = 0 ;si < n_segs ;++ si ) { 377const Seg & s = segs [si ]; 378const bool widening = (s .conv == Conv ::WidenF16 ); 379if (widening && (s .src_bytes & 1ull )) { 380err = r .name + ": an fp16 plane with an odd source byte count" ; 381 sycl::free (stage_in , dpct::get_in_order_queue ()); 382 sycl::free (stage_out , dpct::get_in_order_queue ()); 383return false; 384 } 385uint64_t done = 0 ; 386while (done < s .src_bytes ) { 387uint64_t n = std::min (CHUNK ,s .src_bytes - done ); 388// WIDENING NEVER SPLITS AN ELEMENT. CHUNK is even, so a full chunk cannot, but the tail of a 389// plane whose length is odd would - and half an fp16 is a plausible-looking scale. 390if (widening && (n & 1ull )) { 391if (n == 1 ) { 392err = 393r .name + ": an fp16 plane ending on a half element" ; 394 sycl::free (stage_in , dpct::get_in_order_queue ()); 395 sycl::free (stage_out , dpct::get_in_order_queue ()); 396return false; 397 } 398n -= 1 ; 399 } 400if (!read_at (cur ,r .src_off + s .src_off + done ,stage_in , (size_t )n ,err ,r .name .c_str ())) { 401 sycl::free (stage_in , dpct::get_in_order_queue ()); 402 sycl::free (stage_out , dpct::get_in_order_queue ()); 403return false; 404 } 405const uint8_t * src = (const uint8_t * )stage_in ; 406const void * host_src = src ; 407uint64_t out_bytes = n ; 408uint64_t out_at = s .dst_off + done ; 409 410switch (s .conv ) { 411case Conv ::Copy : 412break ; 413case Conv ::Bf16High : { 414// THE HIGH 16 BITS ARE THE BF16 ENCODING, exactly - not a rounding. A bf16 value is 415// the top half of its f32 image, and the pack promoted it without changing it, so 416// this is a copy with a stride. 417const uint64_t elems = n /4 ; 418out_bytes = elems * 2 ; 419uint8_t * o = (uint8_t * )stage_out ; 420for (uint64_t i = 0 ;i < elems ;++ i ) { 421uint32_t v ; 422 std::memcpy (& v ,src + i * 4 ,4 ); 423const uint16_t h = (uint16_t ) (v >>16 ); 424 std::memcpy (o + i * 2 ,& h ,2 ); 425 } 426host_src = stage_out ; 427out_at = s .dst_off + done /2 ; 428break ; 429 } 430case Conv ::ToF16 : { 431const uint64_t elems = n /4 ; 432out_bytes = elems * 2 ; 433uint8_t * o = (uint8_t * )stage_out ; 434for (uint64_t i = 0 ;i < elems ;++ i ) { 435float v ; 436 std::memcpy (& v ,src + i * 4 ,4 ); 437const uint16_t h = strata::kernels::f16_from_f32 (v ); 438 std::memcpy (o + i * 2 ,& h ,2 ); 439 } 440host_src = stage_out ; 441out_at = s .dst_off + done /2 ; 442break ; 443 } 444case Conv ::WidenF16 : { 445// fp16 bits -> f32. EXACT: every fp16 value is an f32 value, including the 446// subnormals, so this cannot change a single weight - which is why the engine may do 447// it at all, and why doing it costs 10.88 MiB rather than a second kernel family. 448const uint64_t elems = n /2 ; 449out_bytes = elems * 4 ; 450float * o = (float * )stage_out ; 451for (uint64_t i = 0 ;i < elems ;++ i ) { 452uint16_t h ; 453 std::memcpy (& h ,src + i * 2 ,2 ); 454o [i ]= strata::kernels::f32_from_f16 (h ); 455 } 456host_src = stage_out ; 457out_at = s .dst_off + done * 2 ; 458break ; 459 } 460 } 461 462const double u0 = now_ms (); 463/* 464DPCT1114: cudaMemcpy is migrated to asynchronization 465memcpy, assuming in the original code the source host memory is 466pageable memory. If the memory is not pageable, call wait() on 467event return by memcpy API to ensure synchronization behavior. 468*/ 469if (DPCT_CHECK_ERROR (dpct::get_in_order_queue ().memcpy ( 470dst_base + r .dst_off + out_at ,host_src ,out_bytes ).wait ())!= 4710 ) { 472err = "cudaMemcpy failed for " + r .name ; 473 sycl::free (stage_in , dpct::get_in_order_queue ()); 474 sycl::free (stage_out , dpct::get_in_order_queue ()); 475return false; 476 } 477upload_ms += now_ms ()- u0 ; 478done += n ; 479 } 480 } 481 482WeightRef wr ; 483wr .data = dst_base + r .dst_off ; 484wr .bytes = r .dst_bytes ; 485wr .ne0 = r .ne0 ; 486wr .ne1 = r .ne1 ; 487wr .elements = r .ne0 * (r .ne1 > 0 ?r .ne1 :1 ); 488wr .kind = r .kind ; 489wr .code_bits = r .code_bits ; 490wr .code_bias = r .code_bias ; 491wr .group_elems = r .group_elems ; 492wr .codebook_iq4nl = r .codebook != 0 ; 493wr .has_offset = r .has_offset != 0 ; 494wr .codes_bytes = r .codes_bytes ; 495wr .scales_bytes = r .scales_bytes ; 496wr .offset_bytes = r .offset_bytes ; 497wr .src_off = r .src_off ; 498wr .src_bytes = r .src_bytes ; 499wr .file_id = r .file ; 500wr .scales_fp16 = r .scales_fp16 != 0 ; 501wr .act_kind = r .act_kind ; 502table_ [r .name ]= wr ; 503 504++ report_ .tensors ; 505if ((r .kind == WeightKind ::Bf16InF32 || r .kind == WeightKind ::F16InF32 )&& !r .raw16 ) { 506++ report_ .re_rounded ; 507report_ .bytes_saved += r .src_bytes - r .dst_bytes ; 508 } 509 } 510if (cur ) std::fclose (cur ); 511 sycl::free (stage_in , dpct::get_in_order_queue ()); 512 sycl::free (stage_out , dpct::get_in_order_queue ()); 513 514report_ .arena_bytes = pool ; 515report_ .read_ms = now_ms ()- t_read0 - upload_ms ; 516report_ .upload_ms = upload_ms ; 517if (DPCT_CHECK_ERROR (dpct::get_current_device ().queues_wait_and_throw ())!= 5180 ) { 519err = "cudaDeviceSynchronize after the load failed" ;return false; 520 } 521return true; 522} 523catch (sycl::exception const & exc ) { 524 std::cerr <<exc .what () <<"Exception caught at file:" <<__FILE__ 525 <<", line:" <<__LINE__ << std::endl ; 526 std::exit (1 ); 527} 528 529const WeightRef * WeightTable ::find (const std::string & name )const { 530const auto it = table_ .find (name ); 531return it == table_ .end () ?nullptr :& it -> second ; 532} 533 534}// namespace strata::core