It is currently Fri Jul 10, 2020 5:08 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: NVIDIA Management Library (NVML) and PureBasic
PostPosted: Wed Nov 27, 2019 10:26 am 
Offline
Enthusiast
Enthusiast

Joined: Mon May 10, 2010 4:02 pm
Posts: 153
A C-based API for monitoring and managing various states of the NVIDIA GPU devices. It provides a direct access to the queries and commands exposed via nvidia-smi. The runtime version of NVML ships with the NVIDIA display driver, and the SDK provides the appropriate header, stub libraries and sample applications. Each new version of NVML is backwards compatible and is intended to be a platform for building 3rd party applications.
https://developer.nvidia.com/nvidia-man ... brary-nvml

Code:
; NVIDIA Management Library (NVML)
;https://developer.nvidia.com/nvidia-management-library-nvml
; PureBasic x64

#NVML_CLOCK_GRAPHICS  = 0;   Graphics clock domain
#NVML_CLOCK_MEM       = 2;   Memory clock domain
Global nvml_Lib.s = GetUserDirectory(#PB_Directory_Programs) + "NVIDIA Corporation\NVSMI\nvml.dll";

Structure nvmlUtilization_t
  GPU.l
  Mem.l
EndStructure

UtilGPU.nvmlUtilization_t

Prototype nvmlInit()
Prototype nvmlShutdown()
Prototype nvmlDeviceGetCount(pDevCount.l)
Prototype nvmlDeviceGetHandleByIndex (GPU_num.l, GPU_Handle.l)
Prototype nvmlDeviceGetTemperature (GPU_Handle.l, SensorType.l, Temperature.l)
Prototype nvmlDeviceGetUtilizationRates(GPU_Handle1.l, pUtilizationl)
Prototype nvmlDeviceGetClockInfo ( GPU_Handle.l, ClockType.l,  Clock.i)
Prototype nvmlDeviceGetFanSpeed ( GPU_Handle.l, nvmlValue.l)
Prototype nvmlDeviceGetPowerUsage(GPU_Handle.l, nvmlValue.i)

Global nvmlInit.nvmlInit
Global nvmlShutdown.nvmlShutdown
Global nvmlDeviceGetCount.nvmlDeviceGetCount
Global nvmlDeviceGetHandleByIndex.nvmlDeviceGetHandleByIndex
Global nvmlDeviceGetTemperature.nvmlDeviceGetTemperature
Global nvmlDeviceGetUtilizationRates.nvmlDeviceGetUtilizationRates
Global nvmlDeviceGetClockInfo.nvmlDeviceGetClockInfo
Global nvmlDeviceGetFanSpeed.nvmlDeviceGetFanSpeed
Global nvmlDeviceGetPowerUsage.nvmlDeviceGetPowerUsage


;{ Windows
Enumeration
  #Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
  #Text_0
  #Text_1
  #Text_2
  #Text_3
  #Text_4
  #Text_5
  #Text_6
  #Text_7
   
  #Text_GPU_name
  #Text_Temperatur
  #Text_Usage_GPU
  #Text_Usage_Memory_GPU
  #Text_GPU_freq
  #Text_Memory_freq
  #Text_FanSpeed
  #Text_Power_GPU
   
  #Text_20
  #Text_21
  #Text_22
  #Text_23
  #Text_24
  #Text_25
  #Text_26
  #Text_27
   
EndEnumeration
;}


Procedure.i nvml_LoadDLL()
  Protected hDLL.i

  hDLL = OpenLibrary(#PB_Any, nvml_Lib)
  If hDLL <> 0
    nvmlInit = GetFunction(hDLL, "nvmlInit")
    nvmlShutdown= GetFunction(hDLL, "nvmlShutdown")
    nvmlDeviceGetCount= GetFunction(hDLL, "nvmlDeviceGetCount")
    nvmlDeviceGetHandleByIndex= GetFunction(hDLL, "nvmlDeviceGetHandleByIndex")
    nvmlDeviceGetTemperature = GetFunction(hDLL, "nvmlDeviceGetTemperature")
    nvmlDeviceGetUtilizationRates = GetFunction(hDLL, "nvmlDeviceGetUtilizationRates")
    nvmlDeviceGetClockInfo = GetFunction(hDLL, "nvmlDeviceGetClockInfo")
    nvmlDeviceGetFanSpeed  = GetFunction(hDLL, "nvmlDeviceGetFanSpeed")
    nvmlDeviceGetPowerUsage   = GetFunction(hDLL, "nvmlDeviceGetPowerUsage")
  ProcedureReturn hDLL
  EndIf

  ProcedureReturn #False
EndProcedure


; nco2k : https://www.purebasic.fr/english/viewtopic.php?f=13&t=70048
Procedure$ GPUName()
  Protected Result$, DisplayDeviceIndex, display_device.DISPLAY_DEVICE\cb = SizeOf(DISPLAY_DEVICE)
  While EnumDisplayDevices_(0, DisplayDeviceIndex, @display_device, 0)
    If display_device\StateFlags & #DISPLAY_DEVICE_PRIMARY_DEVICE = #DISPLAY_DEVICE_PRIMARY_DEVICE
      Result$ = PeekS(@display_device\DeviceString)
      Break
    EndIf
    DisplayDeviceIndex + 1
  Wend
  ProcedureReturn Result$
EndProcedure


;}
Procedure OpenWindow_Window_0()
  If OpenWindow(#Window_0, 860, 130, 400, 400, "GPU INFO", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
   
      TextGadget(#Text_0, 5, 15, 105, 25, "GPU name  ")
      TextGadget(#Text_1, 5, 45, 205, 25, "Temperature ")
      TextGadget(#Text_2, 5, 75, 205, 25, "Usage GPU  ")
      TextGadget(#Text_3, 5, 105, 205, 25, "Usage Memory GPU")
      TextGadget(#Text_4, 5, 135, 205, 25, "GPU freq")
      TextGadget(#Text_5, 5, 165, 205, 25, "Memory freq")
      TextGadget(#Text_6, 5, 195, 205, 25, "FanSpeed")
      TextGadget(#Text_7, 5, 225, 205, 25, "Power GPU")
 
     
      TextGadget(#Text_GPU_name, 130, 15, 225, 25, "0")
      TextGadget(#Text_Temperatur, 230, 45, 125, 25, "0")
      TextGadget(#Text_Usage_GPU, 230, 75, 125, 25, "0")
      TextGadget(#Text_Usage_Memory_GPU, 230, 105, 125, 25, "0")
      TextGadget(#Text_GPU_freq, 230, 135, 125, 25, "0")
      TextGadget(#Text_Memory_freq, 230, 165, 125, 25, "0")
      TextGadget(#Text_FanSpeed, 230, 195, 125, 25, "0")
      TextGadget(#Text_Power_GPU, 230, 225, 125, 25, "0")
 
     
      TextGadget(#Text_20, 360, 15, 35, 25, "")
      TextGadget(#Text_21, 360, 45, 35, 25, " C")
      TextGadget(#Text_22, 360, 75, 35, 25, " %")
      TextGadget(#Text_23, 360, 105, 35, 25, " %")
      TextGadget(#Text_24, 360, 135, 35, 25, " MGz")
      TextGadget(#Text_25, 360, 165, 35, 25, " MGz")
      TextGadget(#Text_26, 360, 195, 35, 25, " %")
      TextGadget(#Text_27, 360, 225, 35, 25, " mW")
      AddWindowTimer(#Window_0, 1, 250)
   
  EndIf
EndProcedure

OpenWindow_Window_0()

SetGadgetText(#Text_GPU_name,GPUName())

If nvml_LoadDLL()
  nvmlInit()
  nvmlDeviceGetCount(@GPU_count)
   
   If GPU_count>0
     nvmlDeviceGetHandleByIndex(0,@GPU_Handle)
   Else
     MessageRequester("Error", "There is no Data")
     End
  EndIf
  Else
    MessageRequester("Error", "There is no Data")
    End
   EndIf 

;{- Event loop
Repeat
  Event = WaitWindowEvent()
  Select Event
    ; ///////////////////
    Case #PB_Event_Gadget
      EventGadget = EventGadget()
      EventType = EventType()
      If EventGadget = #Text_0
     
      EndIf
    Case #PB_Event_Timer
      If EventTimer() = 1
        nvmlDeviceGetTemperature(GPU_Handle, 0, @Temperature)
        SetGadgetText(#Text_Temperatur, "" + Temperature)
        nvmlDeviceGetUtilizationRates(GPU_Handle,@UtilGPU)
        SetGadgetText(#Text_Usage_GPU, "" + UtilGPU\GPU)
        SetGadgetText(#Text_Usage_Memory_GPU, "" + UtilGPU\Mem)
       
        ; Get information about the frequencies of the processor and GPU memory
       
        If nvmlDeviceGetClockInfo(GPU_Handle, #NVML_CLOCK_GRAPHICS, @nvmlValue) = 0 
           SetGadgetText(#Text_GPU_freq, "" +nvmlValue)
       Else
           SetGadgetText(#Text_GPU_freq, "there is no data" )
      EndIf
     
      If nvmlDeviceGetClockInfo(GPU_Handle, #NVML_CLOCK_MEM,@nvmlValue) = 0
        SetGadgetText(#Text_Memory_freq, "" + nvmlValue)
          Else
        SetGadgetText(#Text_Memory_freq, "there is no data" )
      EndIf
   
      ;  Get NVIDIA-GPU Fan Speed Information
      If nvmlDeviceGetFanSpeed(GPU_Handle, @nvmlValue) = 0
        SetGadgetText(#Text_FanSpeed,"" + nvmlValue)
        Else
        SetGadgetText(#Text_FanSpeed, "there is no data" )
      EndIf

     
      ; Get NVIDIA-GPU Power Consumption Information
      err = nvmlDeviceGetPowerUsage (GPU_Handle, @nvmlValue)
      If  err = 0
        SetGadgetText(#Text_Power_GPU,"" + nvmlValue)
       
      Else
         SetGadgetText(#Text_Power_GPU, "Error № " + err )
      EndIf
     
      EndIf
     
    ; ////////////////////////
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = #Window_0
        CloseWindow(#Window_0)
        nvmlShutdown()
        Break
      EndIf
  EndSelect
ForEver
;
;}

Image


Top
 Profile  
Reply with quote  
 Post subject: Re: NVIDIA Management Library (NVML) and PureBasic
PostPosted: Wed Nov 27, 2019 11:14 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Sep 17, 2015 3:39 pm
Posts: 147
interesting
i have an error

Image

_________________
interested in Cybersecurity..


Top
 Profile  
Reply with quote  
 Post subject: Re: NVIDIA Management Library (NVML) and PureBasic
PostPosted: Wed Nov 27, 2019 11:33 am 
Offline
Enthusiast
Enthusiast

Joined: Mon May 10, 2010 4:02 pm
Posts: 153
CELTIC88 wrote:
interesting
i have an error

PureBasic compiler x64?
check GPU_count, GPU_Handle values.


Last edited by kvitaliy on Wed Nov 27, 2019 11:34 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: NVIDIA Management Library (NVML) and PureBasic
PostPosted: Wed Nov 27, 2019 11:33 am 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4802
Location: Germany
Have you download the dll :?:


Top
 Profile  
Reply with quote  
 Post subject: Re: NVIDIA Management Library (NVML) and PureBasic
PostPosted: Wed Nov 27, 2019 11:37 am 
Offline
Enthusiast
Enthusiast

Joined: Mon May 10, 2010 4:02 pm
Posts: 153
infratec wrote:
Have you download the dll :?:

The runtime version of NVML ships with the NVIDIA display driver,
usually in "C:\Program Files\NVIDIA Corporation\NVSMI\nvml.dll"


Top
 Profile  
Reply with quote  
 Post subject: Re: NVIDIA Management Library (NVML) and PureBasic
PostPosted: Wed Nov 27, 2019 11:43 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Sep 17, 2015 3:39 pm
Posts: 147
kvitaliy wrote:
CELTIC88 wrote:
interesting
i have an error

PureBasic compiler x64?
check GPU_count, GPU_Handle values.



"" ah it work fine in x64, thank for sharing :)

_________________
interested in Cybersecurity..


Top
 Profile  
Reply with quote  
 Post subject: Re: NVIDIA Management Library (NVML) and PureBasic
PostPosted: Wed Nov 27, 2019 11:46 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Sep 17, 2015 3:39 pm
Posts: 147
i have temperature 55 c ? it's normal?

_________________
interested in Cybersecurity..


Top
 Profile  
Reply with quote  
 Post subject: Re: NVIDIA Management Library (NVML) and PureBasic
PostPosted: Wed Nov 27, 2019 12:03 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon May 10, 2010 4:02 pm
Posts: 153
CELTIC88 wrote:
i have temperature 55 c ? it's normal?


GeForce GTX 1080
idle temperature = 42
permissible temperature = 60-84
maximum temperature = 94


Top
 Profile  
Reply with quote  
 Post subject: Re: NVIDIA Management Library (NVML) and PureBasic
PostPosted: Wed Nov 27, 2019 12:13 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 2:15 pm
Posts: 881
Location: Cuernavaca, Mexico
CELTIC88...

I'm showing 36 degrees and 15,000 mW and steady.

(see signature)

Thanks kvitaliy 8)

I'm thinking that a high temperature alarm might be a added, possibly even a temperature log.

(It would be handy when I'm flying my Flight Simulator on 3 screens)

_________________
- It was too lonely at the top.

Current Machine: Win 10 Pro 64-bit, Dual Xeon E5-2670, 64 gigs ram, Geforce GTX 1660 Ti w/6 gigs ram


Top
 Profile  
Reply with quote  
 Post subject: Re: NVIDIA Management Library (NVML) and PureBasic
PostPosted: Thu Nov 28, 2019 8:58 am 
Offline
Addict
Addict
User avatar

Joined: Wed Apr 30, 2003 8:15 am
Posts: 1027
Location: Germany
Thx kvitaliy, nice tool!

_________________
"Daddy, I'll run faster, then it is not so far..."


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye