MCPcopy Create free account
hub / github.com/Niko1221/Strata / open

Method open

engine/src/core/expert_source.cpp:1517–1688  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1515}
1516
1517bool FileExpertSource::open(const std::string& pack_dir, int64_t n_layers, int64_t n_expert, std::string& err) {
1518 close();
1519 if (n_layers <= 0 || n_expert <= 0) { err = "FileExpertSource: the geometry is empty"; return false; }
1520 const auto& layout = strata::kernels::cpu::expert_layout();
1521 if (layout.n_layers != n_layers || layout.n_expert != n_expert) {
1522 err = "FileExpertSource: the requested geometry does not match the loaded expert layout";
1523 return false;
1524 }
1525 if ((uint64_t) n_layers > (uint64_t) std::numeric_limits<int64_t>::max() / (uint64_t) n_expert) {
1526 err = "FileExpertSource: the expert count overflows";
1527 return false;
1528 }
1529 const uint64_t blob_count = (uint64_t) n_layers * (uint64_t) n_expert;
1530 if (blob_count > (uint64_t) std::numeric_limits<int64_t>::max() ||
1531 (uint64_t) n_layers > (uint64_t) std::numeric_limits<size_t>::max()) {
1532 err = "FileExpertSource: the expert count overflows";
1533 return false;
1534 }
1535
1536 std::vector<uint64_t> layer_offsets((size_t) n_layers), layer_blob_bytes((size_t) n_layers);
1537 const uint64_t want = layout.total;
1538 if (want == 0 || want > (uint64_t) std::numeric_limits<size_t>::max()) {
1539 err = "FileExpertSource: the loaded expert layout has an invalid size";
1540 return false;
1541 }
1542 if (!layout.native) {
1543 if (blob_count > std::numeric_limits<uint64_t>::max() / (uint64_t) strata::kernels::cpu::BLOB) {
1544 err = "FileExpertSource: the canonical expert size overflows";
1545 return false;
1546 }
1547 const uint64_t canonical_size = blob_count * (uint64_t) strata::kernels::cpu::BLOB;
1548 if (want != canonical_size) {
1549 err = "FileExpertSource: the canonical expert layout has an inconsistent size";
1550 return false;
1551 }
1552 const uint64_t bytes = (uint64_t) strata::kernels::cpu::BLOB;
1553 const uint64_t layer_bytes = (uint64_t) n_expert * bytes;
1554 for (int64_t layer = 0; layer < n_layers; ++layer) {
1555 layer_offsets[(size_t) layer] = (uint64_t) layer * layer_bytes;
1556 layer_blob_bytes[(size_t) layer] = bytes;
1557 }
1558 } else {
1559 if (layout.offset.size() != (size_t) n_layers || layout.bytes.size() != (size_t) n_layers ||
1560 layout.fmt.size() != (size_t) n_layers) {
1561 err = "FileExpertSource: the native expert layout is incomplete";
1562 return false;
1563 }
1564 uint64_t at = 0;
1565 for (int64_t layer = 0; layer < n_layers; ++layer) {
1566 const size_t i = (size_t) layer;
1567 const uint64_t bytes = (uint64_t) layout.fmt[i].bytes;
1568 if (layout.offset[i] != at || bytes == 0 || layout.bytes[i] != bytes ||
1569 bytes > std::numeric_limits<uint64_t>::max() / (uint64_t) n_expert) {
1570 err = "FileExpertSource: the native expert layout is invalid at layer " + std::to_string(layer);
1571 return false;
1572 }
1573 const uint64_t layer_bytes = bytes * (uint64_t) n_expert;
1574 if (at > want || layer_bytes > want - at) {

Callers

nothing calls this directly

Calls 15

expert_layoutFunction · 0.85
moveFunction · 0.85
open_ggufFunction · 0.85
advise_mapped_expertsFunction · 0.85
arena_need_with_keepFunction · 0.85
arena_hard_limit_needFunction · 0.85
arena_ram_verdictFunction · 0.85
wait_for_ramFunction · 0.85
sortFunction · 0.85
stable_sortFunction · 0.85

Tested by

no test coverage detected