Tags down


Cuda get gpu load percent

By : Akash Sharma
Date : October 16 2020, 03:08 PM
I wish this help you http://eliang.blogspot.com.by/2011/05/getting-nvidia-gpu-usage-in-c.html?m=1
code :
// Getting Nvidia GPU Usage
// Reference: Open Hardware Monitor (http://code.google.com/p/open-hardware-monitor)

#include <windows.h>
#include <iostream>

// magic numbers, do not change them

// function pointer types
typedef int *(*NvAPI_QueryInterface_t)(unsigned int offset);
typedef int (*NvAPI_Initialize_t)();
typedef int (*NvAPI_EnumPhysicalGPUs_t)(int **handles, int *count);
typedef int (*NvAPI_GPU_GetUsages_t)(int *handle, unsigned int *usages);

int main()
    HMODULE hmod = LoadLibraryA("nvapi.dll");
    if (hmod == NULL)
        std::cerr << "Couldn't find nvapi.dll" << std::endl;
        return 1;

    // nvapi.dll internal function pointers
    NvAPI_QueryInterface_t      NvAPI_QueryInterface     = NULL;
    NvAPI_Initialize_t          NvAPI_Initialize         = NULL;
    NvAPI_EnumPhysicalGPUs_t    NvAPI_EnumPhysicalGPUs   = NULL;
    NvAPI_GPU_GetUsages_t       NvAPI_GPU_GetUsages      = NULL;

    // nvapi_QueryInterface is a function used to retrieve other internal functions in nvapi.dll
    NvAPI_QueryInterface = (NvAPI_QueryInterface_t) GetProcAddress(hmod, "nvapi_QueryInterface");

    // some useful internal functions that aren't exported by nvapi.dll
    NvAPI_Initialize = (NvAPI_Initialize_t) (*NvAPI_QueryInterface)(0x0150E828);
    NvAPI_EnumPhysicalGPUs = (NvAPI_EnumPhysicalGPUs_t) (*NvAPI_QueryInterface)(0xE5AC921F);
    NvAPI_GPU_GetUsages = (NvAPI_GPU_GetUsages_t) (*NvAPI_QueryInterface)(0x189A1FDF);

    if (NvAPI_Initialize == NULL || NvAPI_EnumPhysicalGPUs == NULL ||
        NvAPI_EnumPhysicalGPUs == NULL || NvAPI_GPU_GetUsages == NULL)
        std::cerr << "Couldn't get functions in nvapi.dll" << std::endl;
        return 2;

    // initialize NvAPI library, call it once before calling any other NvAPI functions

    int          gpuCount = 0;
    int         *gpuHandles[NVAPI_MAX_PHYSICAL_GPUS] = { NULL };
    unsigned int gpuUsages[NVAPI_MAX_USAGES_PER_GPU] = { 0 };

    // gpuUsages[0] must be this value, otherwise NvAPI_GPU_GetUsages won't work
    gpuUsages[0] = (NVAPI_MAX_USAGES_PER_GPU * 4) | 0x10000;

    (*NvAPI_EnumPhysicalGPUs)(gpuHandles, &gpuCount);

    // print GPU usage every second
    for (int i = 0; i < 100; i++)
        (*NvAPI_GPU_GetUsages)(gpuHandles[0], gpuUsages);
        int usage = gpuUsages[3];
        std::cout << "GPU Usage: " << usage << std::endl;

    return 0;

Share : facebook icon twitter icon

how to get cpu load linux java in percent precise and easy way?

By : Jordyn Iger
Date : March 29 2020, 07:55 AM
help you fix your problem Its better to use Sigar API, you can use it for extracting different metrics. I have also used this for my application, you can refer the following link

Why is my iOS 7 app running at 100 percent processor load after some time?

By : Agarwal Satyam
Date : March 29 2020, 07:55 AM
help you fix your problem I found the answer myself by commenting out different parts of my code until I could pinpoint the part of my code that caused this behavior.
The problem was caused by the following code segment, which I used to change the color of icons..
code :
UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
CGContextRef context = UIGraphicsGetCurrentContext();
[color setFill];
CGContextTranslateCTM(context, 0, image.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextClipToMask(context, CGRectMake(0, 0, image.size.width, image.size.height), [image CGImage]);
CGContextFillRect(context, CGRectMake(0, 0, image.size.width, image.size.height));

Retrieving CPU Load Percent total in Windows with C++

By : Anthony Louey
Date : March 29 2020, 07:55 AM
like below fixes the issue The reason it's popular to compute the load percentage over time is because CPUs don't really have variable speeds -- at any given instant, a CPU core is either processing instructions at its rated clock rate, or it's sitting idle, so an instantaneous measurement would only give you 0% or 100% (*), which isn't really what you want. So in order to calculate a meaningful load percentage, you have to examine what percentage of time the CPU was idle during a particular interval of time.
In any case, here's some code I use to get a CPU-usage value under Windows... just call GetCPULoad() at regular intervals (e.g. every 250mS or at whatever rate you like) and multiply by 100.0 to get a percentage:
code :
#include <Windows.h>

static float CalculateCPULoad(unsigned long long idleTicks, unsigned long long totalTicks)
   static unsigned long long _previousTotalTicks = 0;
   static unsigned long long _previousIdleTicks = 0;

   unsigned long long totalTicksSinceLastTime = totalTicks-_previousTotalTicks;
   unsigned long long idleTicksSinceLastTime  = idleTicks-_previousIdleTicks;

   float ret = 1.0f-((totalTicksSinceLastTime > 0) ? ((float)idleTicksSinceLastTime)/totalTicksSinceLastTime : 0);

   _previousTotalTicks = totalTicks;
   _previousIdleTicks  = idleTicks;
   return ret;

static unsigned long long FileTimeToInt64(const FILETIME & ft) {return (((unsigned long long)(ft.dwHighDateTime))<<32)|((unsigned long long)ft.dwLowDateTime);}

// Returns 1.0f for "CPU fully pinned", 0.0f for "CPU idle", or somewhere in between
// You'll need to call this at regular intervals, since it measures the load between
// the previous call and the current one.  Returns -1.0 on error.
float GetCPULoad()
   FILETIME idleTime, kernelTime, userTime;
   return GetSystemTimes(&idleTime, &kernelTime, &userTime) ? CalculateCPULoad(FileTimeToInt64(idleTime), FileTimeToInt64(kernelTime)+FileTimeToInt64(userTime)) : -1.0f;

AQuery load image with progress in percent on progressbar

By : Fastwp
Date : March 29 2020, 07:55 AM
seems to work fine I'm trying to load images from website with aquery and show loading progress in percent on progressbar. Documentation says, that it is possible with this sample code aq.id(R.id.image).progress(R.id.progress).image(imageUrl, true, true); , Problem disappears after updating AQuery library

100 percent load with multiprocessing queues

By : ifungo
Date : March 29 2020, 07:55 AM
I hope this helps you . I'm not sure I understand your program:
What's with the num parameter of func1() and func2()? It never gets used. func2 will discard its result if func1 happens to have posted another number after func2 got the last number out of the queue. Why do you daemonize the workers? Are you quite sure this is what you want? The if not q.empty(): q.get() construct in the main code will sooner or later raise a queue.Empty exception because it's a race between it and the q.get() in func2. The uncaught queue.Empty exception will terminate the main process, leaving the two workers orphaned - and running.
code :
import multiprocessing
import time
import random
import os

def request_generator(requests):
    while True:
        requests.put(random.randint(1, 101))

def worker(requests, responses):
    worker_id = os.getpid()
    while True:
        request = requests.get()
        response = request ** 2
        responses.put((request, response, worker_id))

def main():
    requests = multiprocessing.Queue()
    responses = multiprocessing.Queue()
    gen = multiprocessing.Process(target=request_generator, args=(requests,))
    w1 = multiprocessing.Process(target=worker, args=(requests, responses))
    w2 = multiprocessing.Process(target=worker, args=(requests, responses))
    while True:
        req, resp, worker_id = responses.get()
        print("worker {}: {} => {}".format(worker_id, req, resp))

if __name__ == "__main__":
Related Posts Related Posts :
Privacy Policy - Terms - Contact Us © soohba.com