2012-04-11 6 views

risposta

-1

Per quanto ne so, non ci sono funzioni di Carbon per farlo direttamente, quindi la soluzione migliore è probabilmente usare l'API Mach per chiedere al kernel.

This example on Apple Dev. Library dovrebbe iniziare.

+0

Questo esempio sembra implicare * l'utilizzo * della GPU per calcolare un istogramma di un set di dati, non ottenere informazioni sull'utilizzo della GPU. – JWWalker

+0

@JWWalker: sì, sembra essere il caso. Non riesco a controllare completamente, poiché non funziona sulla mia macchina (dice clGetDeviceIDs() fallito. (-1)). – houbysoft

+0

@Nit: Sto cercando qualcosa che OTTIENI l'uso corrente della GPU, non qualcosa che usi la GPU di per sé. – houbysoft

2

Divertiti, uso GPU e RAM, non funziona sulla GPU discreta btw perché non espone il dizionario di monitoraggio delle prestazioni. Il mio MBP ha una GPU NVIDIA, dovrebbe funzionare anche su ATI ma non sono sicuro al 100%

#include <CoreFoundation/CoreFoundation.h> 
#include <Cocoa/Cocoa.h> 
#include <IOKit/IOKitLib.h> 

int main(int argc, const char * argv[]) 
{ 

while (1) { 

    // Get dictionary of all the PCI Devicces 
    CFMutableDictionaryRef matchDict = IOServiceMatching(kIOAcceleratorClassName); 

    // Create an iterator 
    io_iterator_t iterator; 

    if (IOServiceGetMatchingServices(kIOMasterPortDefault,matchDict, 
            &iterator) == kIOReturnSuccess) 
    { 
     // Iterator for devices found 
     io_registry_entry_t regEntry; 

     while ((regEntry = IOIteratorNext(iterator))) { 
      // Put this services object into a dictionary object. 
      CFMutableDictionaryRef serviceDictionary; 
      if (IORegistryEntryCreateCFProperties(regEntry, 
                &serviceDictionary, 
                kCFAllocatorDefault, 
                kNilOptions) != kIOReturnSuccess) 
      { 
       // Service dictionary creation failed. 
       IOObjectRelease(regEntry); 
       continue; 
      } 

      CFMutableDictionaryRef perf_properties = (CFMutableDictionaryRef) CFDictionaryGetValue(serviceDictionary, CFSTR("PerformanceStatistics")); 
      if (perf_properties) { 

       static ssize_t gpuCoreUse=0; 
       static ssize_t freeVramCount=0; 
       static ssize_t usedVramCount=0; 

       const void* gpuCoreUtilization = CFDictionaryGetValue(perf_properties, CFSTR("GPU Core Utilization")); 
       const void* freeVram = CFDictionaryGetValue(perf_properties, CFSTR("vramFreeBytes")); 
       const void* usedVram = CFDictionaryGetValue(perf_properties, CFSTR("vramUsedBytes")); 
       if (gpuCoreUtilization && freeVram && usedVram) 
       { 
        CFNumberGetValue((CFNumberRef) gpuCoreUtilization, kCFNumberSInt64Type, &gpuCoreUse); 
        CFNumberGetValue((CFNumberRef) freeVram, kCFNumberSInt64Type, &freeVramCount); 
        CFNumberGetValue((CFNumberRef) usedVram, kCFNumberSInt64Type, &usedVramCount); 
        NSLog(@"GPU: %.3f%% VRAM: %.3f%%",gpuCoreUse/(double)10000000,usedVramCount/(double)(freeVramCount+usedVramCount)*100.0); 

       } 

      } 

      CFRelease(serviceDictionary); 
      IOObjectRelease(regEntry); 
     } 
     IOObjectRelease(iterator); 
    } 

    sleep(1); 
} 
return 0; 
} 
+0

Quindi non c'è modo di ottenere dati gpu dedicati e discreti? –

+0

no, la GPU discreta non espone i dati delle prestazioni, ho anche scoperto che né ATI lo espone, solo l'uso di VRAM, ma nulla per l'utilizzo della GPU:/ –

+0

Ciao di nuovo, Come posso modificare il codice in modo che possa supportare 2 o più GPU? Non ho questo tipo di Hardware anche se non ho un'idea da cui iniziare, per favore, aiutatemi? –

Problemi correlati