File tree 1 file changed +24
-1
lines changed
1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -1546,7 +1546,7 @@ struct llama_mmap {
1546
1546
}
1547
1547
}
1548
1548
1549
- void unmap_fragment(size_t first, size_t last) {
1549
+ virtual void unmap_fragment(size_t first, size_t last) {
1550
1550
// not supported
1551
1551
GGML_UNUSED(first);
1552
1552
GGML_UNUSED(last);
@@ -1652,6 +1652,29 @@ struct llama_anonymous_mmap : llama_mmap {
1652
1652
throw std::runtime_error("unexpectedly reached end of file");
1653
1653
}
1654
1654
}
1655
+
1656
+ #if _WIN32_WINNT >= 0x603
1657
+ void unmap_fragment(size_t first, size_t last) override {
1658
+ DWORD (WINAPI *pOfferVirtualMemory) (PVOID, SIZE_T, DWORD);
1659
+ HMODULE hKernel32 = GetModuleHandleW(L"kernel32.dll");
1660
+
1661
+ pOfferVirtualMemory = reinterpret_cast<decltype(pOfferVirtualMemory)> (GetProcAddress(hKernel32, "OfferVirtualMemory"));
1662
+
1663
+ if (pOfferVirtualMemory) {
1664
+ SYSTEM_INFO siSysInfo;
1665
+ GetSystemInfo(&siSysInfo);
1666
+ DWORD dwPageSize = siSysInfo.dwPageSize;
1667
+
1668
+ align_to_next_page(&first, dwPageSize);
1669
+ align_to_previous_page(&last, dwPageSize);
1670
+
1671
+ if (pOfferVirtualMemory((char *) addr + first, last - first, 0x00000004 /* VMOfferPriorityNormal */)) {
1672
+ LLAMA_LOG_WARN("warning: OfferVirtualMemory failed: %s\n", llama_format_win_err(GetLastError()).c_str());
1673
+ }
1674
+ }
1675
+ }
1676
+ #endif
1677
+
1655
1678
#else
1656
1679
llama_anonymous_mmap(struct llama_file * file) {
1657
1680
GGML_UNUSED(file);
You can’t perform that action at this time.
0 commit comments