@@ -1195,11 +1195,7 @@ def autoset_gpu_layers(ctxsize, sdquanted, bbs, qkv_level): #shitty algo to dete
11951195 except Exception :
11961196 return 0
11971197
1198- def fetch_gpu_properties (testCL ,testCU ,testVK ):
1199- gpumem_ignore_limit_min = 1024 * 1024 * 600 #600 mb min
1200- gpumem_ignore_limit_max = 1024 * 1024 * 1024 * 300 #300 gb max
1201-
1202- if testCU :
1198+ def detect_memory_cu (gpumem_ignore_limit_min , gpumem_ignore_limit_max ):
12031199 FetchedCUdevices = []
12041200 FetchedCUdeviceMem = []
12051201 FetchedCUfreeMem = []
@@ -1276,10 +1272,11 @@ def fetch_gpu_properties(testCL,testCU,testVK):
12761272 lowestcumem = 0
12771273 lowestfreecumem = 0
12781274
1279- MaxMemory [0 ] = max (lowestcumem ,MaxMemory [0 ])
1280- MaxFreeMemory [0 ] = max (lowestfreecumem ,MaxFreeMemory [0 ])
1275+ return lowestcumem , lowestfreecumem
1276+
1277+
1278+ def detect_memory_vk (gpumem_ignore_limit_min , gpumem_ignore_limit_max ):
12811279
1282- if testVK :
12831280 try : # Get Vulkan names
12841281 foundVkGPU = False
12851282 lowestvkmem = 0
@@ -1318,11 +1315,15 @@ def fetch_gpu_properties(testCL,testCU,testVK):
13181315 gpuidx += 1
13191316 except Exception : # failed to get vulkan vram
13201317 pass
1321- MaxMemory [ 0 ] = max ( lowestvkmem , MaxMemory [ 0 ])
1318+ return lowestvkmem
13221319 except Exception :
13231320 pass
13241321
1325- if testCL :
1322+ return 0
1323+
1324+
1325+ def detect_memory_cl (gpumem_ignore_limit_min , gpumem_ignore_limit_max ):
1326+
13261327 try : # Get OpenCL GPU names on windows using a special binary. overwrite at known index if found.
13271328 basepath = os .path .abspath (os .path .dirname (__file__ ))
13281329 output = ""
@@ -1348,10 +1349,40 @@ def fetch_gpu_properties(testCL,testCU,testVK):
13481349 lowestclmem = dmem if lowestclmem == 0 else (dmem if dmem < lowestclmem else lowestclmem )
13491350 dev += 1
13501351 plat += 1
1351- MaxMemory [ 0 ] = max ( lowestclmem , MaxMemory [ 0 ])
1352+ return lowestclmem
13521353 except Exception :
13531354 pass
13541355
1356+ return 0
1357+
1358+
1359+ def fetch_gpu_properties (testCL ,testCU ,testVK ,testmemory = False ):
1360+ gpumem_ignore_limit_min = 1024 * 1024 * 600 #600 mb min
1361+ gpumem_ignore_limit_max = 1024 * 1024 * 1024 * 300 #300 gb max
1362+
1363+ if testCU :
1364+
1365+ cumem , freecumem = detect_memory_cu (gpumem_ignore_limit_min , gpumem_ignore_limit_max )
1366+ MaxMemory [0 ] = max (cumem ,MaxMemory [0 ])
1367+ MaxFreeMemory [0 ] = max (freecumem ,MaxFreeMemory [0 ])
1368+ if testmemory :
1369+ print (f'detected CUDA memory: { cumem / (1024 * 1024 )} MB, { freecumem / (1024 * 102 )} MB free' )
1370+
1371+ if testVK :
1372+
1373+ vkmem = detect_memory_vk (gpumem_ignore_limit_min , gpumem_ignore_limit_max )
1374+ MaxMemory [0 ] = max (vkmem ,MaxMemory [0 ])
1375+ if testmemory :
1376+ print (f'detected Vulkan memory: { vkmem / (1024 * 1024 )} MB' )
1377+
1378+ if testCL :
1379+
1380+ clmem = detect_memory_cl (gpumem_ignore_limit_min , gpumem_ignore_limit_max )
1381+ MaxMemory [0 ] = max (clmem ,MaxMemory [0 ])
1382+ if testmemory :
1383+ print (f'detected OpenCL memory: { clmem / (1024 * 1024 )} MB' )
1384+
1385+
13551386 # Check VRAM detection after all backends have been tested
13561387 if MaxMemory [0 ] < (1024 * 1024 * 256 ):
13571388 print ("Unable to detect VRAM, please set layers manually." )
@@ -6995,6 +7026,10 @@ def main(launch_args, default_args):
69957026 print (f"{ KcppVersion } " ) # just print version and exit
69967027 return
69977028
7029+ if args .testmemory :
7030+ fetch_gpu_properties (True , True , True , testmemory = True )
7031+ return
7032+
69987033 #prevent disallowed combos
69997034 if (args .nomodel or args .benchmark or args .launch or args .admin ) and args .cli :
70007035 exit_with_error (1 , "Error: --cli cannot be combined with --launch, --nomodel, --admin or --benchmark" )
@@ -8100,4 +8135,7 @@ def range_checker(arg: str):
81008135 compatgroup3 .add_argument ("--nommap" ,"--no-mmap" , help = argparse .SUPPRESS , action = 'store_true' )
81018136 deprecatedgroup .add_argument ("--sdnotile" , help = argparse .SUPPRESS , action = 'store_true' ) # legacy option, see sdtiledvae
81028137
8138+ debuggroup = parser .add_argument_group ('Debug Commands' )
8139+ debuggroup .add_argument ("--testmemory" , help = argparse .SUPPRESS , action = 'store_true' )
8140+
81038141 main (launch_args = parser .parse_args (),default_args = parser .parse_args ([]))
0 commit comments