mirror of
https://github.com/ollama/ollama.git
synced 2026-05-13 14:27:00 +00:00
ggml: fix mem_hip incorrectly reporting zero memory for AMD APUs (#8735)
AMD APUs (eg. MI300A) report zero VRAM due to unified CPU/GPU memory. In this case, GPU-accessible memory is exposed via GTT.
This commit is contained in:
parent
4ff8a691bc
commit
cfa6102c54
1 changed files with 26 additions and 2 deletions
28
ml/backend/ggml/ggml/src/mem_hip.cpp
vendored
28
ml/backend/ggml/ggml/src/mem_hip.cpp
vendored
|
|
@ -461,6 +461,8 @@ int ggml_hip_get_device_memory(const char *id, size_t *free, size_t *total) {
|
|||
const std::string drmTotalMemoryFile = "mem_info_vram_total";
|
||||
const std::string drmUsedMemoryFile = "mem_info_vram_used";
|
||||
const std::string drmUeventPCISlotLabel = "PCI_SLOT_NAME=";
|
||||
const std::string drmGttTotalMemoryFile = "mem_info_gtt_total";
|
||||
const std::string drmGttUsedMemoryFile = "mem_info_gtt_used";
|
||||
|
||||
glob_t glob_result;
|
||||
glob(drmDeviceGlob.c_str(), GLOB_NOSORT, NULL, &glob_result);
|
||||
|
|
@ -497,7 +499,29 @@ int ggml_hip_get_device_memory(const char *id, size_t *free, size_t *total) {
|
|||
totalFileStream >> memory;
|
||||
*total = memory;
|
||||
|
||||
std::string usedFile = dir + "/" + drmUsedMemoryFile;
|
||||
// AMD APUs report zero VRAM due to unified CPU/GPU memory
|
||||
// GPU-accessible memory is exposed via GTT
|
||||
if (memory == 0) {
|
||||
std::string gttTotalFile = dir + "/" + drmGttTotalMemoryFile;
|
||||
std::ifstream gttTotalFileStream(gttTotalFile.c_str());
|
||||
if (!gttTotalFileStream.is_open()) {
|
||||
GGML_LOG_DEBUG("%s Failed to read sysfs node %s\n", __func__, gttTotalFile.c_str());
|
||||
file.close();
|
||||
globfree(&glob_result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
gttTotalFileStream >> memory;
|
||||
*total = memory;
|
||||
}
|
||||
|
||||
std::string usedFile;
|
||||
if (*total == 0) {
|
||||
usedFile = dir + "/" + drmGttUsedMemoryFile;
|
||||
} else {
|
||||
usedFile = dir + "/" + drmUsedMemoryFile;
|
||||
}
|
||||
|
||||
std::ifstream usedFileStream(usedFile.c_str());
|
||||
if (!usedFileStream.is_open()) {
|
||||
GGML_LOG_DEBUG("%s Failed to read sysfs node %s\n", __func__, usedFile.c_str());
|
||||
|
|
@ -526,4 +550,4 @@ int ggml_hip_get_device_memory(const char *id, size_t *free, size_t *total) {
|
|||
|
||||
} // extern "C"
|
||||
|
||||
#endif // #ifdef _WIN32
|
||||
#endif // #ifdef _WIN32
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue