Skip to content

Commit

Permalink
GPU: clean up GPU index detection code
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi committed Sep 19, 2024
1 parent 503a8d5 commit 0bcbae9
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/detection/gpu/gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef struct FFGPUMemory

typedef struct FFGPUResult
{
uint8_t index;
uint32_t index;
FFGPUType type;
FFstrbuf vendor;
FFstrbuf name;
Expand Down
3 changes: 3 additions & 0 deletions src/detection/gpu/gpu_amd.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,8 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu
if (result.type)
*result.type = device->isAPU ? FF_GPU_TYPE_INTEGRATED : FF_GPU_TYPE_DISCRETE;

if (result.index)
*result.type = (uint32_t) device->adlAdapterIndex;

return NULL;
}
2 changes: 1 addition & 1 deletion src/detection/gpu/gpu_apple.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
ffStrbufSetStatic(&gpu->platformApi, "Metal Common 1");

gpu->type = device.hasUnifiedMemory ? FF_GPU_TYPE_INTEGRATED : FF_GPU_TYPE_DISCRETE;
gpu->index = (uint8_t)device.locationNumber;
gpu->index = (uint32_t) device.locationNumber;
#endif
}
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/detection/gpu/gpu_driver_specific.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ typedef struct FFGpuDriverCondition
// detect x if not NULL
typedef struct FFGpuDriverResult
{
uint8_t* index;
uint32_t* index;
double* temp;
FFGPUMemory* memory;
uint32_t* coreCount;
Expand Down
2 changes: 1 addition & 1 deletion src/detection/gpu/gpu_mthreads.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const char *ffDetectMthreadsGpuInfo(const FFGpuDriverCondition *cond, FFGpuDrive
{
unsigned int value;
if (mtmlData.ffmtmlDeviceGetIndex(device, &value) == MTML_SUCCESS)
*result.index = (uint8_t)value;
*result.index = value;
}

if (result.temp)
Expand Down
4 changes: 2 additions & 2 deletions src/detection/gpu/gpu_nvidia.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR
{
unsigned int value;
if (nvmlData.ffnvmlDeviceGetIndex(device, &value) == NVML_SUCCESS)
*result.index = (uint8_t)value;
*result.index = value;
}


if (result.temp)
{
Expand Down
11 changes: 5 additions & 6 deletions src/modules/gpu/gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <stdlib.h>

#define FF_GPU_NUM_FORMAT_ARGS 12
#define FF_GPU_NUM_FORMAT_ARGS 13

static void printGPUResult(FFGPUOptions* options, uint8_t index, const FFGPUResult* gpu)
{
Expand Down Expand Up @@ -103,6 +103,7 @@ static void printGPUResult(FFGPUOptions* options, uint8_t index, const FFGPUResu
FF_FORMAT_ARG(sUsed, "shared-used"),
FF_FORMAT_ARG(gpu->platformApi, "platform-api"),
FF_FORMAT_ARG(frequency, "frequency"),
FF_FORMAT_ARG(index, "index"),
}));
}
}
Expand Down Expand Up @@ -323,13 +324,10 @@ void ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_
{
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);

if (gpu->index != FF_GPU_INDEX_UNSET){
yyjson_mut_obj_add_uint(doc, obj, "index", (uint64_t)gpu->index);
}
if (gpu->index != FF_GPU_INDEX_UNSET)
yyjson_mut_obj_add_uint(doc, obj, "index", gpu->index);
else
{
yyjson_mut_obj_add_null(doc, obj, "index");
}

if (gpu->coreCount != FF_GPU_CORE_COUNT_UNSET)
yyjson_mut_obj_add_int(doc, obj, "coreCount", gpu->coreCount);
Expand Down Expand Up @@ -411,6 +409,7 @@ void ffPrintGPUHelpFormat(void)
"GPU used shared memory - shared-used",
"The platform API used when detecting the GPU - platform-api",
"Current frequency in GHz - frequency",
"GPU vendor specific index - index",
}));
}

Expand Down

0 comments on commit 0bcbae9

Please sign in to comment.