okami.mom/strata

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

Andy Slatersycl: size the expert cache from the DRM fdinfo when xe reports 0 free card memory (#1545)ddcc5f56d

main
44.2 KiB1059 linesraw
1#define DPCT_COMPAT_RT_VERSION 12080
2// src/core/expert_cache.cpp - R4's slot storage and residency table.  Read the
3// header first.
4#define DPCT_PROFILING_ENABLED
5#include <sycl/sycl.hpp>
6#include <dpct/dpct.hpp>
7#include "strata/sycl_queue.hpp"
8#include "strata/core/expert_cache.hpp"
9
10// #533's segmented cache uses CUDA's virtual memory management (cuMem*): not on HIP, neither the RDNA backend nor
11// the gfx906 compat build (PR #638), which compiles this file as HIP without STRATA_USE_HIP
12#define STRATA_EC_NO_VMM 1   // SYCL port: no driver virtual memory management on Level Zero (--vram-elastic is CUDA-only, #533)
13
14#if !defined(STRATA_EC_NO_VMM)
15   // #533: the virtual memory management types (the functions come through the
16   // runtime's entry points)
17#endif
18
19#include <algorithm>
20#include <atomic>
21#include <set>
22#include <cstdio>
23#include <filesystem>
24#include <cstdlib>
25#include <utility>
26#include <cstring>
27
28namespace strata::core {
29
30// Local (card) memory this process holds, from the DRM clients' fdinfo (i915: drm-total-local0, xe: drm-total-vram0).
31// Level Zero's free-memory query reads the constant total on an Arc A750 (i915): the engine then sized its caches
32// from the whole card and over-allocated (UR_RESULT_ERROR_OUT_OF_HOST_MEMORY at the first launch). Other processes'
33// memory is not in this number, so it only ever LOWERS the figure the driver gave.  0 = not available.
34static unsigned long long own_drm_local_bytes() {
35#if defined(__linux__)
36    unsigned long long total = 0;
37    std::error_code ec;
38    std::set<unsigned long long> seen;   // one DRM client may appear under several fds
39    for (const auto& e : std::filesystem::directory_iterator("/proc/self/fdinfo", ec)) {
40        std::FILE* f = std::fopen(e.path().string().c_str(), "r");
41        if (f == nullptr) continue;
42        char line[256];
43        bool drm = false;
44        unsigned long long client = 0, bytes = 0;
45        while (std::fgets(line, sizeof line, f)) {
46            unsigned long long v = 0;
47            char unit[8] = {0};
48            if (std::strncmp(line, "drm-driver:", 11) == 0) drm = true;
49            else if (std::sscanf(line, "drm-client-id: %llu", &client) == 1) {}
50            else if ((std::sscanf(line, "drm-total-local0: %llu %7s", &v, unit) >= 1 ||
51                      std::sscanf(line, "drm-total-vram0: %llu %7s", &v, unit) >= 1) && v > 0) {
52                const unsigned long long mul = unit[0] == 'K' ? 1024ull : unit[0] == 'M' ? 1048576ull
53                                             : unit[0] == 'G' ? 1073741824ull : 1ull;
54                bytes += v * mul;
55            }
56        }
57        std::fclose(f);
58        if (drm && bytes > 0 && seen.insert(client).second) total += bytes;
59    }
60    return total;
61#else
62    return 0;
63#endif
64}
65
66// See the header.  NVIDIA's DGX Spark Porting Guide (section 5.5, "Memory reporting on UMA systems") recommends the same:
67// not to rely on cudaMemGetInfo alone but to count the memory the OS can reclaim.  Swap is not counted here (unlike
68// NVIDIA's reference snippet): an expert cache that pushes the system into swap would be far slower than a smaller one.
69size_t device_free_bytes() try {
70    size_t free_b = 0, total_b = 0;
71    /*
72    DPCT1106: 'cudaMemGetInfo' was migrated with the Intel extensions for
73    device information which may not be supported by all compilers or runtimes.
74    You may need to adjust the code.
75    */
76    dpct::get_current_device().get_memory_info(free_b, total_b);
77    // An Arc on the xe driver whose Level Zero has no ext_intel_free_memory reports 0 free (Arc A770 16 GB, xe, #1545):
78    // --expert-cache auto then sized its caches from 0 bytes.  0 with a known total means "the driver does not know", so on
79    // Linux (xe is Linux-only) the card's total less what this process holds (the DRM fdinfo, as for the A750/i915 below)
80    // is used instead.  Like that figure it does not see other processes' memory.  Elsewhere the 0 stands.
81#if defined(__linux__)
82    if (free_b == 0 && total_b > 0)
83        if (const unsigned long long own = own_drm_local_bytes(); own < total_b) {
84            static std::atomic<bool> said{false};
85            if (!said.exchange(true))
86                std::fprintf(stderr, "strata: the driver reports no free card memory (xe without ext_intel_free_memory); sizing from the DRM fdinfo (this process holds %.2f GiB)\n", (double) own / 1073741824.0);
87            free_b = (size_t) (total_b - own);
88        }
89#endif
90    // #1440: own_drm_local_bytes() sums every DRM fd of the process, i.e. both cards on a layer split, and would charge the
91    // first card's cache to the second. With more than one GPU it runs only where the driver reports the whole card as
92    // free (Arc A750/i915); a one-GPU run keeps the figure it always had.
93    if (const unsigned long long own = (free_b + (16ull << 20) >= total_b || dpct::device_count() <= 1)
94                                           ? own_drm_local_bytes() : 0ull;
95        own > 0 && total_b > own && total_b - own < free_b) {
96        static std::atomic<bool> said{false};
97        if (free_b + (16ull << 20) >= total_b && !said.exchange(true))
98            std::fprintf(stderr, "strata: the driver reports the whole card as free although this process holds %.2f GiB of it (Arc A750/i915 does this); sizing from the DRM fdinfo instead\n", (double) own / 1073741824.0);
99        free_b = (size_t) (total_b - own);
100    }
101#if defined(__linux__) && !defined(STRATA_HIP_GFX906)   // (the gfx906 compat layer has no cudaDevAttrIntegrated; that GPU is discrete)
102    // per device: a box can mix an integrated GPU (an APU) with a discrete one, and the answer is the CURRENT device's
103    static std::atomic<int> uma_cache[64];   // 0 unknown, 1 integrated (unified memory), 2 discrete
104    bool unified_memory = false;
105    {
106        int dev = 0, v = 0;
107        if (DPCT_CHECK_ERROR(dev = dpct::get_current_device_id()) == 0 &&
108            dev >= 0 && dev < 64) {
109            int c = uma_cache[dev].load(std::memory_order_acquire);
110            if (c == 0) {
111                c = DPCT_CHECK_ERROR(
112                        v = dpct::get_device(dev).get_integrated()) == 0 &&
113                            v
114                        ? 1
115                        : 2;
116                uma_cache[dev].store(c, std::memory_order_release);
117            }
118            unified_memory = c == 1;
119        }
120    }
121    if (unified_memory) {
122        if (FILE* m = std::fopen("/proc/meminfo", "r")) {
123            char line[256];
124            unsigned long long kb = 0;
125            while (std::fgets(line, sizeof line, m))
126                if (std::sscanf(line, "MemAvailable: %llu kB", &kb) == 1) break;
127            std::fclose(m);
128            // STRATA_UMA_HEADROOM_GIB: a whole number of GiB, 0..1024; anything else keeps the default 6 (said once)
129            static const long gib = [] {
130                const char* h = std::getenv("STRATA_UMA_HEADROOM_GIB");
131                if (h == nullptr) return 6L;
132                char* end = nullptr;
133                const long v = std::strtol(h, &end, 10);
134                if (end != h && *end == '\0' && v >= 0 && v <= 1024) return v;
135                std::fprintf(stderr, "strata: STRATA_UMA_HEADROOM_GIB=%s is not a whole number of GiB (0-1024): using 6\n", h);
136                return 6L;
137            }();
138            const unsigned long long head = (unsigned long long) gib << 30;
139            const unsigned long long avail = kb << 10;
140            if (avail > head && avail - head > free_b) free_b = (size_t) (avail - head);
141        }
142    }
143#endif
144    return free_b;
145}
146catch (sycl::exception const &exc) {
147  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
148            << ", line:" << __LINE__ << std::endl;
149  std::exit(1);
150}
151
152bool read_expert_profile(const std::string& path, int64_t n_layers, int64_t n_expert,
153                         std::vector<std::pair<int32_t, int32_t>>& ranked, int64_t& slots, std::string& err) {
154    std::FILE* f = std::fopen(path.c_str(), "rb");
155    if (f == nullptr) {
156        err = "read_expert_profile: cannot open " + path;
157        return false;
158    }
159    char magic[4] = {0, 0, 0, 0};
160    uint32_t hdr[5] = {0, 0, 0, 0, 0};
161    if (std::fread(magic, 1, 4, f) != 4 || std::fread(hdr, 4, 5, f) != 5) {
162        std::fclose(f);
163        err = "read_expert_profile: " + path + " is too short to hold a header";
164        return false;
165    }
166    if (std::memcmp(magic, "STRP", 4) != 0) {
167        std::fclose(f);
168        err = "read_expert_profile: " + path + " does not start with STRP";
169        return false;
170    }
171    const uint32_t version = hdr[0], nl = hdr[1], ne = hdr[2], want = hdr[3], n_ranked = hdr[4];
172    if ((int64_t) nl != n_layers || (int64_t) ne != n_expert) {
173        std::fclose(f);
174        char buf[256];
175        std::snprintf(buf, sizeof buf,
176                      "read_expert_profile: %s is %ux%u but this model is %lldx%lld - it is a profile for a "
177                      "different artifact", path.c_str(), nl, ne, (long long) n_layers, (long long) n_expert);
178        err = buf;
179        return false;
180    }
181    if (n_ranked > want) {
182        std::fclose(f);
183        err = "read_expert_profile: the header claims more ranked pairs than slots";
184        return false;
185    }
186    ranked.assign(n_ranked, {0, 0});
187    std::vector<uint16_t> raw((size_t) n_ranked * 2);
188    if (n_ranked > 0 && std::fread(raw.data(), 2, (size_t) n_ranked * 2, f) != (size_t) n_ranked * 2) {
189        std::fclose(f);
190        err = "read_expert_profile: the ranked list is truncated";
191        return false;
192    }
193    std::fclose(f);
194    for (uint32_t i = 0; i < n_ranked; ++i) {
195        const int32_t l = (int32_t) raw[(size_t) i * 2], e = (int32_t) raw[(size_t) i * 2 + 1];
196        if (l < 0 || l >= n_layers || e < 0 || e >= n_expert) {
197            char buf[256];
198            std::snprintf(buf, sizeof buf, "read_expert_profile: pair %u is (layer %d, expert %d), out of range",
199                          i, l, e);
200            err = buf;
201            return false;
202        }
203        ranked[(size_t) i] = {l, e};
204    }
205    slots = (int64_t) want;
206    (void) version;   // a future format bumps it; the layout check above is what protects this reader today
207    return true;
208}
209
210std::vector<std::pair<int32_t, int32_t>> rank_learned_profile(int64_t n_layers, int64_t n_expert,
211                                                              const std::vector<uint8_t>& resident,
212                                                              const std::vector<double>& heat,
213                                                              const std::vector<std::pair<int32_t, int32_t>>& prior) {
214    const size_t n = (size_t) (n_layers * n_expert);
215    std::vector<int64_t> prior_rank(n, INT64_MAX);
216    for (size_t r = 0; r < prior.size(); ++r) {
217        const auto [l, e] = prior[r];
218        if (l >= 0 && l < n_layers && e >= 0 && e < n_expert) {
219            int64_t& pr = prior_rank[(size_t) (l * n_expert + e)];
220            if (pr == INT64_MAX) pr = (int64_t) r;
221        }
222    }
223    std::vector<int64_t> order(n);
224    for (size_t i = 0; i < n; ++i) order[i] = (int64_t) i;
225    auto res = [&](int64_t i) { return (size_t) i < resident.size() && resident[(size_t) i] != 0; };
226    auto ht = [&](int64_t i) { return (size_t) i < heat.size() ? heat[(size_t) i] : 0.0; };
227    std::stable_sort(order.begin(), order.end(), [&](int64_t a, int64_t b) {
228        if (res(a) != res(b)) return res(a);
229        if (ht(a) != ht(b)) return ht(a) > ht(b);
230        if (prior_rank[(size_t) a] != prior_rank[(size_t) b]) return prior_rank[(size_t) a] < prior_rank[(size_t) b];
231        return a < b;
232    });
233    std::vector<std::pair<int32_t, int32_t>> ranked(n);
234    for (size_t r = 0; r < n; ++r)
235        ranked[r] = {(int32_t) (order[r] / n_expert), (int32_t) (order[r] % n_expert)};
236    return ranked;
237}
238
239bool write_expert_profile(const std::string& path, int64_t n_layers, int64_t n_expert,
240                          const std::vector<std::pair<int32_t, int32_t>>& ranked, std::string& err) {
241    if (n_layers <= 0 || n_expert <= 0 || n_layers > 65535 || n_expert > 65535) {
242        err = "write_expert_profile: the model's layout does not fit the format";
243        return false;
244    }
245    std::vector<int32_t> table((size_t) (n_layers * n_expert), -1);
246    std::vector<uint16_t> pairs;
247    pairs.reserve(ranked.size() * 2);
248    for (size_t r = 0; r < ranked.size(); ++r) {
249        const auto [l, e] = ranked[r];
250        if (l < 0 || l >= n_layers || e < 0 || e >= n_expert) {
251            err = "write_expert_profile: a ranked pair is out of range";
252            return false;
253        }
254        table[(size_t) (l * n_expert + e)] = (int32_t) r;
255        pairs.push_back((uint16_t) l);
256        pairs.push_back((uint16_t) e);
257    }
258    const uint32_t hdr[5] = {1u, (uint32_t) n_layers, (uint32_t) n_expert, (uint32_t) ranked.size(),
259                             (uint32_t) ranked.size()};
260    const std::string tmp = path + ".tmp";
261    std::FILE* f = std::fopen(tmp.c_str(), "wb");
262    if (f == nullptr) {
263        err = "write_expert_profile: cannot create " + tmp;
264        return false;
265    }
266    // the format is little-endian (make_profile.py's "<"): so is every machine this engine runs on
267    bool ok = std::fwrite("STRP", 1, 4, f) == 4 && std::fwrite(hdr, 4, 5, f) == 5 &&
268              (pairs.empty() || std::fwrite(pairs.data(), 2, pairs.size(), f) == pairs.size()) &&
269              std::fwrite(table.data(), 4, table.size(), f) == table.size();
270    ok = (std::fclose(f) == 0) && ok;
271    std::error_code ec;
272    if (ok) std::filesystem::rename(tmp, path, ec);   // replaces an existing file (MoveFileEx / rename(2))
273    if (!ok || ec) {
274        std::filesystem::remove(tmp, ec);
275        err = "write_expert_profile: cannot write " + path;
276        return false;
277    }
278    return true;
279}
280
281ExpertCache::~ExpertCache() { close(); }
282
283// ---- #533: the segmented arena (--vram-elastic).  The driver API's virtual memory functions, looked up through the
284// runtime (no link against the driver library): one address range for the whole arena, backed by physical segments,
285// and the tail's segments unmapped / mapped again later.  Nothing here runs unless a segment size was set.
286#if !defined(STRATA_EC_NO_VMM)
287namespace {
288struct Vmm {
289    int(CUDAAPI *device_get)(int *, int) = nullptr;
290    int(CUDAAPI *attribute)(int *, CUdevice_attribute, int) = nullptr;
291    int(CUDAAPI *granularity)(
292        size_t *, const dpct::experimental::mem_prop *,
293        sycl::ext::oneapi::experimental::granularity_mode) = nullptr;
294    int(CUDAAPI *reserve)(dpct::device_ptr *, size_t, size_t, dpct::device_ptr,
295                          unsigned long long) = nullptr;
296    int(CUDAAPI *address_free)(dpct::device_ptr, size_t) = nullptr;
297    int(CUDAAPI *create)(dpct::experimental::physical_mem_ptr *, size_t,
298                         const dpct::experimental::mem_prop *,
299                         unsigned long long) = nullptr;
300    int(CUDAAPI *release)(dpct::experimental::physical_mem_ptr) = nullptr;
301    int(CUDAAPI *map)(dpct::device_ptr, size_t, size_t,
302                      dpct::experimental::physical_mem_ptr,
303                      unsigned long long) = nullptr;
304    int(CUDAAPI *unmap)(dpct::device_ptr, size_t) = nullptr;
305    int(CUDAAPI *set_access)(dpct::device_ptr, size_t,
306                             const dpct::experimental::mem_access_desc *,
307                             size_t) = nullptr;
308    bool ok = false;
309};
310
311template <class F> bool entry(const char *name, F &f) try {
312    void* p = nullptr;
313    cudaDriverEntryPointQueryResult q{};
314#if DPCT_COMPAT_RT_VERSION >= 12050
315    /*
316    DPCT1007: Migration of cudaGetDriverEntryPointByVersion is not
317    supported.
318    */
319    const dpct::err0 e = cudaGetDriverEntryPointByVersion(
320        name, &p, 12000, cudaEnableDefault, &q);
321#else
322    const cudaError_t e = cudaGetDriverEntryPoint(name, &p, cudaEnableDefault, &q);
323#endif
324    if (e != 0 || q != cudaDriverEntryPointSuccess || p == nullptr) {
325        /*
326        DPCT1010: SYCL uses exceptions to report errors and does not use the
327        error codes. The cudaGetLastError function call was replaced with 0. You
328        need to rewrite this code.
329        */
330        (void)0;
331        return false;
332    }
333    f = reinterpret_cast<F>(p);
334    return true;
335}
336catch (sycl::exception const &exc) {
337  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
338            << ", line:" << __LINE__ << std::endl;
339  std::exit(1);
340}
341
342const Vmm& vmm() {
343    static const Vmm v = [] {
344        Vmm x;
345        x.ok = entry("cuDeviceGet", x.device_get) && entry("cuDeviceGetAttribute", x.attribute) &&
346               entry("cuMemGetAllocationGranularity", x.granularity) && entry("cuMemAddressReserve", x.reserve) &&
347               entry("cuMemAddressFree", x.address_free) && entry("cuMemCreate", x.create) &&
348               entry("cuMemRelease", x.release) && entry("cuMemMap", x.map) && entry("cuMemUnmap", x.unmap) &&
349               entry("cuMemSetAccess", x.set_access);
350        return x;
351    }();
352    return v;
353}
354
355dpct::experimental::mem_prop device_prop(int dev) {
356    dpct::experimental::mem_prop prop{};
357    prop.type = 0;
358    prop.location.type = 1;
359    prop.location.id = dev;
360    return prop;
361}
362
363// one segment: a physical allocation mapped at `va`, readable and writable by this device
364bool map_segment(const Vmm &v, int dev, dpct::device_ptr va, size_t bytes,
365                 unsigned long long &handle) {
366    const dpct::experimental::mem_prop prop = device_prop(dev);
367    dpct::experimental::physical_mem_ptr h = 0;
368    if (v.create(&h, bytes, &prop, 0) != 0) return false;
369    if (v.map(va, bytes, 0, h, 0) != 0) {
370        v.release(h);
371        return false;
372    }
373    dpct::experimental::mem_access_desc access{};
374    access.location.type = 1;
375    access.location.id = dev;
376    access.flags =
377        sycl::ext::oneapi::experimental::address_access_mode::read_write;
378    if (v.set_access(va, bytes, &access, 1) != 0) {
379        v.unmap(va, bytes);
380        v.release(h);
381        return false;
382    }
383    handle = (unsigned long long) h;
384    return true;
385}
386}  // namespace
387#endif
388
389bool ExpertCache::open_segmented(uint64_t want, std::string &err) try {
390#if defined(STRATA_EC_NO_VMM)
391    (void) want;
392    err = "ExpertCache: --vram-elastic (a segmented expert cache) is CUDA-only for now";
393    return false;
394#else
395    const Vmm& v = vmm();
396    int dev = 0, supported = 0;
397    int cu = 0;
398    if (!v.ok || DPCT_CHECK_ERROR(dev = dpct::get_current_device_id()) != 0 ||
399        v.device_get(&cu, dev) != 0 ||
400        v.attribute(&supported,
401                    CU_DEVICE_ATTRIBUTE_VIRTUAL_MEMORY_MANAGEMENT_SUPPORTED,
402                    cu) != 0 ||
403        !supported) {
404        err = "ExpertCache: --vram-elastic needs the driver's virtual memory management, which this GPU or driver "
405              "does not offer";
406        return false;
407    }
408    const dpct::experimental::mem_prop prop = device_prop(dev);
409    size_t gran = 0;
410    if (v.granularity(
411            &gran, &prop,
412            sycl::ext::oneapi::experimental::granularity_mode::recommended) !=
413            0 ||
414        gran == 0) {
415        err = "ExpertCache: cannot read the driver's allocation granularity";
416        return false;
417    }
418    const uint64_t g = (uint64_t) gran;
419    const uint64_t total = (want + g - 1) / g * g;
420    seg_ = (int64_t) (((uint64_t) seg_req_ + g - 1) / g * g);
421    dpct::device_ptr va = 0;
422    if (v.reserve(&va, (size_t)total, 0, 0, 0) != 0) {
423        err = "ExpertCache: cannot reserve the address range of the segmented expert cache";
424        return false;
425    }
426    base_ = reinterpret_cast<uint8_t*>(va);
427    reserved_ = total;
428    for (uint64_t at = 0; at < total; at += (uint64_t) seg_) {
429        segs_.push_back(0);
430        seg_size_.push_back((int64_t) std::min<uint64_t>((uint64_t) seg_, total - at));
431    }
432    for (size_t i = 0; i < segs_.size(); ++i) {
433        if (!map_segment(v, dev,
434                         va + (dpct::device_ptr)((uint64_t)i * (uint64_t)seg_),
435                         (size_t)seg_size_[i], segs_[i])) {
436            char buf[200];
437            std::snprintf(buf, sizeof buf, "ExpertCache: cudaMalloc failed: segment %zu of %zu (%.2f GiB) of the "
438                          "segmented cache could not be allocated", i + 1, segs_.size(),
439                          (double) seg_size_[i] / 1073741824.0);
440            err = buf;   // "cudaMalloc failed": the auto cache's smaller-retry path reads it as an allocation failure
441            release_segmented();
442            return false;
443        }
444        mapped_segs_ = (int64_t) i + 1;
445    }
446    // the reserved VA, so device_offset_end can place a borrowed prompt buffer or a resident expert inside it (the GEMM
447    // stages an operand that lies more than 4 GiB in; oneMKL misreads such an operand's last partial tile)
448    strata::device_alloc_register(base_, (size_t) reserved_);
449    return true;
450#endif
451}
452catch (sycl::exception const &exc) {
453  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
454            << ", line:" << __LINE__ << std::endl;
455  std::exit(1);
456}
457
458void ExpertCache::release_segmented() {
459#if !defined(STRATA_EC_NO_VMM)
460    const Vmm& v = vmm();
461    if (base_ != nullptr) dpct::get_current_device().queues_wait_and_throw();
462    const dpct::device_ptr va = reinterpret_cast<dpct::device_ptr>(base_);
463    for (size_t i = 0; i < segs_.size(); ++i)
464        if (segs_[i] != 0) {
465            v.unmap(va + (dpct::device_ptr)((uint64_t)i * (uint64_t)seg_),
466                    (size_t)seg_size_[i]);
467            v.release((dpct::experimental::physical_mem_ptr)segs_[i]);
468        }
469    if (base_ != nullptr && reserved_ > 0) v.address_free(va, (size_t) reserved_);
470#endif
471    segs_.clear();
472    seg_size_.clear();
473    mapped_segs_ = 0;
474    reserved_ = 0;
475    strata::device_alloc_unregister(base_);
476    base_ = nullptr;
477}
478
479int64_t ExpertCache::mapped_bytes() const {
480    if (segs_.empty()) return base_ != nullptr ? full_bytes() : 0;
481    int64_t b = 0;
482    for (int64_t i = 0; i < mapped_segs_; ++i) b += seg_size_[(size_t) i];
483    return b;
484}
485
486int64_t ExpertCache::slots_within(int64_t bytes) const {
487    if (bytes >= full_bytes()) return slots_;
488    if (bytes <= 0) return 0;
489    if (off_.empty()) return blob_ > 0 ? bytes / blob_ : 0;
490    // off_[i + 1] is slot i's end: count the slots whose end is at most `bytes`
491    return (int64_t) (std::upper_bound(off_.begin() + 1, off_.end(), (uint64_t) bytes) - (off_.begin() + 1));
492}
493
494bool ExpertCache::shrink(int64_t keep_bytes, std::string &err) try {
495    if (segs_.empty()) {
496        err = "the expert cache is not segmented (the engine needs --vram-elastic)";
497        return false;
498    }
499#if defined(STRATA_EC_NO_VMM)
500    (void) keep_bytes;
501    return false;
502#else
503    const Vmm& v = vmm();
504    int64_t keep = 0, at = 0;   // the segments [0, keep) hold the first keep_bytes
505    while (keep < (int64_t) segs_.size() && at < keep_bytes) at += seg_size_[(size_t) keep++];
506    if (keep >= mapped_segs_) return true;
507    if (DPCT_CHECK_ERROR(dpct::get_current_device().queues_wait_and_throw()) !=
508        0) {
509        /*
510        DPCT1009: SYCL reports errors using exceptions and does not use
511        error codes. Please replace the "get_error_string_dummy(...)" with a
512        real error-handling function.
513        */
514        /*
515        DPCT1010: SYCL uses exceptions to report errors and does not use the
516        error codes. The cudaGetLastError function call was replaced with 0. You
517        need to rewrite this code.
518        */
519        err = std::string("the device failed before the cache shrank: ") +
520              dpct::get_error_string_dummy(0);
521        return false;
522    }
523    const dpct::device_ptr va = reinterpret_cast<dpct::device_ptr>(base_);
524    for (int64_t i = mapped_segs_ - 1; i >= keep; --i) {
525        const dpct::device_ptr p =
526            va + (dpct::device_ptr)((uint64_t)i * (uint64_t)seg_);
527        if (v.unmap(p, (size_t)seg_size_[(size_t)i]) != 0 ||
528            v.release((dpct::experimental::physical_mem_ptr)segs_[(size_t)i]) !=
529                0) {
530            err = "the driver refused to release an expert-cache segment";
531            live_slots_ = slots_within(mapped_bytes());
532            return false;
533        }
534        segs_[(size_t) i] = 0;
535        mapped_segs_ = i;
536    }
537    live_slots_ = slots_within(mapped_bytes());
538    return true;
539#endif
540}
541catch (sycl::exception const &exc) {
542  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
543            << ", line:" << __LINE__ << std::endl;
544  std::exit(1);
545}
546
547bool ExpertCache::grow(int64_t want_bytes, std::string& err) {
548    if (segs_.empty()) {
549        err = "the expert cache is not segmented (the engine needs --vram-elastic)";
550        return false;
551    }
552#if defined(STRATA_EC_NO_VMM)
553    (void) want_bytes;
554    return false;
555#else
556    const Vmm& v = vmm();
557    int dev = 0;
558    dev = dpct::get_current_device_id();
559    const dpct::device_ptr va = reinterpret_cast<dpct::device_ptr>(base_);
560    int64_t at = mapped_bytes();
561    while (mapped_segs_ < (int64_t) segs_.size() && at + seg_size_[(size_t) mapped_segs_] <= want_bytes) {
562        const size_t i = (size_t) mapped_segs_;
563        if (!map_segment(v, dev,
564                         va + (dpct::device_ptr)((uint64_t)i * (uint64_t)seg_),
565                         (size_t)seg_size_[i], segs_[i])) {
566            /*
567            DPCT1010: SYCL uses exceptions to report errors and does not use
568            the error codes. The cudaGetLastError function call was replaced
569            with 0. You need to rewrite this code.
570            */
571            (void)0;
572            err = "the driver has no VRAM for another expert-cache segment";
573            live_slots_ = slots_within(mapped_bytes());
574            return false;
575        }
576        at += seg_size_[i];
577        ++mapped_segs_;
578    }
579    live_slots_ = slots_within(mapped_bytes());
580    return true;
581#endif
582}
583
584#if defined(STRATA_USE_HIP)
585bool ExpertCache::ensure_blocking_staging(std::size_t bytes, std::string& err) {
586    if (bytes <= blocking_staging_bytes_) return true;
587    void* next = nullptr;
588    const cudaError_t status = cudaHostAlloc(&next, bytes, cudaHostAllocDefault);
589    if (status != cudaSuccess) {
590        err = std::string("ExpertCache: HIP blocking staging allocation: ") + cudaGetErrorString(status);
591        return false;
592    }
593    if (blocking_staging_) (void) cudaFreeHost(blocking_staging_);
594    blocking_staging_ = static_cast<uint8_t*>(next);
595    blocking_staging_bytes_ = bytes;
596    return true;
597}
598#endif
599
600namespace {
601bool g_cache_vmm = false;   // set_vmm
602}  // namespace
603
604void ExpertCache::set_vmm(bool enabled) { g_cache_vmm = enabled; }
605
606bool ExpertCache::open(int64_t n_slots, int64_t n_layers, int64_t n_expert, int64_t blob_bytes,
607                       std::string& err) {
608    close();
609    if (n_slots <= 0) {
610        err = "ExpertCache: n_slots must be positive";
611        return false;
612    }
613    if (n_layers <= 0 || n_expert <= 0 || blob_bytes <= 0) {
614        err = "ExpertCache: n_layers, n_expert and blob_bytes must all be positive";
615        return false;
616    }
617
618    const uint64_t want = (uint64_t) n_slots * (uint64_t) blob_bytes;
619
620    // ---- **THE ALLOCATION IS CHECKED AGAINST THE CARD, NOT AGAINST THE REQUEST.**
621    //
622    // `cudaMalloc` failing is the easy case. The one that matters is a machine where the weights already own
623    // most of VRAM: the cache then takes what is left and `slots()` would report the number ASKED FOR while
624    // `device_slot()` walks off the end. So the free-VRAM figure is read and compared BEFORE the allocation,
625    // and the two numbers are named in the refusal.
626    size_t free_b = 0, total_b = 0;
627    /*
628    DPCT1106: 'cudaMemGetInfo' was migrated with the Intel extensions for
629    device information which may not be supported by all compilers or runtimes.
630    You may need to adjust the code.
631    */
632    if (DPCT_CHECK_ERROR(
633            dpct::get_current_device().get_memory_info(free_b, total_b)) == 0) {
634        free_b = device_free_bytes();   // unified memory: what the OS can give back counts (see the header)
635        if ((uint64_t) free_b < want) {
636            char buf[320];
637            std::snprintf(buf, sizeof buf,
638                          "ExpertCache: %lld slots x %lld B = %.2f GiB, but only %.2f GiB of VRAM is free "
639                          "(%.2f GiB of %.2f GiB total). Lower --expert-cache.",
640                          (long long) n_slots, (long long) blob_bytes, (double) want / 1073741824.0,
641                          (double) free_b / 1073741824.0, (double) (total_b - free_b) / 1073741824.0,
642                          (double) total_b / 1073741824.0);
643            err = buf;
644            return false;
645        }
646    }
647
648    if (seg_req_ > 0) {   // #533: --vram-elastic: physical segments behind one address range (zeroed below)
649        if (!open_segmented(want, err)) return false;
650    } else if (g_cache_vmm && vmm_available()) {
651        // the elastic K/V: every chunk mapped now; the K/V may later take some of them (and give them back)
652        auto r = std::make_unique<VmmRange>();
653        if (!r->reserve(want) || !r->map_range(0, r->chunks(), [] { return (VmmChunk) 0; })) {
654            char buf[256];
655            std::snprintf(buf, sizeof buf, "ExpertCache: mapping %.2f GiB of VRAM failed: out of memory",
656                          (double) want / 1073741824.0);
657            err = buf;
658            return false;
659        }
660        base_ = r->base();
661        vmm_ = std::move(r);
662    } else if (DPCT_CHECK_ERROR(
663                   base_ = (uint8_t *)strata::malloc_device_guarded(
664                       (size_t)want, dpct::get_in_order_queue(), "expert cache arena")) != 0 ||
665               base_ == nullptr) {   // Level Zero answers a too-large allocation with null, not an exception
666        // (an Arc A750 caps one allocation at 4 GiB unless UR_L0_ENABLE_RELAXED_ALLOCATION_LIMITS=1)
667        base_ = nullptr;
668        char buf[256];
669        std::snprintf(
670            buf, sizeof buf, "ExpertCache: cudaMalloc(%.2f GiB) failed: %s",
671            /*
672            DPCT1009: SYCL reports errors using exceptions and does not use
673            error codes. Please replace the "get_error_string_dummy(...)" with a
674            real error-handling function.
675            */
676            /*
677            DPCT1010: SYCL uses exceptions to report errors and does not
678            use the error codes. The cudaGetLastError function call was replaced
679            with 0. You need to rewrite this code.
680            */
681            (double)want / 1073741824.0, dpct::get_error_string_dummy(0));
682        err = buf;
683        return false;
684    }
685    // Zeroed so a slot read before it is filled is a DETERMINISTIC wrong answer rather than whatever the
686    // allocator handed back.  A stale block of a previous process's memory would still sum to finite floats.
687    if (DPCT_CHECK_ERROR(
688            (strata::big_fill_zero(dpct::get_in_order_queue(), base_, (size_t)want), 0)) !=
689        0) {
690        err = "ExpertCache: cudaMemset of the slot arena failed";
691        close();
692        return false;
693    }
694
695    residency_.assign((size_t) (n_layers * n_expert), kNotResident);
696    slots_ = n_slots;
697    live_slots_ = n_slots;
698    n_layers_ = n_layers;
699    n_expert_ = n_expert;
700    blob_ = blob_bytes;
701#if defined(STRATA_USE_HIP)
702    if (!ensure_blocking_staging((std::size_t) blob_, err)) {
703        close();
704        return false;
705    }
706#endif
707    next_free_ = 0;
708    fills_ = 0;
709    admitted_ = 0;
710    // R4.2g: each layer starts at the bottom of its own range.  Built here rather than lazily so `admit`
711    // stays allocation-free on the token path.
712    layer_next_.assign((size_t) (n_layers > 0 ? n_layers : 0), 0);
713    for (int64_t l = 0; l < n_layers; ++l) {
714        int64_t lo = 0, hi = 0;
715        layer_slot_range(l, lo, hi);
716        layer_next_[(size_t) l] = (int32_t) lo;
717    }
718    return true;
719}
720
721bool ExpertCache::open_sized(const std::vector<int64_t>& slot_bytes, int64_t n_layers, int64_t n_expert,
722                             std::string& err) {
723    if (slot_bytes.empty()) { err = "ExpertCache: no slots"; return false; }
724    int64_t mx = 0;
725    std::vector<uint64_t> off(slot_bytes.size() + 1, 0);
726    for (size_t i = 0; i < slot_bytes.size(); ++i) {
727        // 256-byte aligned slots, so every blob starts where the kernels' vector loads expect it
728        off[i + 1] = off[i] + ((uint64_t) slot_bytes[i] + 255) / 256 * 256;
729        mx = slot_bytes[i] > mx ? slot_bytes[i] : mx;
730    }
731    // one allocation of the summed size, through the uniform path's checks: n "slots" of 1 byte
732    if (!open((int64_t) off.back(), n_layers, n_expert, 1, err)) return false;
733    slots_ = (int64_t) slot_bytes.size();
734    live_slots_ = slots_;
735    blob_ = mx;
736    off_ = std::move(off);
737#if defined(STRATA_USE_HIP)
738    if (!ensure_blocking_staging((std::size_t) blob_, err)) {
739        close();
740        return false;
741    }
742#endif
743    // #369: each layer's cursor at the bottom of its own range, as open() seeds it - open() above ran on byte-sized
744    // "slots", so its seeds are not slot indices
745    layer_next_.assign((size_t) (n_layers > 0 ? n_layers : 0), 0);
746    for (int64_t l = 0; l < n_layers; ++l) {
747        int64_t lo = 0, hi = 0;
748        layer_slot_range(l, lo, hi);
749        layer_next_[(size_t) l] = (int32_t) lo;
750    }
751    return true;
752}
753
754void ExpertCache::close() {
755#if defined(STRATA_USE_HIP)
756    if (blocking_staging_) (void) cudaFreeHost(blocking_staging_);
757    blocking_staging_ = nullptr;
758    blocking_staging_bytes_ = 0;
759#endif
760    off_.clear();
761    if (!segs_.empty()) {
762        release_segmented();
763    } else if (vmm_) {
764        vmm_.reset();   // unmaps and frees every chunk it still holds
765        strata::device_alloc_unregister(base_);
766        base_ = nullptr;
767    } else if (base_ != nullptr) {
768        strata::device_alloc_unregister(base_);
769        sycl::free(base_, dpct::get_in_order_queue());
770        base_ = nullptr;
771    }
772    residency_.clear();
773    slots_ = 0;
774    live_slots_ = 0;
775    n_layers_ = 0;
776    n_expert_ = 0;
777    blob_ = 0;
778    next_free_ = 0;
779    fills_ = 0;
780    admitted_ = 0;
781    layer_next_.clear();
782}
783
784/// R4.2g.  Layer `l` owns `[l*q, (l+1)*q)` with `q = slots_ / n_layers_`; the LAST layer takes whatever is
785/// left over, so the ranges always cover `0..slots_` exactly and no slot is orphaned by the division.
786void ExpertCache::layer_slot_range(int64_t layer, int64_t& lo, int64_t& hi) const {
787    lo = 0;
788    hi = 0;
789    if (n_layers_ <= 0 || slots_ <= 0 || layer < 0 || layer >= n_layers_) return;
790    const int64_t q = slots_ / n_layers_;
791    lo = layer * q;
792    hi = (layer == n_layers_ - 1) ? slots_ : (layer + 1) * q;
793}
794
795int32_t ExpertCache::slot_of(int64_t layer, int64_t expert) const {
796    if (layer < 0 || layer >= n_layers_ || expert < 0 || expert >= n_expert_) return kNotResident;
797    return residency_[(size_t) (layer * n_expert_ + expert)];
798}
799
800int32_t ExpertCache::admit(int64_t layer, int64_t expert) {
801    if (layer < 0 || layer >= n_layers_ || expert < 0 || expert >= n_expert_) return kNotResident;
802    const size_t at = (size_t) (layer * n_expert_ + expert);
803    if (residency_[at] != kNotResident) return residency_[at];
804    // R4.2g: THE PER-LAYER PATH.  Same "no eviction" rule, but the ceiling is this layer's own range rather
805    // than one counter shared by all 48 - which is what confined the measured hit rate to 2.97%.
806    if (per_layer_) {
807        if (layer_next_.empty()) return kNotResident;
808        int64_t lo = 0, hi = 0;
809        layer_slot_range(layer, lo, hi);
810        if ((int64_t) layer_next_[(size_t) layer] >= hi) return kNotResident;   // this layer's quota is full
811        residency_[at] = layer_next_[(size_t) layer]++;
812        ++admitted_;
813        return residency_[at];
814    }
815    if (next_free_ >= slots_) return kNotResident;   // full: no eviction, deliberately - see the header
816    residency_[at] = (int32_t) next_free_;
817    return (int32_t) next_free_++;
818}
819
820uint8_t* ExpertCache::device_slot(int32_t slot) {
821    if (slot < 0 || slot >= slots_) return nullptr;
822    if (!off_.empty()) return base_ + off_[(size_t) slot];
823    return base_ + (size_t) slot * (size_t) blob_;
824}
825
826const uint8_t* ExpertCache::device_slot(int32_t slot) const {
827    if (slot < 0 || slot >= slots_) return nullptr;
828    if (!off_.empty()) return base_ + off_[(size_t) slot];
829    return base_ + (size_t) slot * (size_t) blob_;
830}
831
832bool ExpertCache::fill_slot(int32_t slot, const uint8_t *host_blob,
833                            void *stream, std::string &err, int64_t bytes) try {
834    const size_t n = (size_t) (bytes > 0 && bytes <= blob_ ? bytes : blob_);
835    uint8_t* dst = device_slot(slot);
836    if (dst == nullptr) {
837        err = "ExpertCache::fill_slot: slot " + std::to_string(slot) + " is outside 0.." +
838              std::to_string(slots_ - 1);
839        return false;
840    }
841    if (host_blob == nullptr) {
842        err = "ExpertCache::fill_slot: the host blob is null";
843        return false;
844    }
845    /*
846    DPCT1124: cudaMemcpyAsync is migrated to asynchronous memcpy API. While
847    the origin API might be synchronous, it depends on the type of operand
848    memory, so you may need to call wait() on event return by memcpy API to
849    ensure synchronization behavior.
850    */
851    const dpct::err0 e =
852        DPCT_CHECK_ERROR(strata::q_of(stream)->memcpy(dst, host_blob, n));
853    /*
854    DPCT1000: Error handling if-stmt was detected but could not be
855    rewritten.
856    */
857    if (e != 0) {
858        /*
859        DPCT1009: SYCL reports errors using exceptions and does not use
860        error codes. Please replace the "get_error_string_dummy(...)" with a
861        real error-handling function.
862        */
863        /*
864        DPCT1001: The statement could not be removed.
865        */
866        err = std::string("ExpertCache::fill_slot: ") +
867              dpct::get_error_string_dummy(e);
868        return false;
869    }
870    ++fills_;
871    return true;
872}
873catch (sycl::exception const &exc) {
874  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
875            << ", line:" << __LINE__ << std::endl;
876  std::exit(1);
877}
878
879bool ExpertCache::fill_slot_blocking(int32_t slot, const uint8_t *host_blob,
880                                     std::string &err, int64_t bytes) try {
881    const size_t n = (size_t) (bytes > 0 && bytes <= blob_ ? bytes : blob_);
882    uint8_t* dst = device_slot(slot);
883    if (dst == nullptr) {
884        err = "ExpertCache::fill_slot_blocking: slot outside the arena";
885        return false;
886    }
887    if (host_blob == nullptr) {
888        err = "ExpertCache::fill_slot_blocking: the host blob is null";
889        return false;
890    }
891#if defined(STRATA_USE_HIP)
892    // Bound HIP's pageable-source staging to one expert instead of repeatedly
893    // registering regions of the mmap. The blocking copy completes before reuse.
894    if (!blocking_staging_ || n > blocking_staging_bytes_) {
895        err = "ExpertCache::fill_slot_blocking: HIP staging buffer is too small";
896        return false;
897    }
898    std::memcpy(blocking_staging_, host_blob, n);
899    const cudaError_t e = cudaMemcpy(dst, blocking_staging_, n, cudaMemcpyHostToDevice);
900#else
901    /*
902    DPCT1114: cudaMemcpy is migrated to asynchronization memcpy, assuming
903    in the original code the source host memory is pageable memory. If the
904    memory is not pageable, call wait() on event return by memcpy API to ensure
905    synchronization behavior.
906    */
907    const dpct::err0 e =
908        DPCT_CHECK_ERROR(dpct::get_in_order_queue().memcpy(dst, host_blob, n).wait());
909#endif
910    /*
911    DPCT1000: Error handling if-stmt was detected but could not be
912    rewritten.
913    */
914    if (e != 0) {
915        /*
916        DPCT1009: SYCL reports errors using exceptions and does not use
917        error codes. Please replace the "get_error_string_dummy(...)" with a
918        real error-handling function.
919        */
920        /*
921        DPCT1001: The statement could not be removed.
922        */
923        err = std::string("ExpertCache::fill_slot_blocking: ") +
924              dpct::get_error_string_dummy(e);
925        return false;
926    }
927    ++fills_;
928    return true;
929}
930catch (sycl::exception const &exc) {
931  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
932            << ", line:" << __LINE__ << std::endl;
933  std::exit(1);
934}
935
936bool ExpertCache::fill_slot_queued(int32_t slot, const uint8_t *host_blob,
937                                   std::string &err, int64_t bytes) try {
938    const size_t n = (size_t) (bytes > 0 && bytes <= blob_ ? bytes : blob_);
939    uint8_t* dst = device_slot(slot);
940    if (dst == nullptr || host_blob == nullptr) {
941        err = dst == nullptr ? "ExpertCache::fill_slot_queued: slot outside the arena"
942                             : "ExpertCache::fill_slot_queued: the host blob is null";
943        return false;
944    }
945    /*
946    DPCT1124: cudaMemcpyAsync is migrated to asynchronous memcpy API. While
947    the origin API might be synchronous, it depends on the type of operand
948    memory, so you may need to call wait() on event return by memcpy API to
949    ensure synchronization behavior.
950    */
951    const dpct::err0 e =
952        DPCT_CHECK_ERROR(dpct::get_in_order_queue().memcpy(dst, host_blob, n).wait());
953    /*
954    DPCT1000: Error handling if-stmt was detected but could not be
955    rewritten.
956    */
957    if (e != 0) {
958        /*
959        DPCT1009: SYCL reports errors using exceptions and does not use
960        error codes. Please replace the "get_error_string_dummy(...)" with a
961        real error-handling function.
962        */
963        /*
964        DPCT1001: The statement could not be removed.
965        */
966        err = std::string("ExpertCache::fill_slot_queued: ") +
967              dpct::get_error_string_dummy(e);
968        return false;
969    }
970    ++fills_;
971    return true;
972}
973catch (sycl::exception const &exc) {
974  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
975            << ", line:" << __LINE__ << std::endl;
976  std::exit(1);
977}
978
979bool ExpertCache::sync_queued(std::string &err) try {
980    const dpct::err0 e = DPCT_CHECK_ERROR(dpct::get_in_order_queue().wait());
981    /*
982    DPCT1000: Error handling if-stmt was detected but could not be
983    rewritten.
984    */
985    if (e != 0) {
986        /*
987        DPCT1009: SYCL reports errors using exceptions and does not use
988        error codes. Please replace the "get_error_string_dummy(...)" with a
989        real error-handling function.
990        */
991        /*
992        DPCT1001: The statement could not be removed.
993        */
994        err = std::string("ExpertCache::sync_queued: ") +
995              dpct::get_error_string_dummy(e);
996        return false;
997    }
998    return true;
999}
1000catch (sycl::exception const &exc) {
1001  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
1002            << ", line:" << __LINE__ << std::endl;
1003  std::exit(1);
1004}
1005
1006bool ExpertCache::verify_slot(int32_t slot, const uint8_t *host_blob,
1007                              std::string &err, int64_t bytes) try {
1008    const int64_t nb = bytes > 0 && bytes <= blob_ ? bytes : blob_;
1009    const uint8_t* src = device_slot(slot);
1010    if (src == nullptr) {
1011        err = "ExpertCache::verify_slot: slot outside the arena";
1012        return false;
1013    }
1014    // `cudaMemcpy` and not `cudaMemcpyAsync`: this is a startup check, and a check that can be read before it
1015    // has happened is not a check.  It also synchronises the fills queued before it, which is what makes the
1016    // comparison meaningful.
1017    std::vector<uint8_t> got((size_t) nb);
1018    const dpct::err0 e = DPCT_CHECK_ERROR(
1019        dpct::get_in_order_queue().memcpy(got.data(), src, (size_t)nb).wait());
1020    /*
1021    DPCT1000: Error handling if-stmt was detected but could not be
1022    rewritten.
1023    */
1024    if (e != 0) {
1025        /*
1026        DPCT1009: SYCL reports errors using exceptions and does not use
1027        error codes. Please replace the "get_error_string_dummy(...)" with a
1028        real error-handling function.
1029        */
1030        /*
1031        DPCT1001: The statement could not be removed.
1032        */
1033        err = std::string("ExpertCache::verify_slot: ") +
1034              dpct::get_error_string_dummy(e);
1035        return false;
1036    }
1037    if (std::memcmp(got.data(), host_blob, (size_t) nb) != 0) {
1038        size_t first = 0;
1039        while (first < (size_t) nb && got[first] == host_blob[first]) ++first;
1040        char buf[384];
1041        std::snprintf(buf, sizeof buf,
1042                      "ExpertCache::verify_slot: slot %d differs from the arena at byte %llu (of %lld): device %02x%02x%02x%02x, arena %02x%02x%02x%02x",
1043                      (int) slot, (unsigned long long) first, (long long) blob_, first < (size_t) nb ? got[first] : 0,
1044                      first + 1 < (size_t) nb ? got[first + 1] : 0, first + 2 < (size_t) nb ? got[first + 2] : 0,
1045                      first + 3 < (size_t) nb ? got[first + 3] : 0, first < (size_t) nb ? host_blob[first] : 0,
1046                      first + 1 < (size_t) nb ? host_blob[first + 1] : 0, first + 2 < (size_t) nb ? host_blob[first + 2] : 0,
1047                      first + 3 < (size_t) nb ? host_blob[first + 3] : 0);
1048        err = buf;
1049        return false;
1050    }
1051    return true;
1052}
1053catch (sycl::exception const &exc) {
1054  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
1055            << ", line:" << __LINE__ << std::endl;
1056  std::exit(1);
1057}
1058
1059}  // namespace strata::core