Skip to content

Commit 11c4e7c

Browse files
committed
automatic memory detection for vulkan
1 parent a3f7de7 commit 11c4e7c

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

koboldcpp.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,8 @@ def autoset_gpu_layers(ctxsize,sdquanted,bbs): #shitty algo to determine how man
972972
def fetch_gpu_properties(testCL,testCU,testVK):
973973
import subprocess
974974

975+
gpumem_ignore_limit = 1024*1024*600
976+
975977
if testCU:
976978
FetchedCUdevices = []
977979
FetchedCUdeviceMem = []
@@ -1038,6 +1040,7 @@ def fetch_gpu_properties(testCL,testCU,testVK):
10381040

10391041
if testVK:
10401042
try: # Get Vulkan names
1043+
foundVkGPU = False
10411044
output = subprocess.run(['vulkaninfo','--summary'], capture_output=True, text=True, check=True, encoding='utf-8', timeout=10).stdout
10421045
devicelist = [line.split("=")[1].strip() for line in output.splitlines() if "deviceName" in line]
10431046
devicetypes = [line.split("=")[1].strip() for line in output.splitlines() if "deviceType" in line]
@@ -1050,8 +1053,31 @@ def fetch_gpu_properties(testCL,testCU,testVK):
10501053
idx = 0
10511054
for dvtype in devicetypes:
10521055
if idx<len(VKIsDGPU):
1053-
VKIsDGPU[idx] = (1 if dvtype=="PHYSICAL_DEVICE_TYPE_DISCRETE_GPU" else 0)
1056+
typeflag = (1 if dvtype=="PHYSICAL_DEVICE_TYPE_DISCRETE_GPU" else 0)
1057+
VKIsDGPU[idx] = typeflag
1058+
if typeflag:
1059+
foundVkGPU = True
10541060
idx += 1
1061+
1062+
if foundVkGPU:
1063+
try: # Try get vulkan memory (experimental)
1064+
output = subprocess.run(['vulkaninfo'], capture_output=True, text=True, check=True, encoding='utf-8', timeout=10).stdout
1065+
devicechunks = output.split("VkPhysicalDeviceMemoryProperties")[1:]
1066+
gpuidx = 0
1067+
lowestvkmem = 0
1068+
for chunk in devicechunks:
1069+
heaps = chunk.split("memoryTypes:")[0].split("memoryHeaps[")[1:]
1070+
snippet = heaps[0]
1071+
if "MEMORY_HEAP_DEVICE_LOCAL_BIT" in snippet and "size" in snippet:
1072+
match = re.search(r"size\s*=\s*(\d+)", snippet)
1073+
if match:
1074+
dmem = int(match.group(1))
1075+
if dmem > gpumem_ignore_limit:
1076+
lowestvkmem = dmem if lowestvkmem==0 else (dmem if dmem<lowestvkmem else lowestvkmem)
1077+
gpuidx += 1
1078+
except Exception: # failed to get vulkan vram
1079+
pass
1080+
MaxMemory[0] = max(lowestvkmem,MaxMemory[0])
10551081
except Exception:
10561082
pass
10571083

@@ -1077,7 +1103,8 @@ def fetch_gpu_properties(testCL,testCU,testVK):
10771103
idx = plat+dev*2
10781104
if idx<len(CLDevices):
10791105
CLDevicesNames[idx] = dname
1080-
lowestclmem = dmem if lowestclmem==0 else (dmem if dmem<lowestclmem else lowestclmem)
1106+
if dmem > gpumem_ignore_limit:
1107+
lowestclmem = dmem if lowestclmem==0 else (dmem if dmem<lowestclmem else lowestclmem)
10811108
dev += 1
10821109
plat += 1
10831110
MaxMemory[0] = max(lowestclmem,MaxMemory[0])

0 commit comments

Comments
 (0)