2024-06-05 19:07:20 +00:00
|
|
|
package gpu
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"syscall"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MEMORYSTATUSEX struct {
|
|
|
|
length uint32
|
|
|
|
MemoryLoad uint32
|
|
|
|
TotalPhys uint64
|
|
|
|
AvailPhys uint64
|
|
|
|
TotalPageFile uint64
|
|
|
|
AvailPageFile uint64
|
|
|
|
TotalVirtual uint64
|
|
|
|
AvailVirtual uint64
|
|
|
|
AvailExtendedVirtual uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
k32 = syscall.NewLazyDLL("kernel32.dll")
|
|
|
|
globalMemoryStatusExProc = k32.NewProc("GlobalMemoryStatusEx")
|
|
|
|
sizeofMemoryStatusEx = uint32(unsafe.Sizeof(MEMORYSTATUSEX{}))
|
|
|
|
)
|
|
|
|
|
|
|
|
var CudartGlobs = []string{
|
|
|
|
"c:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v*\\bin\\cudart64_*.dll",
|
|
|
|
}
|
|
|
|
|
|
|
|
var NvmlGlobs = []string{
|
|
|
|
"c:\\Windows\\System32\\nvml.dll",
|
|
|
|
}
|
|
|
|
|
|
|
|
var NvcudaGlobs = []string{
|
|
|
|
"c:\\windows\\system*\\nvcuda.dll",
|
|
|
|
}
|
|
|
|
|
|
|
|
var OneapiGlobs = []string{
|
|
|
|
"c:\\Windows\\System32\\DriverStore\\FileRepository\\*\\ze_intel_gpu64.dll",
|
|
|
|
}
|
|
|
|
|
2024-08-01 21:52:15 +00:00
|
|
|
var (
|
|
|
|
CudartMgmtName = "cudart64_*.dll"
|
|
|
|
NvcudaMgmtName = "nvcuda.dll"
|
|
|
|
NvmlMgmtName = "nvml.dll"
|
|
|
|
OneapiMgmtName = "ze_intel_gpu64.dll"
|
|
|
|
)
|
2024-06-05 19:07:20 +00:00
|
|
|
|
|
|
|
func GetCPUMem() (memInfo, error) {
|
|
|
|
memStatus := MEMORYSTATUSEX{length: sizeofMemoryStatusEx}
|
|
|
|
r1, _, err := globalMemoryStatusExProc.Call(uintptr(unsafe.Pointer(&memStatus)))
|
|
|
|
if r1 == 0 {
|
|
|
|
return memInfo{}, fmt.Errorf("GlobalMemoryStatusEx failed: %w", err)
|
|
|
|
}
|
2024-07-11 23:42:57 +00:00
|
|
|
return memInfo{TotalMemory: memStatus.TotalPhys, FreeMemory: memStatus.AvailPhys, FreeSwap: memStatus.AvailPageFile}, nil
|
2024-06-05 19:07:20 +00:00
|
|
|
}
|