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

Method copy_from_files

engine/src/core/expert_source.cpp:1904–1958  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1902}
1903
1904bool FileExpertSource::copy_from_files(int64_t layer, int64_t expert, uint8_t* dst) const {
1905 if (dst == nullptr || layer < 0 || expert < 0 || layer >= n_layers_ || expert >= n_expert_) return false;
1906 if (!direct_.empty()) { // #286: from the drive; a failed read falls back to the mapping below
1907 const Fill f{0, layer, expert, dst};
1908 if (read_direct(&f, 1)) {
1909 verify_blob(layer, expert, dst); // NAN879-LAB: no-op unless STRATA_BLOB_VERIFY=1
1910 return true;
1911 }
1912 direct_fallbacks_.fetch_add(1, std::memory_order_relaxed);
1913 }
1914#if defined(__linux__)
1915 if (io_pf_ || io_stats_) { // count what the page cache holds; with io prefetch, read what it does not with pread
1916 Span sp[3];
1917 const int ns = spans(layer, expert, sp);
1918 for (int i = 0; i < ns; ++i) {
1919 const uint64_t res = resident_in(sp[i].p, sp[i].n);
1920 io_cached_.fetch_add(res, std::memory_order_relaxed);
1921 io_uncached_.fetch_add(sp[i].n - res, std::memory_order_relaxed);
1922 const bool dec = in_decode();
1923 if (gate_on_ && dec) {
1924 gate_c_.fetch_add(res, std::memory_order_relaxed);
1925 gate_u_.fetch_add(sp[i].n - res, std::memory_order_relaxed);
1926 }
1927 if (io_pf_ && res < sp[i].n && sp[i].fd >= 0 && !(dec && !gate_open())) {
1928 const auto t0 = std::chrono::steady_clock::now();
1929 const bool ok = pread_full(sp[i].fd, dst + sp[i].at, sp[i].n, sp[i].off);
1930 io_pread_us_.fetch_add((uint64_t) std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() - t0).count(),
1931 std::memory_order_relaxed);
1932 io_pread_n_.fetch_add(1, std::memory_order_relaxed);
1933 if (ok) {
1934 io_pread_bytes_.fetch_add(sp[i].n, std::memory_order_relaxed);
1935 continue;
1936 }
1937 }
1938 std::memcpy(dst + sp[i].at, sp[i].p, (size_t) sp[i].n);
1939 }
1940 if (ns > 0) return true;
1941 }
1942#endif
1943 if (!role_ptr_.empty()) {
1944 if (unmapped_) return false; // drop_mapping closed the GGUF views: only the unbuffered reads remain
1945 uint64_t at = 0;
1946 for (int r = 0; r < 3; ++r) {
1947 const size_t i = (size_t) (3 * layer + r);
1948 const uint64_t per = role_bytes_[i];
1949 std::memcpy(dst + at, role_ptr_[i] + (size_t) ((uint64_t) expert * per), (size_t) per);
1950 at += per;
1951 }
1952 return true;
1953 }
1954 const uint8_t* b = mapped_blob(layer, expert);
1955 if (b == nullptr) return false;
1956 std::memcpy(dst, b, (size_t) layer_blob_bytes_[(size_t) layer]);
1957 return true;
1958}
1959
1960// NAN879-LAB diagnostic (see expert_source.hpp). Plain buffered reads of the very byte ranges
1961// read_direct just delivered - an independent channel through the file cache. The offsets are

Callers

nothing calls this directly

Calls 7

resident_inFunction · 0.85
pread_fullFunction · 0.85
memcpyFunction · 0.85
fetch_addMethod · 0.80
nowFunction · 0.50
emptyMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected