okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-1402-y' into f-14025af104b51

main
24.4 KiB534 linesraw
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() {
28    using namespace std::chrono;
29    return duration<double, std::milli>(steady_clock::now().time_since_epoch()).count();
30}
31
32struct IndexRow {
33    std::string name;
34    int file = 0;
35    WeightKind kind = WeightKind::Verbatim;
36    uint64_t src_off = 0, src_bytes = 0, dst_off = 0, dst_bytes = 0;
37    int64_t ne0 = 0, ne1 = 0;
38    int code_bits = 0, code_bias = 0, group_elems = 0, codebook = 0, has_offset = 0;
39    uint64_t codes_bytes = 0, scales_bytes = 0, offset_bytes = 0;
40    int scales_fp16 = 0;
41    int act_kind = 0;
42    bool 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 {
47    Copy = 0,      ///< the bytes are already the engine form
48    Bf16High = 1,  ///< f32 container holding a bf16 value: take the high 16 bits
49    ToF16 = 2,     ///< f32 container holding an f16 value: a real round-to-nearest-even conversion
50    WidenF16 = 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 {
59    uint64_t src_off = 0;   ///< relative to the row's src_off
60    uint64_t src_bytes = 0;
61    uint64_t dst_off = 0;   ///< relative to the row's dst_off
62    uint64_t dst_bytes = 0;
63    Conv conv = Conv::Copy;
64};
65
66const char* file_name(int id) {
67    switch (id) {
68        case 0: return "dense.bin";
69        case 1: return "embd.bin";
70        case 2: return "experts.bin";
71        case 3: return "extra.bin";   // plan v0.3 P6: a native pack's float tensors that the base pack quantized
72        default: 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)
81    if (_fseeki64(f, (long long) off, SEEK_SET) != 0) { err = std::string(what) + ": seek failed"; return false; }
82#else
83    if (fseeko(f, (off_t) off, SEEK_SET) != 0) { err = std::string(what) + ": seek failed"; return false; }
84#endif
85    if (std::fread(dst, 1, n, f) != n) { err = std::string(what) + ": short read"; return false; }
86    return true;
87}
88
89}  // namespace
90
91bool WeightTable::pool_bytes(const std::string& pack_dir, uint64_t& out, std::string& err,
92                             const std::set<std::string>* skip) {
93    const std::string path = pack_dir + "/index.txt";
94    std::FILE* f = std::fopen(path.c_str(), "rb");
95    if (!f) { err = "cannot open " + path; return false; }
96    char line[1024];
97    out = 0;
98    uint64_t pool = 0, compact = 0;
99    int align = 0;
100    while (std::fgets(line, sizeof line, f)) {
101        if (line[0] == '#') {
102            unsigned long long p = 0;
103            int a = 0, tensors = 0;
104            if (std::sscanf(line, "# align %d pool %llu tensors %d", &a, &p, &tensors) == 3) { pool = p; align = a; }
105            continue;
106        }
107        if (skip == nullptr) continue;
108        char name[256] = {0};
109        unsigned long long dst_bytes = 0, dummy = 0;
110        int i1 = 0, i2 = 0;
111        if (std::sscanf(line, "%255s %d %d %llu %llu %llu %llu", name, &i1, &i2, &dummy, &dummy, &dummy, &dst_bytes) != 7)
112            continue;
113        if (skip->count(name)) continue;
114        const uint64_t a = align > 0 ? (uint64_t) align : 256;
115        compact += (dst_bytes + a - 1) / a * a;
116    }
117    std::fclose(f);
118    if (pool == 0) { err = "no '# align ... pool ...' header in " + path; return false; }
119    out = skip ? compact : pool;
120    return true;
121}
122
123bool WeightTable::index_code_bits(const std::string& pack_dir, const std::string& name, int& code_bits,
124                                  std::string& err) {
125    const std::string path = pack_dir + "/index.txt";
126    std::FILE* f = std::fopen(path.c_str(), "rb");
127    if (!f) { err = "cannot open " + path; return false; }
128    char line[1024];
129    code_bits = -1;
130    while (std::fgets(line, sizeof line, f)) {
131        if (line[0] == '#') continue;
132        char row[256] = {0};
133        unsigned long long dummy = 0;
134        long long ne = 0;
135        int 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
137        if (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)
139            continue;
140        if (name == row) { code_bits = bits; break; }
141    }
142    std::fclose(f);
143    return true;
144}
145
146bool WeightTable::load(const std::string &pack_dir, void *arena_base,
147                       uint64_t arena_bytes, std::string &err,
148                       const std::set<std::string> *skip) try {
149    const std::string path = pack_dir + "/index.txt";
150    std::FILE* idx = std::fopen(path.c_str(), "rb");
151    if (!idx) { err = "cannot open " + path + " (run tools/pack_index.py)"; return false; }
152
153    uint64_t pool = 0;
154    int align = 0;
155    std::vector<IndexRow> rows;
156    char line[1024];
157    while (std::fgets(line, sizeof line, idx)) {
158        if (line[0] == '#') {
159            unsigned long long p = 0;
160            int a = 0, t = 0;
161            if (std::sscanf(line, "# align %d pool %llu tensors %d", &a, &p, &t) == 3) { pool = p; align = a; }
162            continue;
163        }
164        IndexRow r;
165        char name[256] = {0};
166        int 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.
169        const 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",
171                                  name, &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);
175        if (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.
178            err = "index.txt: could not parse a row (" + std::to_string(n) + " of 19 fields)";
179            std::fclose(idx);
180            return false;
181        }
182        r.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
185        if (kind == 4 || kind == 5) {
186            r.raw16 = true;
187            kind = kind == 4 ? (int) WeightKind::Bf16InF32 : (int) WeightKind::F16InF32;
188        }
189        r.kind = (WeightKind) kind;
190        rows.push_back(r);
191    }
192    std::fclose(idx);
193
194    if (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);
198    if (skip != nullptr) {
199        const uint64_t a = align > 0 ? (uint64_t) align : 256;
200        uint64_t at = 0;
201        for (size_t i = 0; i < rows.size(); ++i) {
202            if (skip->count(rows[i].name)) { skipped[i] = true; continue; }
203            rows[i].dst_off = at;
204            at += (rows[i].dst_bytes + a - 1) / a * a;
205        }
206        pool = at;
207    }
208    if (arena_bytes < pool) {
209        err = "arena is " + std::to_string(arena_bytes) + " B but the index needs " + std::to_string(pool);
210        return 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.
226    void* stage_in = nullptr;
227    void* stage_out = nullptr;
228    /*
229    DPCT1048: The original value cudaHostAllocDefault is not meaningful in the
230    migrated code and was removed or replaced with 0. You may need to check the
231    migrated code.
232    */
233    if (DPCT_CHECK_ERROR(stage_in = (void *)sycl::malloc_host(
234                             CHUNK, dpct::get_in_order_queue())) != 0 ||
235        /*
236        DPCT1048: The original value cudaHostAllocDefault is not meaningful in
237        the migrated code and was removed or replaced with 0. You may need to
238        check the migrated code.
239        */
240        DPCT_CHECK_ERROR(stage_out = (void *)sycl::malloc_host(
241                             CHUNK * 2, dpct::get_in_order_queue())) != 0) {
242        err = "cudaHostAlloc for the staging buffers failed";
243        if (stage_in) sycl::free(stage_in, dpct::get_in_order_queue());
244        if (stage_out) sycl::free(stage_out, dpct::get_in_order_queue());
245        return false;
246    }
247
248    uint8_t* dst_base = (uint8_t*) arena_base;
249    std::FILE* cur = nullptr;
250    int cur_file = -1;
251    table_.clear();
252    report_ = LoadReport{};
253
254    const double t_read0 = now_ms();
255    double upload_ms = 0;
256    for (size_t row_i = 0; row_i < rows.size(); ++row_i) {
257        const IndexRow& r = rows[row_i];
258        if (skipped[row_i]) {
259            WeightRef wr;
260            wr.data = nullptr;
261            wr.resident = false;
262            wr.bytes = r.dst_bytes;
263            wr.ne0 = r.ne0;
264            wr.ne1 = r.ne1;
265            wr.elements = r.ne0 * (r.ne1 > 0 ? r.ne1 : 1);
266            wr.kind = r.kind;
267            wr.code_bits = r.code_bits;
268            wr.code_bias = r.code_bias;
269            wr.group_elems = r.group_elems;
270            wr.codebook_iq4nl = r.codebook != 0;
271            wr.has_offset = r.has_offset != 0;
272            wr.codes_bytes = r.codes_bytes;
273            wr.scales_bytes = r.scales_bytes;
274            wr.offset_bytes = r.offset_bytes;
275            wr.src_off = r.src_off;
276            wr.src_bytes = r.src_bytes;
277            wr.file_id = r.file;
278            wr.scales_fp16 = r.scales_fp16 != 0;
279            wr.act_kind = r.act_kind;
280            table_[r.name] = wr;
281            ++report_.tensors;
282            continue;
283        }
284        if (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
286            err = 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());
289            return false;
290        }
291        if (r.file != cur_file) {
292            if (cur) std::fclose(cur);
293            const char* fn = file_name(r.file);
294            const std::string p = pack_dir + "/" + (fn ? fn : "?");
295            cur = std::fopen(p.c_str(), "rb");
296            if (!cur) {
297                err = "cannot open " + p;
298                sycl::free(stage_in, dpct::get_in_order_queue());
299                sycl::free(stage_out, dpct::get_in_order_queue());
300                return false;
301            }
302            cur_file = r.file;
303#if !defined(_WIN32)
304            // ask for this file's remaining rows up front so their reads overlap
305            for (size_t j = row_i; j < rows.size(); ++j)
306                if (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
312        Seg segs[3];
313        int n_segs = 0;
314        bool bad = false;
315        uint64_t sum_src = 0, sum_dst = 0;
316        if (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).
319            segs[n_segs++] = Seg{0, r.codes_bytes, 0, r.codes_bytes, Conv::Copy};
320            if (r.scales_bytes) {
321                const uint64_t src_scale_bytes = r.scales_fp16 ? r.scales_bytes / 2 : r.scales_bytes;
322                if (r.scales_fp16 && (r.scales_bytes % 2 || src_scale_bytes * 2 != r.scales_bytes)) {
323                    err = r.name + ": an fp16 scale plane of an odd byte count";
324                    bad = true;
325                }
326                segs[n_segs++] = Seg{r.codes_bytes, src_scale_bytes, r.codes_bytes, r.scales_bytes,
327                                     r.scales_fp16 ? Conv::WidenF16 : Conv::Copy};
328            }
329            if (r.offset_bytes) {
330                const uint64_t after = r.codes_bytes + (r.scales_fp16 ? r.scales_bytes / 2 : r.scales_bytes);
331                segs[n_segs++] = Seg{after, r.offset_bytes, r.codes_bytes + r.scales_bytes, r.offset_bytes,
332                                     Conv::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.
337            Conv c = Conv::Copy;
338            if (r.raw16) c = Conv::Copy;
339            else if (r.kind == WeightKind::Bf16InF32) c = Conv::Bf16High;
340            else if (r.kind == WeightKind::F16InF32) c = Conv::ToF16;
341            const uint64_t elems = (uint64_t) r.ne0 * (uint64_t) (r.ne1 > 0 ? r.ne1 : 1);
342            if (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.
346                char 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",
349                              r.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));
352                err = buf;
353                bad = true;
354            }
355            segs[n_segs++] = Seg{0, r.src_bytes, 0, r.dst_bytes, c};
356        }
357        for (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.
360        if (!bad && (sum_src != r.src_bytes || sum_dst != r.dst_bytes)) {
361            char 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",
365                          r.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);
367            err = buf;
368            bad = true;
369        }
370        if (bad) {
371            sycl::free(stage_in, dpct::get_in_order_queue());
372            sycl::free(stage_out, dpct::get_in_order_queue());
373            return false;
374        }
375
376        for (int si = 0; si < n_segs; ++si) {
377            const Seg& s = segs[si];
378            const bool widening = (s.conv == Conv::WidenF16);
379            if (widening && (s.src_bytes & 1ull)) {
380                err = 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());
383                return false;
384            }
385            uint64_t done = 0;
386            while (done < s.src_bytes) {
387                uint64_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.
390                if (widening && (n & 1ull)) {
391                    if (n == 1) {
392                        err =
393                            r.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());
396                        return false;
397                    }
398                    n -= 1;
399                }
400                if (!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());
403                    return false;
404                }
405                const uint8_t* src = (const uint8_t*) stage_in;
406                const void* host_src = src;
407                uint64_t out_bytes = n;
408                uint64_t out_at = s.dst_off + done;
409
410                switch (s.conv) {
411                    case Conv::Copy:
412                        break;
413                    case 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.
417                        const uint64_t elems = n / 4;
418                        out_bytes = elems * 2;
419                        uint8_t* o = (uint8_t*) stage_out;
420                        for (uint64_t i = 0; i < elems; ++i) {
421                            uint32_t v;
422                            std::memcpy(&v, src + i * 4, 4);
423                            const uint16_t h = (uint16_t) (v >> 16);
424                            std::memcpy(o + i * 2, &h, 2);
425                        }
426                        host_src = stage_out;
427                        out_at = s.dst_off + done / 2;
428                        break;
429                    }
430                    case Conv::ToF16: {
431                        const uint64_t elems = n / 4;
432                        out_bytes = elems * 2;
433                        uint8_t* o = (uint8_t*) stage_out;
434                        for (uint64_t i = 0; i < elems; ++i) {
435                            float v;
436                            std::memcpy(&v, src + i * 4, 4);
437                            const uint16_t h = strata::kernels::f16_from_f32(v);
438                            std::memcpy(o + i * 2, &h, 2);
439                        }
440                        host_src = stage_out;
441                        out_at = s.dst_off + done / 2;
442                        break;
443                    }
444                    case 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.
448                        const uint64_t elems = n / 2;
449                        out_bytes = elems * 4;
450                        float* o = (float*) stage_out;
451                        for (uint64_t i = 0; i < elems; ++i) {
452                            uint16_t h;
453                            std::memcpy(&h, src + i * 2, 2);
454                            o[i] = strata::kernels::f32_from_f16(h);
455                        }
456                        host_src = stage_out;
457                        out_at = s.dst_off + done * 2;
458                        break;
459                    }
460                }
461
462                const double u0 = now_ms();
463                /*
464                DPCT1114: cudaMemcpy is migrated to asynchronization
465                memcpy, assuming in the original code the source host memory is
466                pageable memory. If the memory is not pageable, call wait() on
467                event return by memcpy API to ensure synchronization behavior.
468                */
469                if (DPCT_CHECK_ERROR(dpct::get_in_order_queue().memcpy(
470                        dst_base + r.dst_off + out_at, host_src, out_bytes).wait()) !=
471                    0) {
472                    err = "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());
475                    return false;
476                }
477                upload_ms += now_ms() - u0;
478                done += n;
479            }
480        }
481
482        WeightRef wr;
483        wr.data = dst_base + r.dst_off;
484        wr.bytes = r.dst_bytes;
485        wr.ne0 = r.ne0;
486        wr.ne1 = r.ne1;
487        wr.elements = r.ne0 * (r.ne1 > 0 ? r.ne1 : 1);
488        wr.kind = r.kind;
489        wr.code_bits = r.code_bits;
490        wr.code_bias = r.code_bias;
491        wr.group_elems = r.group_elems;
492        wr.codebook_iq4nl = r.codebook != 0;
493        wr.has_offset = r.has_offset != 0;
494        wr.codes_bytes = r.codes_bytes;
495        wr.scales_bytes = r.scales_bytes;
496        wr.offset_bytes = r.offset_bytes;
497        wr.src_off = r.src_off;
498        wr.src_bytes = r.src_bytes;
499        wr.file_id = r.file;
500        wr.scales_fp16 = r.scales_fp16 != 0;
501        wr.act_kind = r.act_kind;
502        table_[r.name] = wr;
503
504        ++report_.tensors;
505        if ((r.kind == WeightKind::Bf16InF32 || r.kind == WeightKind::F16InF32) && !r.raw16) {
506            ++report_.re_rounded;
507            report_.bytes_saved += r.src_bytes - r.dst_bytes;
508        }
509    }
510    if (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
514    report_.arena_bytes = pool;
515    report_.read_ms = now_ms() - t_read0 - upload_ms;
516    report_.upload_ms = upload_ms;
517    if (DPCT_CHECK_ERROR(dpct::get_current_device().queues_wait_and_throw()) !=
518        0) {
519        err = "cudaDeviceSynchronize after the load failed"; return false;
520    }
521    return 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 {
530    const auto it = table_.find(name);
531    return it == table_.end() ? nullptr : &it->second;
532}
533
534}  // namespace strata::core