mirror of https://github.com/google/gemma.cpp.git
parent
c805fbe780
commit
b6aaf6bbb8
|
|
@ -13,6 +13,19 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
// Request POSIX 2008, including `pread()` and `posix_fadvise()`.
|
||||||
|
#if !defined(_XOPEN_SOURCE) || _XOPEN_SOURCE < 700
|
||||||
|
#undef _XOPEN_SOURCE
|
||||||
|
#define _XOPEN_SOURCE 700
|
||||||
|
#endif
|
||||||
|
#if !defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 200809
|
||||||
|
#define _POSIX_C_SOURCE 200809
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Make `off_t` 64-bit even on 32-bit systems. Works for Android >= r15c.
|
||||||
|
#undef _FILE_OFFSET_BITS
|
||||||
|
#define _FILE_OFFSET_BITS 64
|
||||||
|
|
||||||
// copybara:import_next_line:gemma_cpp
|
// copybara:import_next_line:gemma_cpp
|
||||||
#include "compression/blob_store.h"
|
#include "compression/blob_store.h"
|
||||||
|
|
||||||
|
|
@ -81,7 +94,7 @@ static int64_t pwrite(int fd, const void* buf, uint64_t size, uint64_t offset) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
namespace gcpp {
|
namespace gcpp {
|
||||||
|
|
||||||
|
|
@ -133,6 +146,7 @@ struct IO {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
static_assert(sizeof(off_t) == 8, "64-bit off_t required");
|
||||||
const off_t size = lseek(fd, 0, SEEK_END);
|
const off_t size = lseek(fd, 0, SEEK_END);
|
||||||
HWY_ASSERT(close(fd) != -1);
|
HWY_ASSERT(close(fd) != -1);
|
||||||
if (size == static_cast<off_t>(-1)) {
|
if (size == static_cast<off_t>(-1)) {
|
||||||
|
|
@ -318,7 +332,8 @@ class BlobStore {
|
||||||
BlobError BlobReader::Open(const char* filename) {
|
BlobError BlobReader::Open(const char* filename) {
|
||||||
#if HWY_OS_WIN
|
#if HWY_OS_WIN
|
||||||
DWORD flags = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN;
|
DWORD flags = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN;
|
||||||
HANDLE file = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, flags, nullptr);
|
HANDLE file = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, nullptr,
|
||||||
|
OPEN_EXISTING, flags, nullptr);
|
||||||
if (file == INVALID_HANDLE_VALUE) return __LINE__;
|
if (file == INVALID_HANDLE_VALUE) return __LINE__;
|
||||||
fd_ = _open_osfhandle(reinterpret_cast<intptr_t>(file), _O_RDONLY);
|
fd_ = _open_osfhandle(reinterpret_cast<intptr_t>(file), _O_RDONLY);
|
||||||
#else
|
#else
|
||||||
|
|
@ -326,7 +341,7 @@ BlobError BlobReader::Open(const char* filename) {
|
||||||
#endif
|
#endif
|
||||||
if (fd_ < 0) return __LINE__;
|
if (fd_ < 0) return __LINE__;
|
||||||
|
|
||||||
#if _POSIX_C_SOURCE >= 200112L
|
#if HWY_OS_LINUX
|
||||||
// Doubles the readahead window, which seems slightly faster when cached.
|
// Doubles the readahead window, which seems slightly faster when cached.
|
||||||
(void)posix_fadvise(fd_, 0, 0, POSIX_FADV_SEQUENTIAL);
|
(void)posix_fadvise(fd_, 0, 0, POSIX_FADV_SEQUENTIAL);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -403,7 +418,8 @@ BlobError BlobWriter::WriteAll(hwy::ThreadPool& pool,
|
||||||
// Create/replace existing file.
|
// Create/replace existing file.
|
||||||
#if HWY_OS_WIN
|
#if HWY_OS_WIN
|
||||||
DWORD flags = FILE_ATTRIBUTE_NORMAL;
|
DWORD flags = FILE_ATTRIBUTE_NORMAL;
|
||||||
HANDLE file = CreateFileA(filename, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, flags, nullptr);
|
HANDLE file = CreateFileA(filename, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS,
|
||||||
|
flags, nullptr);
|
||||||
if (file == INVALID_HANDLE_VALUE) return __LINE__;
|
if (file == INVALID_HANDLE_VALUE) return __LINE__;
|
||||||
const int fd = _open_osfhandle(reinterpret_cast<intptr_t>(file), _O_WRONLY);
|
const int fd = _open_osfhandle(reinterpret_cast<intptr_t>(file), _O_WRONLY);
|
||||||
#else
|
#else
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue