Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>In order to query for the gpu usage I first need to call the NvAPI_Initialize function.</p> </blockquote> <p>There are actually two initialization functions involved: the one from the static library nvapi.lib, which tries to dynamically load nvapi.dll, locates some functions and calls the second initialization function from the dynamic link library. The steps involved when calling NvApi_Initialize from the <em>static</em> library are roughly as follows:</p> <ol> <li><p>Check if nvapi.dll is already loaded, if not, load it</p></li> <li><p>Use GetProcAddress to get a pointer to <code>nvapi_QueryInterface</code> from the DLL Use the newly obtained function to query for the interface with the Id <strong>0x150E828</strong>. This will be the second initialization function from the dynamic library</p></li> <li><p>Call the obtained initialization function. If the function was successful (indicated by a return value of 0), obtain two new function pointers via <code>nvapi_QueryInterface</code>, using the ids <strong>0x33C7358C</strong> (let's call this ENTER) and <strong>0x593E8644</strong> (EXIT).</p></li> </ol> <p>So, if you want to stay pure Python, you basically have to replicate these steps using ctypes, which would be pretty easy. After you are done, there is a cleanup function in nvapi.dll, which you can query using the id <strong>0xD22BDD7E</strong>. If you are done using the library, remember to call this function.</p> <p>Now on to the real problem: unfortunately, there is no function <code>NvAPI_GPU_GetUsages</code> in the December 2010 NVIDIA SDK. There is, however, <code>NvAPI_GPU_GetDynamicPstatesInfoEx</code> which will allow you to request an array of structures of type <code>NV_GPU_DYNAMIC_PSTATES_INFO_EX</code> to be filled, which in turn will contain the utilization as percentage of time during the last second for a given domain (i.e. GPU, frame buffer and video engine).</p> <p>Basically, if you want to retrieve GPU usage information, you transfer the <code>NV_GPU_DYNAMIC_PSTATES_INFO_EX</code> struct to Python (see <a href="http://docs.python.org/library/ctypes.html#structures-and-unions" rel="nofollow">Structures and unions</a> in the ctypes documentation), create an array of at least 3 structures and pass that array to the <code>NvAPI_GPU_GetDynamicPstatesInfoEx</code> function, which you would have to query from the dynamic link library first, using the id <strong>0x60DED2ED</strong>.</p> <p>This is, by the way, where the two functions come into play you queries during initialization - it's a sort of locking mechanism. While not strictly necessary (i.e. you can omit this during calling), you are encouraged to call them, i.e.</p> <pre><code>Enter() NvAPI_GPU_GetDynamicPstatesInfoEx(array_of_structs) Exit() </code></pre> <p>You are supposed to be able to find at at which position in the array GPU usage information is stored by looking at the NVAPI_GPU_UTILIZATION_DOMAIN_GPU macro (or constant), unfortunately, there does not seem to be a declaration included in the header files for the SDK. Still, you could easily verify this by comparing the results of your code with the NVIDIA system tool that displays GPU usage information.</p> <p>Hope that helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload