gpu_windows.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package gpu
  2. import (
  3. "fmt"
  4. "syscall"
  5. "unsafe"
  6. )
  7. type MEMORYSTATUSEX struct {
  8. length uint32
  9. MemoryLoad uint32
  10. TotalPhys uint64
  11. AvailPhys uint64
  12. TotalPageFile uint64
  13. AvailPageFile uint64
  14. TotalVirtual uint64
  15. AvailVirtual uint64
  16. AvailExtendedVirtual uint64
  17. }
  18. var (
  19. k32 = syscall.NewLazyDLL("kernel32.dll")
  20. globalMemoryStatusExProc = k32.NewProc("GlobalMemoryStatusEx")
  21. sizeofMemoryStatusEx = uint32(unsafe.Sizeof(MEMORYSTATUSEX{}))
  22. )
  23. var CudartGlobs = []string{
  24. "c:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v*\\bin\\cudart64_*.dll",
  25. }
  26. var NvmlGlobs = []string{
  27. "c:\\Windows\\System32\\nvml.dll",
  28. }
  29. var NvcudaGlobs = []string{
  30. "c:\\windows\\system*\\nvcuda.dll",
  31. }
  32. var OneapiGlobs = []string{
  33. "c:\\Windows\\System32\\DriverStore\\FileRepository\\*\\ze_intel_gpu64.dll",
  34. }
  35. var CudartMgmtName = "cudart64_*.dll"
  36. var NvcudaMgmtName = "nvcuda.dll"
  37. var NvmlMgmtName = "nvml.dll"
  38. var OneapiMgmtName = "ze_intel_gpu64.dll"
  39. func GetCPUMem() (memInfo, error) {
  40. memStatus := MEMORYSTATUSEX{length: sizeofMemoryStatusEx}
  41. r1, _, err := globalMemoryStatusExProc.Call(uintptr(unsafe.Pointer(&memStatus)))
  42. if r1 == 0 {
  43. return memInfo{}, fmt.Errorf("GlobalMemoryStatusEx failed: %w", err)
  44. }
  45. return memInfo{TotalMemory: memStatus.TotalPhys, FreeMemory: memStatus.AvailPhys}, nil
  46. }