Update llama-mmap to use ftello/fseeko (#22497)
* Update llama-mmap to work with 32-bit wasm and >2GB models * Update to gguf.cpp style
This commit is contained in:
+10
-2
@@ -40,6 +40,14 @@
|
|||||||
#include <TargetConditionals.h>
|
#include <TargetConditionals.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
# define llama_mmap_ftell _ftelli64
|
||||||
|
# define llama_mmap_fseek _fseeki64
|
||||||
|
#else
|
||||||
|
# define llama_mmap_ftell ftello
|
||||||
|
# define llama_mmap_fseek fseeko
|
||||||
|
#endif
|
||||||
|
|
||||||
// TODO: consider moving to llama-impl.h if needed in more places
|
// TODO: consider moving to llama-impl.h if needed in more places
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
static std::string llama_format_win_err(DWORD err) {
|
static std::string llama_format_win_err(DWORD err) {
|
||||||
@@ -226,7 +234,7 @@ struct llama_file::impl {
|
|||||||
|
|
||||||
size_t tell() const {
|
size_t tell() const {
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
long ret = std::ftell(fp);
|
off_t ret = llama_mmap_ftell(fp);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
throw std::runtime_error(format("ftell error: %s", strerror(errno)));
|
throw std::runtime_error(format("ftell error: %s", strerror(errno)));
|
||||||
}
|
}
|
||||||
@@ -244,7 +252,7 @@ struct llama_file::impl {
|
|||||||
void seek(size_t offset, int whence) const {
|
void seek(size_t offset, int whence) const {
|
||||||
off_t ret = 0;
|
off_t ret = 0;
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
ret = std::fseek(fp, (long) offset, whence);
|
ret = llama_mmap_fseek(fp, offset, whence);
|
||||||
} else {
|
} else {
|
||||||
ret = lseek(fd, offset, whence);
|
ret = lseek(fd, offset, whence);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user