2023-12-20 14:45:27 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "gpu.h"
|
|
|
|
|
|
2026-04-09 16:20:59 +08:00
|
|
|
typedef enum FF_A_PACKED FFGpuDriverConditionType {
|
2023-12-20 14:45:27 +08:00
|
|
|
FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID = 1 << 0,
|
|
|
|
|
FF_GPU_DRIVER_CONDITION_TYPE_DEVICE_ID = 1 << 1,
|
|
|
|
|
FF_GPU_DRIVER_CONDITION_TYPE_LUID = 1 << 2,
|
2024-11-14 10:04:57 +08:00
|
|
|
FF_GPU_DRIVER_CONDITION_TYPE_FORCE_UNSIGNED = UINT8_MAX,
|
2023-12-20 14:45:27 +08:00
|
|
|
} FFGpuDriverConditionType;
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
typedef struct FFGpuDriverPciDeviceId {
|
2023-12-20 14:45:27 +08:00
|
|
|
uint32_t deviceId;
|
|
|
|
|
uint32_t vendorId;
|
|
|
|
|
uint32_t subSystemId;
|
|
|
|
|
uint32_t revId;
|
|
|
|
|
} FFGpuDriverPciDeviceId;
|
|
|
|
|
|
|
|
|
|
// Use pciBusId if not NULL; use pciDeviceId otherwise
|
2026-03-29 09:28:49 +08:00
|
|
|
typedef struct FFGpuDriverCondition {
|
2023-12-20 14:45:27 +08:00
|
|
|
FFGpuDriverConditionType type;
|
|
|
|
|
FFGpuDriverPciBusId pciBusId;
|
|
|
|
|
FFGpuDriverPciDeviceId pciDeviceId;
|
|
|
|
|
uint64_t luid;
|
|
|
|
|
} FFGpuDriverCondition;
|
|
|
|
|
|
|
|
|
|
// detect x if not NULL
|
2026-03-29 09:28:49 +08:00
|
|
|
typedef struct FFGpuDriverResult {
|
2024-09-19 15:38:43 +08:00
|
|
|
uint32_t* index;
|
2023-12-20 14:45:27 +08:00
|
|
|
double* temp;
|
|
|
|
|
FFGPUMemory* memory;
|
2025-03-24 15:22:26 +08:00
|
|
|
FFstrbuf* memoryType;
|
|
|
|
|
FFGPUMemory* sharedMemory;
|
2023-12-20 14:45:27 +08:00
|
|
|
uint32_t* coreCount;
|
2024-08-01 14:10:07 +08:00
|
|
|
double* coreUsage;
|
2023-12-20 14:45:27 +08:00
|
|
|
FFGPUType* type;
|
2024-07-17 14:52:35 +08:00
|
|
|
uint32_t* frequency;
|
2024-08-02 15:21:42 +08:00
|
|
|
FFstrbuf* name;
|
2023-12-20 14:45:27 +08:00
|
|
|
} FFGpuDriverResult;
|
|
|
|
|
|
|
|
|
|
const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName);
|
|
|
|
|
const char* ffDetectIntelGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName);
|
2023-12-21 14:53:35 +08:00
|
|
|
const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName);
|
2024-08-02 16:00:54 +08:00
|
|
|
const char* ffDetectMthreadsGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName);
|
2024-08-02 16:29:23 +08:00
|
|
|
|
2026-04-05 00:08:18 +08:00
|
|
|
#ifndef FF_GPU_DRIVER_DLLNAME_PATH_PREFIX
|
2026-04-15 16:16:46 +08:00
|
|
|
#define FF_GPU_DRIVER_DLLNAME_PATH_PREFIX
|
2026-04-05 00:08:18 +08:00
|
|
|
#endif
|
|
|
|
|
|
2026-04-09 16:20:59 +08:00
|
|
|
FF_A_UNUSED static inline bool getDriverSpecificDetectionFn(const char* vendor, __typeof__(&ffDetectNvidiaGpuInfo)* pDetectFn, const char** pDllName) {
|
2026-03-29 09:28:49 +08:00
|
|
|
if (vendor == FF_GPU_VENDOR_NAME_NVIDIA) {
|
2024-08-02 16:29:23 +08:00
|
|
|
*pDetectFn = ffDetectNvidiaGpuInfo;
|
2026-03-29 09:28:49 +08:00
|
|
|
#ifdef _WIN32
|
2026-04-05 00:08:18 +08:00
|
|
|
*pDllName = FF_GPU_DRIVER_DLLNAME_PATH_PREFIX "nvml.dll";
|
2026-03-29 09:28:49 +08:00
|
|
|
#else
|
2026-04-05 00:08:18 +08:00
|
|
|
*pDllName = FF_GPU_DRIVER_DLLNAME_PATH_PREFIX "libnvidia-ml.so";
|
2026-03-29 09:28:49 +08:00
|
|
|
#endif
|
|
|
|
|
} else if (vendor == FF_GPU_VENDOR_NAME_MTHREADS) {
|
2024-08-02 16:29:23 +08:00
|
|
|
*pDetectFn = ffDetectMthreadsGpuInfo;
|
2026-03-29 09:28:49 +08:00
|
|
|
#ifdef _WIN32
|
2026-04-05 00:08:18 +08:00
|
|
|
*pDllName = FF_GPU_DRIVER_DLLNAME_PATH_PREFIX "mtml.dll";
|
2026-03-29 09:28:49 +08:00
|
|
|
#else
|
2026-04-05 00:08:18 +08:00
|
|
|
*pDllName = FF_GPU_DRIVER_DLLNAME_PATH_PREFIX "libmtml.so";
|
2026-03-29 09:28:49 +08:00
|
|
|
#endif
|
2024-08-02 16:29:23 +08:00
|
|
|
}
|
2026-03-29 09:28:49 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
else if (vendor == FF_GPU_VENDOR_NAME_INTEL) {
|
2024-08-02 16:29:23 +08:00
|
|
|
*pDetectFn = ffDetectIntelGpuInfo;
|
2026-04-15 16:16:46 +08:00
|
|
|
#ifdef _WIN64
|
2026-04-05 00:08:18 +08:00
|
|
|
*pDllName = FF_GPU_DRIVER_DLLNAME_PATH_PREFIX "ControlLib.dll";
|
2026-04-15 16:16:46 +08:00
|
|
|
#else
|
2026-04-05 00:08:18 +08:00
|
|
|
*pDllName = FF_GPU_DRIVER_DLLNAME_PATH_PREFIX "ControlLib32.dll";
|
2026-04-15 16:16:46 +08:00
|
|
|
#endif
|
2026-03-29 09:28:49 +08:00
|
|
|
} else if (vendor == FF_GPU_VENDOR_NAME_AMD) {
|
2024-08-02 16:29:23 +08:00
|
|
|
*pDetectFn = ffDetectAmdGpuInfo;
|
2026-04-15 16:16:46 +08:00
|
|
|
#ifdef _WIN64
|
2026-04-05 00:08:18 +08:00
|
|
|
*pDllName = FF_GPU_DRIVER_DLLNAME_PATH_PREFIX "atiadlxx.dll";
|
2026-04-15 16:16:46 +08:00
|
|
|
#else
|
2026-04-05 00:08:18 +08:00
|
|
|
*pDllName = FF_GPU_DRIVER_DLLNAME_PATH_PREFIX "atiadlxy.dll";
|
2026-04-15 16:16:46 +08:00
|
|
|
#endif
|
2024-08-02 16:29:23 +08:00
|
|
|
}
|
2026-03-29 09:28:49 +08:00
|
|
|
#endif
|
|
|
|
|
else {
|
2024-08-02 16:29:23 +08:00
|
|
|
*pDetectFn = NULL;
|
|
|
|
|
*pDllName = NULL;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|