Run frontier MoE models on hardware you already own β pure C, zero deps, experts streamed from disk. Tiny engine, immense model. π¦
C
win32: stop erasing the real ReadFile error β pread failures name their WinErr (#307)
JustVugg211d4488c36d
diff --git a/c/compat.h b/c/compat.hindex 82de8b6c..a21bbd8d 100644--- a/c/compat.h+++ b/c/compat.h@@ -143,6 +143,12 @@ static inline int compat_fadvise(int fd, off_t off, off_t len, int advice){* Thread-safe (no shared seek position). Gestisce offset >4 GB e chunking* per letture >2 GB (anche se i tensori individuali sono nell'ordine dei* MB-centinaia di MB, il wrapper e' robusto per ogni taglia). */+/* Ultimo GetLastError() di una ReadFile fallita, per thread: il chiamante+ * (pread_full in glm.c) lo stampa accanto a strerror. Senza questo, OGNI+ * fallimento Windows collassa in "EIO -> Input/output error" e la diagnosi+ * dal campo diventa un tirare a indovinare (#307: tre giri di ipotesi tra+ * tre persone perche' il codice vero non compariva da nessuna parte). */+static __thread DWORD compat_pread_lasterr __attribute__((unused));static inline ssize_t compat_pread(int fd, void *buf, size_t n, off_t off){intptr_t osfh = _get_osfhandle(fd);if(osfh == -1 || osfh == -2){ errno = EBADF; return -1; }@@ -158,6 +164,7 @@ static inline ssize_t compat_pread(int fd, void *buf, size_t n, off_t off){if(!ReadFile(h, (char*)buf + total, chunk32, &rd, &ov)){DWORD err = GetLastError();if(err == ERROR_HANDLE_EOF) break; /* past EOF β return bytes read (0 if none, matching POSIX pread) */+ compat_pread_lasterr = err; /* preserva il codice VERO per il report (#307) */if(err == ERROR_INVALID_HANDLE || err == ERROR_INVALID_FUNCTION) errno = EBADF;else errno = EIO;return -1;diff --git a/c/glm.c b/c/glm.cindex 30d970ab..003a42d8 100644--- a/c/glm.c+++ b/c/glm.c@@ -1732,8 +1732,14 @@ static int pread_full(int fd, void *buf, int64_t n, int64_t off, const char *tagwhile(got<n){ssize_t r=pread(fd, p+got, (size_t)(n-got), off+got);if(r<0){ if(errno==EINTR) continue;+#ifdef _WIN32+ fprintf(stderr,"%s: %s (off %lld, %lld/%lld bytes, WinErr=%lu)\n",tag,strerror(errno),+ (long long)off,(long long)got,(long long)n,(unsigned long)compat_pread_lasterr);+#elsefprintf(stderr,"%s: %s (off %lld, %lld/%lld bytes)\n",tag,strerror(errno),- (long long)off,(long long)got,(long long)n); return -1; }+ (long long)off,(long long)got,(long long)n);+#endif+ return -1; }if(r==0){ fprintf(stderr,"%s: short read at EOF (off %lld, %lld/%lld bytes) β truncated shard?\n",tag,(long long)off,(long long)got,(long long)n); return -1; }got+=r;