Skip to content

Commit 5cbfb18

Browse files
authored
Update llama-mmap to use ftello/fseeko (ggml-org#22497)
* Update llama-mmap to work with 32-bit wasm and >2GB models * Update to gguf.cpp style
1 parent beb42ff commit 5cbfb18

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/llama-mmap.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
#include <TargetConditionals.h>
4141
#endif
4242

43+
#ifdef _WIN32
44+
# define llama_mmap_ftell _ftelli64
45+
# define llama_mmap_fseek _fseeki64
46+
#else
47+
# define llama_mmap_ftell ftello
48+
# define llama_mmap_fseek fseeko
49+
#endif
50+
4351
// TODO: consider moving to llama-impl.h if needed in more places
4452
#if defined(_WIN32)
4553
static std::string llama_format_win_err(DWORD err) {
@@ -226,7 +234,7 @@ struct llama_file::impl {
226234

227235
size_t tell() const {
228236
if (fd == -1) {
229-
long ret = std::ftell(fp);
237+
off_t ret = llama_mmap_ftell(fp);
230238
if (ret == -1) {
231239
throw std::runtime_error(format("ftell error: %s", strerror(errno)));
232240
}
@@ -244,7 +252,7 @@ struct llama_file::impl {
244252
void seek(size_t offset, int whence) const {
245253
off_t ret = 0;
246254
if (fd == -1) {
247-
ret = std::fseek(fp, (long) offset, whence);
255+
ret = llama_mmap_fseek(fp, offset, whence);
248256
} else {
249257
ret = lseek(fd, offset, whence);
250258
}

0 commit comments

Comments
 (0)