okami.mom/strata

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

Niko1221rc1 merge arc-uc (512333833)299fb68ea

main
25.1 KiB494 linesraw
1#define DPCT_PROFILING_ENABLED
2#include <sycl/sycl.hpp>
3#include <dpct/dpct.hpp>
4#include "strata/sycl_queue.hpp"
5#include "strata/core/native_dense.hpp"
6#include <cstdlib>
7#include "strata/core/weights.hpp"
8#include "strata/artifact/gguf_reader.hpp"
9#include "strata/kernels/native_mmvq.hpp"
10#include "strata/platform/memory.hpp"
11
12#include <algorithm>
13#include <climits>
14#include <cstdio>
15#include <cstdlib>
16#include <exception>
17#include <limits>
18#include <memory>
19#include <mutex>
20#include <set>
21#include <cmath>
22#include <cstring>
23#include <vector>
24
25namespace strata::core {
26namespace {
27int g_layer_lb = -1, g_layer_le = -1;   // set_layer_range; -1: every layer
28bool in_range(const std::string& name) {
29    if (g_layer_lb < 0 || name.rfind("blk.", 0) != 0) return true;
30    const int l = std::atoi(name.c_str() + 4);
31    return l >= g_layer_lb && l < g_layer_le;
32}
33// S23 experiment (STRATA_HC_Q8=1): the hyper-connection projections' Q8_0 bytes for the verify read
34bool hc_q8_env() {
35    static const bool on = [] { const char* v = std::getenv("STRATA_HC_Q8"); return v != nullptr && v[0] == '1'; }();
36    return on;
37}
38bool hc_q8_name(const std::string& name) {
39    if (name == "output_hc_down.weight" || name == "output_hc_up.weight") return true;   // S25: the final mixer too
40    if (name.rfind("blk.", 0) != 0) return false;
41    static const char* suffixes[] = {".hc_attn_down.weight", ".hc_attn_up.weight", ".hc_attn_inject.weight",
42                                     ".hc_ffn_down.weight", ".hc_ffn_up.weight", ".hc_ffn_inject.weight"};
43    for (const char* suffix : suffixes) if (name.ends_with(suffix)) return true;
44    return false;
45}
46// S25: the GGUF keeps the inject rows as F32 - quantized here to Q8_0 (ggml's reference rounding) so the Q8_0 read
47// covers every hc projection
48uint16_t half_bits(float f) {
49    uint32_t x;
50    std::memcpy(&x, &f, 4);
51    const uint32_t sign = (x >> 16) & 0x8000u;
52    int32_t e = (int32_t) ((x >> 23) & 0xff) - 127 + 15;
53    uint32_t m = x & 0x7fffffu;
54    if (e <= 0) {                                   // subnormal or zero
55        if (e < -10) return (uint16_t) sign;
56        m |= 0x800000u;
57        const uint32_t shift = (uint32_t) (14 - e);
58        uint32_t h = m >> shift;
59        const uint32_t rem = m & ((1u << shift) - 1), half = 1u << (shift - 1);
60        if (rem > half || (rem == half && (h & 1u))) ++h;
61        return (uint16_t) (sign | h);
62    }
63    if (e >= 31) return (uint16_t) (sign | 0x7c00u);
64    uint32_t h = ((uint32_t) e << 10) | (m >> 13);
65    const uint32_t rem = m & 0x1fffu;
66    if (rem > 0x1000u || (rem == 0x1000u && (h & 1u))) ++h;
67    return (uint16_t) (sign | h);
68}
69std::vector<uint8_t> q8_0_of(const float* x, uint64_t n) {
70    std::vector<uint8_t> out((size_t) (n / 32 * 34));
71    for (uint64_t b = 0; b < n / 32; ++b) {
72        float amax = 0.0f;
73        for (int j = 0; j < 32; ++j) amax = (std::max)(amax, std::fabs(x[b * 32 + j]));
74        const float d = amax / 127.0f, id = d != 0.0f ? 1.0f / d : 0.0f;
75        uint8_t* o = out.data() + b * 34;
76        const uint16_t hb = half_bits(d);
77        std::memcpy(o, &hb, 2);
78        for (int j = 0; j < 32; ++j) o[2 + j] = (uint8_t) (int8_t) std::lround(x[b * 32 + j] * id);
79    }
80    return out;
81}
82bool eligible(const strata::TensorInfo& tensor, bool include_ple_key) {
83    const auto& name = tensor.name;
84    if (name.rfind("blk.", 0) != 0) return false;
85    // Match the native PLE kernel: Q2_0, IQ3_XXS, IQ4_XS and Q8_0 (UD-Q4_K_XL). Other keys retain the packed BF16
86    // fallback.
87    if (name == "blk.1.ple_key.weight")
88        return include_ple_key && (tensor.type == 42 || tensor.type == 18 || tensor.type == 23 || tensor.type == 8);
89    static const char* suffixes[] = {".attn_qkv.weight", ".attn_gate.weight", ".ssm_out.weight",
90        ".attn_q.weight", ".attn_k.weight", ".attn_v.weight", ".attn_output.weight",
91        ".ffn_gate_shexp.weight", ".ffn_up_shexp.weight", ".ffn_down_shexp.weight"};
92    for (const char* suffix : suffixes) if (name.ends_with(suffix)) return true;
93    return false;
94}
95// The native dense matrices (one allocation each, ~300 of them) are carved out of a few big blocks. On an Arc A-series card
96// (i915) every kernel launch costs the host time proportional to the number of live device allocations (12 us with none,
97// 131 us with 300, 1.8 ms with 3000) and the kernels themselves run slower; the allocation size does not matter.
98// STRATA_DENSE_SLAB_MIB=<n>: block size in MiB (default 256 under the i915 driver, 0 = one allocation per matrix, which is
99// what every other driver does); matrices of half a block or more keep their own allocation.
100struct DenseSlab {
101    struct Block { void* base; size_t size; size_t used; };
102    std::mutex mu;
103    std::vector<Block> blocks;
104};
105DenseSlab& dense_slab() { static DenseSlab s; return s; }
106size_t dense_slab_bytes() {
107    static const size_t v = [] {
108        if (const char* e = std::getenv("STRATA_DENSE_SLAB_MIB")) return (size_t) (std::atol(e) > 0 ? std::atol(e) : 0) << 20;
109        // on by default where it is measured: an Arc A-series card under the i915 driver (A750: 4K-token prompt 112.6 ->
110        // 185.6 tok/s, output bit-identical); other drivers and cards keep one allocation per matrix
111        return strata::intel_gpu_driver() == "i915" ? ((size_t) 256 << 20) : (size_t) 0;
112    }();
113    return v;
114}
115bool dense_slab_owns(const void* p) {
116    DenseSlab& s = dense_slab();
117    std::lock_guard<std::mutex> lk(s.mu);
118    for (const auto& b : s.blocks) if ((uintptr_t) p >= (uintptr_t) b.base && (uintptr_t) p < (uintptr_t) b.base + b.size) return true;
119    return false;
120}
121void* dense_alloc(size_t bytes) {
122    const size_t sb = dense_slab_bytes();
123    const size_t need = (bytes + 255) & ~(size_t) 255;
124    if (sb == 0 || need >= sb / 2) return strata::malloc_device_guarded(bytes, dpct::get_in_order_queue());
125    DenseSlab& s = dense_slab();
126    std::lock_guard<std::mutex> lk(s.mu);
127    for (auto& b : s.blocks)   // first fit: a gap left by a big matrix is filled by a later small one
128        if (b.size - b.used >= need) { void* p = (uint8_t*) b.base + b.used; b.used += need; return p; }
129    void* base = strata::malloc_device_guarded(sb, dpct::get_in_order_queue(), "native dense block");
130    if (base == nullptr) return nullptr;
131    s.blocks.push_back({base, sb, need});
132    return base;
133}
134void dense_slab_free_blocks() {
135    DenseSlab& s = dense_slab();
136    std::lock_guard<std::mutex> lk(s.mu);
137    for (auto& b : s.blocks) { strata::device_alloc_unregister(b.base); sycl::free(b.base, dpct::get_in_order_queue()); }
138    s.blocks.clear();
139}
140struct DeviceFree {
141    void
142    operator()(void *p) const {
143        if (p && !dense_slab_owns(p)) sycl::free(p, dpct::get_in_order_queue());
144    }
145};
146using DevicePtr = std::unique_ptr<void, DeviceFree>;
147struct Pending {
148    WeightRef* ref;
149    int type;
150    uint64_t bytes;
151    DevicePtr data;
152    DevicePtr packed;   // STRATA_Q8_PACKED=1 copy, or null
153};
154// The block with the most unused room is copied into an allocation of exactly its used size (and freed): the VRAM the
155// last, part-filled block would waste is the expert cache's (192 slots became 53 on an 8 GB card without this).
156// Called before the matrices' pointers are published, so the Pending items are the only holders of them.
157bool dense_slab_trim(std::vector<Pending>& pending) {
158    DenseSlab& s = dense_slab();
159    size_t at = s.blocks.size(), best = 0;
160    for (size_t i = 0; i < s.blocks.size(); ++i)
161        if (s.blocks[i].size - s.blocks[i].used > best) { best = s.blocks[i].size - s.blocks[i].used; at = i; }
162    if (at == s.blocks.size() || best < ((size_t) 4 << 20)) return true;
163    DenseSlab::Block old = s.blocks[at];
164    void* fresh = strata::malloc_device_guarded(old.used, dpct::get_in_order_queue(), "native dense block");
165    if (fresh == nullptr) return true;   // keep the part-filled block
166    dpct::get_in_order_queue().memcpy(fresh, old.base, old.used).wait();
167    auto rebase = [&](DevicePtr& d) {
168        const uintptr_t a = (uintptr_t) d.get();
169        if (d && a >= (uintptr_t) old.base && a < (uintptr_t) old.base + old.used)
170            (void) d.release(), d.reset((uint8_t*) fresh + (a - (uintptr_t) old.base));
171    };
172    for (auto& item : pending) { rebase(item.data); rebase(item.packed); }
173    {
174        std::lock_guard<std::mutex> lk(s.mu);
175        s.blocks[at] = {fresh, old.used, old.used};   // the new block now owns those pointers
176    }
177    strata::device_alloc_unregister(old.base);
178    sycl::free(old.base, dpct::get_in_order_queue());
179    return true;
180}
181}
182
183// the shared header declares the static member (b60aab1b); this port only needs the env switch
184bool NativeDense::hc_q8_requested() { return hc_q8_env(); }
185
186bool NativeDense::served_names(const std::vector<std::string>& shards, bool include_ple_key,
187                               std::set<std::string>& out, std::string& err) {
188    try {
189        for (const auto& path : shards) {
190            strata::GgufFile gguf(path);
191            for (const auto& tensor : gguf.tensors())
192                if (eligible(tensor, include_ple_key) && strata::kernels::native_mmvq_supported(tensor.type) &&
193                    tensor.shape.size() == 2)
194                    out.insert(tensor.name);
195        }
196        return true;
197    } catch (const std::exception& error) {
198        err = std::string("native dense: ") + error.what();
199        return false;
200    }
201}
202
203void NativeDense::set_layer_range(int lb, int le) { g_layer_lb = lb; g_layer_le = le; }
204bool NativeDense::keep_unquantized_ple_key(const std::string& pack_dir, std::set<std::string>& skip,
205                                           std::string& err) {
206    const std::string key = "blk.1.ple_key.weight";
207    if (!skip.count(key)) return true;
208    int code_bits = -1;
209    if (!WeightTable::index_code_bits(pack_dir, key, code_bits, err)) return false;
210    if (code_bits == 0) skip.erase(key);
211    return true;
212}
213
214NativeDense::~NativeDense() {
215    for (const void* p : packed_keys_) strata::kernels::native_q8_0_packed_unregister(p);
216    if (scratch_) sycl::free(scratch_, dpct::get_in_order_queue());
217    for (void *p : weights_)
218        if (!dense_slab_owns(p)) DPCT_CHECK_ERROR(sycl::free(p, dpct::get_in_order_queue()));
219    dense_slab_free_blocks();
220}
221
222bool NativeDense::load(const std::vector<std::string> &shards,
223                       WeightTable &table, std::string &err,
224                       bool include_ple_key, int64_t layer_lo,
225                       int64_t layer_hi) try {
226    auto outside = [&](const std::string& name) {   // a blk.<l>. tensor of another stage's layers
227        if (layer_hi < 0 || name.rfind("blk.", 0) != 0) return false;
228        const long l = std::strtol(name.c_str() + 4, nullptr, 10);
229        return l < layer_lo || l >= layer_hi;
230    };
231    if (scratch_ || !weights_.empty()) { err = "native dense: already loaded"; return false; }
232    if (shards.empty()) { err = "native dense: at least one GGUF shard is required"; return false; }
233    try {
234        std::vector<Pending> pending;
235        std::set<std::string> seen;
236        int max_in = 0;
237        uint64_t total = 0, hc_q8_bytes = 0;
238        uint64_t split_count = 0, split_tensors = 0;
239        std::set<uint64_t> split_numbers;
240        bool have_architecture = false;
241        for (const auto& path : shards) {
242            strata::GgufFile gguf(path);
243            const auto* count = gguf.get("split.count");
244            const auto* number = gguf.get("split.no");
245            const auto* tensors = gguf.get("split.tensors.count");
246            if (gguf.get("general.architecture")) {
247                err = strata::check_engine_architecture(gguf);
248                if (!err.empty()) return false;
249                have_architecture = true;
250                if (count && number && tensors && number->u == 0 && count->u > 1) {
251                    split_count = count->u;
252                    split_tensors = tensors->u;
253                }
254            } else if (!have_architecture || !split_count || !count || !number || !tensors ||
255                       count->u != split_count || number->u == 0 || number->u >= split_count ||
256                       tensors->u != split_tensors) {
257                err = "native dense: additional shard must match the architecture-validated first shard's split metadata";
258                return false;
259            }
260            if (number && !split_numbers.insert(number->u).second) {
261                err = "native dense: duplicate split shard number"; return false;
262            }
263            std::vector<uint64_t> offsets;
264            for (const auto& tensor : gguf.tensors()) offsets.push_back(tensor.offset);
265            std::sort(offsets.begin(), offsets.end());
266            if (std::adjacent_find(offsets.begin(), offsets.end()) != offsets.end()) {
267                err = "native dense: tensor payload offsets overlap"; return false;
268            }
269            // Validate every directory span, including tensors we do not upload:
270            // an ignored tensor must not overlap the native matrix that follows it.
271            const uint64_t payload = gguf.file_size() - gguf.data_start();
272            for (const auto& tensor : gguf.tensors()) {
273                int block_elements = 0, block_bytes = 0;
274                uint64_t elements = 1;
275                if (tensor.shape.empty() || !strata::block_geometry(tensor.type, block_elements, block_bytes) ||
276                    tensor.shape[0] % (uint64_t) block_elements != 0) {
277                    err = "native dense: invalid block geometry " + tensor.name; return false;
278                }
279                for (uint64_t dimension : tensor.shape) {
280                    if (!dimension || elements > (std::numeric_limits<uint64_t>::max)() / dimension) {
281                        err = "native dense: invalid tensor extent " + tensor.name; return false;
282                    }
283                    elements *= dimension;
284                }
285                const uint64_t blocks = elements / (uint64_t) block_elements;
286                if (blocks > (std::numeric_limits<uint64_t>::max)() / (uint64_t) block_bytes) {
287                    err = "native dense: tensor byte count overflow " + tensor.name; return false;
288                }
289                const uint64_t bytes = blocks * (uint64_t) block_bytes;
290                if (tensor.offset > payload || bytes > payload - tensor.offset) {
291                    err = "native dense: truncated payload " + tensor.name; return false;
292                }
293                const auto next = std::upper_bound(offsets.begin(), offsets.end(), tensor.offset);
294                if (next != offsets.end() && bytes > *next - tensor.offset) {
295                    err = "native dense: overlapping payload " + tensor.name; return false;
296                }
297                // the uploads below read these: ask for them now so the reads overlap
298                if (eligible(tensor, include_ple_key) && !outside(tensor.name) &&
299                    strata::kernels::native_mmvq_supported(tensor.type))
300                    strata::platform::advise_willneed(gguf.tensor_data(tensor), bytes);
301            }
302            for (const auto& tensor : gguf.tensors()) {
303                if (!eligible(tensor, include_ple_key) || outside(tensor.name)) continue;
304                if (!in_range(tensor.name) && tensor.name.find("ple") == std::string::npos) continue;
305                if (!seen.insert(tensor.name).second) {
306                    err = "native dense: duplicate tensor " + tensor.name; return false;
307                }
308                auto found = table.table_.find(tensor.name);
309                if (found == table.table_.end()) {
310                    err = "native dense: tensor absent from canonical table: " + tensor.name; return false;
311                }
312                auto& ref = found->second;
313                if (ref.native_data) { err = "native dense: override already attached"; return false; }
314                if (!strata::kernels::native_mmvq_supported(tensor.type)) continue;
315                // #326: the pack keeps an unquantized (--compat-bf16) key, which the PLE reads from the arena
316                if (tensor.name == "blk.1.ple_key.weight" && !ref.quantized()) continue;
317                if (!ref.quantized() || tensor.shape.size() != 2 ||
318                    ref.ne0 <= 0 || ref.ne0 > INT_MAX || ref.ne1 <= 0 || ref.ne1 > INT_MAX ||
319                    tensor.shape[0] != (uint64_t) ref.ne0 || tensor.shape[1] != (uint64_t) ref.ne1) {
320                    err = "native dense: incompatible matrix " + tensor.name; return false;
321                }
322                const auto bytes = strata::kernels::native_mmvq_weight_bytes(
323                    tensor.type, (int) ref.ne0, (int) ref.ne1);
324                void* allocation = nullptr;
325                auto status =
326                    DPCT_CHECK_ERROR(allocation = dense_alloc(bytes));
327                DevicePtr data(allocation);
328                if (status == 0)
329                    status = DPCT_CHECK_ERROR(
330                        dpct::get_in_order_queue()
331                            .memcpy(data.get(), gguf.tensor_data(tensor), bytes)
332                            .wait());
333                /*
334                DPCT1000: Error handling if-stmt was detected but could not
335                be rewritten.
336                */
337                if (status != 0) {
338                    /*
339                    DPCT1009: SYCL reports errors using exceptions and does
340                    not use error codes. Please replace the
341                    "get_error_string_dummy(...)" with a real error-handling
342                    function.
343                    */
344                    /*
345                    DPCT1001: The statement could not be removed.
346                    */
347                    err = "native dense upload " + tensor.name + ": " +
348                          dpct::get_error_string_dummy(status);
349                        return false;
350                }
351                max_in = (std::max)(max_in, (int) ref.ne0);
352                total += bytes;
353                // STRATA_Q8_PACKED=1: a second, packed copy of an eligible Q8_0 matrix for the decode MMVQ (the GGUF
354                // copy stays: the prompt path's GEMMs read it).
355                DevicePtr packed;
356                if (tensor.type == 8 && tensor.name != "blk.1.ple_key.weight" &&   // the PLE has its own kernel
357                    strata::kernels::native_q8_0_packed_enabled() &&
358                    strata::kernels::native_q8_0_packed_eligible((int) ref.ne0, (int) ref.ne1)) {
359                    std::vector<uint8_t> host(bytes);
360                    strata::kernels::native_q8_0_pack_host(gguf.tensor_data(tensor), host.data(), (int) ref.ne0,
361                                                           (int) ref.ne1);
362                    void* packed_allocation = nullptr;
363                    auto packed_status = DPCT_CHECK_ERROR(
364                        packed_allocation = dense_alloc(bytes));
365                    packed.reset(packed_allocation);
366                    if (packed_status == 0)
367                        packed_status = DPCT_CHECK_ERROR(
368                            dpct::get_in_order_queue()
369                                .memcpy(packed.get(), host.data(), bytes)
370                                .wait());
371                    /*
372                    DPCT1000: Error handling if-stmt was detected but could
373                    not be rewritten.
374                    */
375                    if (packed_status != 0) {
376                        /*
377                        DPCT1009: SYCL reports errors using exceptions and
378                        does not use error codes. Please replace the
379                        "get_error_string_dummy(...)" with a real error-handling
380                        function.
381                        */
382                        /*
383                        DPCT1001: The statement could not be removed.
384                        */
385                        err = "native dense packed upload " + tensor.name +
386                              ": " +
387                              dpct::get_error_string_dummy(packed_status);
388                        return false;
389                    }
390                }
391                pending.push_back(Pending{&ref, (int) tensor.type, bytes, std::move(data), std::move(packed)});
392            }
393            if (hc_q8_requested())
394                for (const auto& tensor : gguf.tensors()) {
395                    // S25: the F32 inject rows hold BF16-exact values: the read takes the pack's BF16 rows unless
396                    // STRATA_HC_Q8_INJECT=1 asks for a Q8_0 copy
397                    static const bool q8_inject = [] { const char* v = std::getenv("STRATA_HC_Q8_INJECT"); return v && v[0] == '1'; }();
398                    const bool f32_inject = q8_inject && tensor.type == 0 && tensor.name.ends_with("_inject.weight");
399                    if ((tensor.type != 8 && !f32_inject) || !hc_q8_name(tensor.name) || tensor.shape.size() != 2) continue;
400                    auto found = table.table_.find(tensor.name);
401                    if (found == table.table_.end() || found->second.hc_q8 != nullptr) continue;
402                    auto& ref = found->second;
403                    if (tensor.shape[0] != (uint64_t) ref.ne0 || tensor.shape[1] != (uint64_t) ref.ne1 || ref.ne0 % 32 != 0) {
404                        err = "native dense (STRATA_HC_Q8): incompatible matrix " + tensor.name; return false;
405                    }
406                    const uint64_t bytes = (uint64_t) ref.ne0 / 32 * 34 * (uint64_t) ref.ne1;
407                    void* p = nullptr;
408                    std::vector<uint8_t> q8;
409                    if (f32_inject) q8 = q8_0_of((const float*) gguf.tensor_data(tensor), (uint64_t) ref.ne0 * (uint64_t) ref.ne1);
410                    if (DPCT_CHECK_ERROR(
411                            p = (void *)strata::malloc_device_guarded(
412                                bytes, dpct::get_in_order_queue())) != 0 ||
413                        /*
414                        DPCT1114: cudaMemcpy is migrated to
415                        asynchronization memcpy, assuming in the original code
416                        the source host memory is pageable memory. If the memory
417                        is not pageable, call wait() on event return by memcpy
418                        API to ensure synchronization behavior.
419                        */
420                        DPCT_CHECK_ERROR(dpct::get_in_order_queue().memcpy(
421                            p,
422                            f32_inject ? (const void *)q8.data()
423                                       : gguf.tensor_data(tensor),
424                            bytes).wait()) != 0) {
425                        err = "native dense (STRATA_HC_Q8) upload " + tensor.name; return false;
426                    }
427                    ref.hc_q8 = p;
428                    weights_.push_back(p);
429                    hc_q8_bytes += bytes;
430                }
431        }
432        if (pending.empty()) { err = "native dense: no supported GDN/QSA matrices in supplied shards"; return false; }
433        void* allocation = nullptr;
434        const auto status =
435            DPCT_CHECK_ERROR(allocation = (void *)strata::malloc_device_guarded(
436                                 strata::kernels::native_q8_1_bytes(max_in),
437                                 dpct::get_in_order_queue()));
438        DevicePtr scratch(allocation);
439        /*
440        DPCT1009: SYCL reports errors using exceptions and does not use
441        error codes. Please replace the "get_error_string_dummy(...)" with a
442        real error-handling function.
443        */
444        /*
445        DPCT1001: The statement could not be removed.
446        */
447        /*
448        DPCT1000: Error handling if-stmt was detected but could not be
449        rewritten.
450        */
451        if (status != 0) {
452            err = std::string("native dense scratch: ") +
453                  dpct::get_error_string_dummy(status);
454            return false;
455        }
456        // All checks and allocations finish before publishing any reference.
457        dense_slab_trim(pending);
458        weights_.reserve(pending.size());
459        uint64_t packed_bytes = 0;
460        size_t packed_count = 0;
461        for (auto& item : pending) {
462            item.ref->native_data = item.data.get();
463            item.ref->native_type = item.type;
464            item.ref->native_q8_1 = scratch.get();
465            if (item.packed) {
466                strata::kernels::native_q8_0_packed_register(item.data.get(), item.packed.get(), (int) item.ref->ne0,
467                                                             (int) item.ref->ne1);
468                packed_keys_.push_back(item.data.get());
469                packed_bytes += item.bytes;
470                ++packed_count;
471                weights_.push_back(item.packed.release());
472            }
473            weights_.push_back(item.data.release());
474        }
475        if (packed_count)
476            std::fprintf(stderr, "native dense: STRATA_Q8_PACKED=1 packed %zu Q8_0 matrices for decode (+%.1f MiB)\n",
477                         packed_count, packed_bytes / 1048576.0);
478        scratch_ = scratch.release();
479        bytes_ = total + hc_q8_bytes;
480        if (hc_q8_requested())
481            std::fprintf(stderr, "strata: STRATA_HC_Q8=1: %.2f GiB of Q8_0 hyper-connection projections for the verify read\n",
482                         (double) hc_q8_bytes / 1073741824.0);
483        return true;
484    } catch (const std::exception& error) {
485        err = std::string("native dense: ") + error.what();
486        return false;
487    }
488}
489catch (sycl::exception const &exc) {
490  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
491            << ", line:" << __LINE__ << std::endl;
492  std::exit(1);
493}
494} // namespace strata::core