Skip to content

Commit 0bcbae9

Browse files
committed
GPU: clean up GPU index detection code
1 parent 503a8d5 commit 0bcbae9

File tree

7 files changed

+14
-12
lines changed

7 files changed

+14
-12
lines changed

src/detection/gpu/gpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ typedef struct FFGPUMemory
2828

2929
typedef struct FFGPUResult
3030
{
31-
uint8_t index;
31+
uint32_t index;
3232
FFGPUType type;
3333
FFstrbuf vendor;
3434
FFstrbuf name;

src/detection/gpu/gpu_amd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,8 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu
6565
if (result.type)
6666
*result.type = device->isAPU ? FF_GPU_TYPE_INTEGRATED : FF_GPU_TYPE_DISCRETE;
6767

68+
if (result.index)
69+
*result.type = (uint32_t) device->adlAdapterIndex;
70+
6871
return NULL;
6972
}

src/detection/gpu/gpu_apple.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
ffStrbufSetStatic(&gpu->platformApi, "Metal Common 1");
4444

4545
gpu->type = device.hasUnifiedMemory ? FF_GPU_TYPE_INTEGRATED : FF_GPU_TYPE_DISCRETE;
46-
gpu->index = (uint8_t)device.locationNumber;
46+
gpu->index = (uint32_t) device.locationNumber;
4747
#endif
4848
}
4949
return NULL;

src/detection/gpu/gpu_driver_specific.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ typedef struct FFGpuDriverCondition
3737
// detect x if not NULL
3838
typedef struct FFGpuDriverResult
3939
{
40-
uint8_t* index;
40+
uint32_t* index;
4141
double* temp;
4242
FFGPUMemory* memory;
4343
uint32_t* coreCount;

src/detection/gpu/gpu_mthreads.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ const char *ffDetectMthreadsGpuInfo(const FFGpuDriverCondition *cond, FFGpuDrive
138138
{
139139
unsigned int value;
140140
if (mtmlData.ffmtmlDeviceGetIndex(device, &value) == MTML_SUCCESS)
141-
*result.index = (uint8_t)value;
141+
*result.index = value;
142142
}
143143

144144
if (result.temp)

src/detection/gpu/gpu_nvidia.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR
111111
{
112112
unsigned int value;
113113
if (nvmlData.ffnvmlDeviceGetIndex(device, &value) == NVML_SUCCESS)
114-
*result.index = (uint8_t)value;
114+
*result.index = value;
115115
}
116-
116+
117117

118118
if (result.temp)
119119
{

src/modules/gpu/gpu.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <stdlib.h>
1212

13-
#define FF_GPU_NUM_FORMAT_ARGS 12
13+
#define FF_GPU_NUM_FORMAT_ARGS 13
1414

1515
static void printGPUResult(FFGPUOptions* options, uint8_t index, const FFGPUResult* gpu)
1616
{
@@ -103,6 +103,7 @@ static void printGPUResult(FFGPUOptions* options, uint8_t index, const FFGPUResu
103103
FF_FORMAT_ARG(sUsed, "shared-used"),
104104
FF_FORMAT_ARG(gpu->platformApi, "platform-api"),
105105
FF_FORMAT_ARG(frequency, "frequency"),
106+
FF_FORMAT_ARG(index, "index"),
106107
}));
107108
}
108109
}
@@ -323,13 +324,10 @@ void ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_
323324
{
324325
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
325326

326-
if (gpu->index != FF_GPU_INDEX_UNSET){
327-
yyjson_mut_obj_add_uint(doc, obj, "index", (uint64_t)gpu->index);
328-
}
327+
if (gpu->index != FF_GPU_INDEX_UNSET)
328+
yyjson_mut_obj_add_uint(doc, obj, "index", gpu->index);
329329
else
330-
{
331330
yyjson_mut_obj_add_null(doc, obj, "index");
332-
}
333331

334332
if (gpu->coreCount != FF_GPU_CORE_COUNT_UNSET)
335333
yyjson_mut_obj_add_int(doc, obj, "coreCount", gpu->coreCount);
@@ -411,6 +409,7 @@ void ffPrintGPUHelpFormat(void)
411409
"GPU used shared memory - shared-used",
412410
"The platform API used when detecting the GPU - platform-api",
413411
"Current frequency in GHz - frequency",
412+
"GPU vendor specific index - index",
414413
}));
415414
}
416415

0 commit comments

Comments
 (0)