This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/core/format/table_copy.cpp
T
Deadcode e466fa07e2 radiance 1.0.10
- Four-rank Qwen3.8-Flash-Next (PRs 14 and 16 by keptn42): the all-reduce runs fused with the
  hyper-connection's write, and with the MoE gather in front of it, on decode and verify steps on
  the exact wire. The routed experts are split in four classes, so every rank computes the same
  share; moe_gemm_q_mod4 is the new grouped GEMM. The oracle now checks moe_gemm_q on w4nl and
  w5nl containers.
- --embedding-placement and --ngram-placement, each auto | vram | ram | disk. The token embedding
  can live in the pinned host pool, read in place over the link (from PR 17 by mechkbfan). An n-gram
  table can be copied into locked RAM at load instead of read from the container (from PR 15 by
  keptn42). auto takes the fastest tier with room once every other weight is placed, and startup
  prints what it chose and why. A tier that cannot be honoured stops the start with the reason; the
  embedding on disk and the n-gram table in VRAM are refused, since nothing can serve them.
- The expert_tiered placement no longer spends the pinned host pool twice when it falls back to
  layer offload, and a lossy-wire request for a four-rank fused write is a selection miss rather
  than a startup abort.
2026-10-05 14:01:30 +02:00

88 lines
3.1 KiB
C++

/* table_copy.cpp -- see table_copy.h. */
#include "table_copy.h"
#include "../rad_internal.h"
#include <sys/mman.h>
#include <algorithm>
#include <atomic>
#include <cerrno>
#include <cstring>
#include <thread>
#include <vector>
namespace rad {
int table_copy_make(const RadFile& file, const uint8_t* src, int64_t n, int64_t foff,
TableCopy* out, std::string* why) {
if (!out || !why || !src || n <= 0) return RAD_E_INVAL;
*out = TableCopy{};
const size_t huge = (size_t)2 << 20;
const size_t sz = ((size_t)n + huge - 1) & ~(huge - 1);
void* m = ::mmap(nullptr, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
-1, 0);
if (m == MAP_FAILED) {
*why = fmt("mmap of %s: %s", humanb((int64_t)sz).c_str(), std::strerror(errno));
return RAD_E_NOMEM;
}
(void)::madvise(m, sz, MADV_HUGEPAGE);
if (::mlock2(m, sz, MLOCK_ONFAULT) != 0) {
*why = fmt("mlock2 of %s: %s", humanb((int64_t)sz).c_str(), std::strerror(errno));
::munmap(m, sz);
return RAD_E_NOMEM;
}
uint8_t* buf = static_cast<uint8_t*>(m);
/* A reader per hardware thread up to sixteen, each reading its own contiguous span in pieces of
* 64 MiB: a drive serves sixteen queued reads at full rate, and the span keeps each reader's
* reads sequential on the file. */
const int nt = (int)std::max(1u, std::min(16u, std::thread::hardware_concurrency()));
const int64_t piece = (int64_t)64 << 20;
const int64_t span = ((n + nt - 1) / nt + (int64_t)huge - 1) & ~((int64_t)huge - 1);
std::atomic<int> err{RAD_OK};
std::vector<std::thread> rd;
for (int i = 0; i < nt; ++i) {
const int64_t lo = (int64_t)i * span, hi = std::min(n, lo + span);
if (lo >= hi) break;
rd.emplace_back([&, lo, hi] {
for (int64_t o = lo; o < hi && err.load() == RAD_OK; o += piece) {
const int64_t b = std::min(piece, hi - o);
const int rc = file.read_at(buf + o, b, foff + o);
if (rc < 0) { err.store(rc); return; }
file.drop_range(foff + o, b);
}
});
}
for (std::thread& t : rd) t.join();
bool same = err.load() == RAD_OK;
if (same) {
const int64_t probe = std::min<int64_t>(n, 4096);
same = std::memcmp(buf, src, (size_t)probe) == 0 &&
std::memcmp(buf + n - probe, src + n - probe, (size_t)probe) == 0;
for (int64_t o = 0; same && o + 4096 <= n; o += std::max<int64_t>(n / 64, 4096))
same = std::memcmp(buf + o, src + o, 4096) == 0;
if (!same) *why = "the copy does not match the container's mapping";
} else {
*why = fmt("reading the container failed (%s)", rad_strerror(err.load()));
}
if (!same) {
::munlock(m, sz);
::munmap(m, sz);
return RAD_E_IO;
}
out->base = m;
out->bytes = sz;
return RAD_OK;
}
void table_copy_free(TableCopy* c) {
if (!c || !c->base) return;
::munlock(c->base, c->bytes);
::munmap(c->base, c->bytes);
*c = TableCopy{};
}
} /* namespace rad */