mirror of
https://github.com/vladmandic/automatic
synced 2026-09-17 16:24:33 +02:00
d711880aa9
1. Performance Counter.
Get vram size allocated to & used by python.exe from pdh.dll.
Generation can be slower than atiadlxx.
Use memory less greedy then atiadlxx.
Windows only.
2. atiadlxx.
Get max vram size and available vram size from AMD GPU driver (atiadlxx.dll).
Use memory more greedy than Performance Counter.
Windows & WSL are supported.
3. None.
Assume available vram size is 8GB.
Use memory regardless of current vram usage.
47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
import ctypes as C
|
|
from .atiadlxx_apis import *
|
|
from .atiadlxx_structures import *
|
|
from .atiadlxx_defines import *
|
|
|
|
class ATIADLxx(object):
|
|
iHyperMemorySize = 0
|
|
|
|
def __init__(self):
|
|
self.context = ADL_CONTEXT_HANDLE()
|
|
ADL2_Main_Control_Create(ADL_Main_Memory_Alloc, 1, C.byref(self.context))
|
|
num_adapters = C.c_int(-1)
|
|
ADL2_Adapter_NumberOfAdapters_Get(self.context, C.byref(num_adapters))
|
|
AdapterInfoArray = (AdapterInfo * num_adapters.value)()
|
|
ADL2_Adapter_AdapterInfo_Get(self.context, C.cast(AdapterInfoArray, LPAdapterInfo), C.sizeof(AdapterInfoArray))
|
|
self.devices = []
|
|
busNumbers = []
|
|
for adapter in AdapterInfoArray:
|
|
if adapter.iBusNumber not in busNumbers: # filter duplicate device
|
|
self.devices.append(adapter)
|
|
busNumbers.append(adapter.iBusNumber)
|
|
self.iHyperMemorySize = self.get_memory_info2(0).iHyperMemorySize
|
|
|
|
def get_memory_info2(self, adapterIndex: int) -> ADLMemoryInfo2:
|
|
info = ADLMemoryInfo2()
|
|
|
|
if ADL2_Adapter_MemoryInfo2_Get(self.context, adapterIndex, C.byref(info)) != ADL_OK:
|
|
raise RuntimeError("ADL2: Failed to get MemoryInfo2")
|
|
|
|
return info
|
|
|
|
def get_dedicated_vram_usage(self, index: int) -> int:
|
|
usage = C.c_int(-1)
|
|
|
|
if ADL2_Adapter_DedicatedVRAMUsage_Get(self.context, self.devices[index].iAdapterIndex, C.byref(usage)) != ADL_OK:
|
|
raise RuntimeError("ADL2: Failed to get DedicatedVRAMUsage")
|
|
|
|
return usage.value
|
|
|
|
def get_vram_usage(self, index: int) -> int:
|
|
usage = C.c_int(-1)
|
|
|
|
if ADL2_Adapter_VRAMUsage_Get(self.context, self.devices[index].iAdapterIndex, C.byref(usage)) != ADL_OK:
|
|
raise RuntimeError("ADL2: Failed to get VRAMUsage")
|
|
|
|
return usage.value
|