llama : Extend fallback, fix fileno for dio file, exclude case that mmap uses dio file (#18887)
This commit is contained in:
+5
-1
@@ -265,7 +265,8 @@ struct llama_file::impl {
|
|||||||
continue; // Interrupted by signal, retry
|
continue; // Interrupted by signal, retry
|
||||||
}
|
}
|
||||||
// Fallback to std::fread in case the DMA controller cannot access the buffer
|
// Fallback to std::fread in case the DMA controller cannot access the buffer
|
||||||
if (errno == EFAULT) {
|
if (errno == EFAULT || errno == EINVAL) {
|
||||||
|
LLAMA_LOG_WARN("%s: Falling back to buffered IO due to %s\n", __func__, strerror(errno));
|
||||||
auto curr_off = tell();
|
auto curr_off = tell();
|
||||||
close(fd);
|
close(fd);
|
||||||
fd = -1;
|
fd = -1;
|
||||||
@@ -384,6 +385,9 @@ int llama_file::file_id() const {
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return _fileno(pimpl->fp);
|
return _fileno(pimpl->fp);
|
||||||
#else
|
#else
|
||||||
|
if (pimpl->fd != -1) {
|
||||||
|
return pimpl->fd;
|
||||||
|
}
|
||||||
#if defined(fileno)
|
#if defined(fileno)
|
||||||
return fileno(pimpl->fp);
|
return fileno(pimpl->fp);
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -539,12 +539,18 @@ llama_model_loader::llama_model_loader(
|
|||||||
files.emplace_back(new llama_file(fname.c_str(), "rb", use_direct_io));
|
files.emplace_back(new llama_file(fname.c_str(), "rb", use_direct_io));
|
||||||
contexts.emplace_back(ctx);
|
contexts.emplace_back(ctx);
|
||||||
|
|
||||||
use_direct_io = use_direct_io && files.back()->has_direct_io();
|
if (use_mmap && use_direct_io) {
|
||||||
|
if (files.back()->has_direct_io()) {
|
||||||
// Disable mmap in case Direct I/O is enabled and available
|
// Disable mmap, as DirectIO is available
|
||||||
if (use_direct_io && use_mmap) {
|
|
||||||
use_mmap = false;
|
use_mmap = false;
|
||||||
LLAMA_LOG_WARN("%s: direct I/O is enabled, disabling mmap\n", __func__);
|
LLAMA_LOG_WARN("%s: direct I/O is enabled, disabling mmap\n", __func__);
|
||||||
|
} else {
|
||||||
|
// Disable DirectIO and reopen file using std::fopen for mmap
|
||||||
|
use_direct_io = false;
|
||||||
|
files.pop_back();
|
||||||
|
files.emplace_back(new llama_file(fname.c_str(), "rb", false));
|
||||||
|
LLAMA_LOG_WARN("%s: direct I/O is not available, using mmap\n", __func__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save tensors data offset of the main file.
|
// Save tensors data offset of the main file.
|
||||||
|
|||||||
Reference in New Issue
Block a user