|
| 1 | +#include "gpu.h" |
| 2 | + |
| 3 | +#ifdef FF_HAVE_PCIACCESS |
| 4 | + |
| 5 | +#include "common/properties.h" |
| 6 | +#include "common/io/io.h" |
| 7 | +#include "common/library.h" |
| 8 | + |
| 9 | +#include <pciaccess.h> |
| 10 | + |
| 11 | +const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpus) |
| 12 | +{ |
| 13 | + FF_LIBRARY_LOAD(pciaccess, "Failed to load libpciaccess" FF_LIBRARY_EXTENSION, "libpciaccess" FF_LIBRARY_EXTENSION, 0) |
| 14 | + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(pciaccess, pci_system_init) |
| 15 | + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(pciaccess, pci_slot_match_iterator_create) |
| 16 | + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(pciaccess, pci_device_next) |
| 17 | + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(pciaccess, pci_system_cleanup) |
| 18 | + |
| 19 | + { |
| 20 | + // Requires root access |
| 21 | + // Same behavior can be observed with `cp $(which scanpci) /tmp/ && /tmp/scanpci` |
| 22 | + FF_SUPPRESS_IO(); |
| 23 | + if (ffpci_system_init() < 0) |
| 24 | + return "pci_system_init() failed"; |
| 25 | + } |
| 26 | + |
| 27 | + struct pci_device_iterator* iter = ffpci_slot_match_iterator_create(NULL); |
| 28 | + for (struct pci_device* dev = NULL; (dev = ffpci_device_next(iter)); ) |
| 29 | + { |
| 30 | + if (dev->device_class >> 16 != 0x03 /*PCI_BASE_CLASS_DISPLAY*/) |
| 31 | + continue; |
| 32 | + |
| 33 | + FFGPUResult* gpu = (FFGPUResult*)ffListAdd(gpus); |
| 34 | + ffStrbufInitStatic(&gpu->vendor, ffGetGPUVendorString(dev->vendor_id)); |
| 35 | + ffStrbufInit(&gpu->name); |
| 36 | + ffStrbufInit(&gpu->driver); |
| 37 | + ffStrbufInit(&gpu->platformApi); |
| 38 | + gpu->temperature = FF_GPU_TEMP_UNSET; |
| 39 | + gpu->coreCount = FF_GPU_CORE_COUNT_UNSET; |
| 40 | + gpu->type = FF_GPU_TYPE_UNKNOWN; |
| 41 | + gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET; |
| 42 | + gpu->deviceId = ((uint64_t) dev->domain << 6) | ((uint64_t) dev->bus << 4) | ((uint64_t) dev->dev << 2) | (uint64_t) dev->func; |
| 43 | + gpu->frequency = FF_GPU_FREQUENCY_UNSET; |
| 44 | + |
| 45 | + if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD) |
| 46 | + { |
| 47 | + char query[32]; |
| 48 | + snprintf(query, sizeof(query), "%X,\t%X,", (unsigned) dev->device_id, (unsigned) dev->revision); |
| 49 | + ffParsePropFileData("libdrm/amdgpu.ids", query, &gpu->name); |
| 50 | + } |
| 51 | + |
| 52 | + if (gpu->name.length == 0) |
| 53 | + { |
| 54 | + ffGPUFillVendorAndName((dev->device_class >> 8) & 8, dev->vendor_id, dev->device_id, gpu); |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + ffpci_system_cleanup(); |
| 59 | + return NULL; |
| 60 | +} |
| 61 | + |
| 62 | +#else |
| 63 | +#endif |
0 commit comments