Skip to content

Commit 0b296b5

Browse files
committed
fix: gpustack init uuid to prevent crash for opengl, opencl, vulkan
1 parent 1befc6d commit 0b296b5

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

src/detection/gpu/gpu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ const char* detectByOpenGL(FFlist* gpus)
5353
ffStrbufInitMove(&gpu->name, &result.renderer);
5454
ffStrbufInitMove(&gpu->driver, &result.vendor);
5555
ffStrbufInitF(&gpu->platformApi, "OpenGL %s", result.version.chars);
56+
ffStrbufInit(&gpu->uuid);
5657
gpu->index = FF_GPU_INDEX_UNSET;
5758
gpu->temperature = FF_GPU_TEMP_UNSET;
5859
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
5960
gpu->frequency = FF_GPU_FREQUENCY_UNSET;
6061
gpu->dedicated = gpu->shared = (FFGPUMemory){0, 0};
6162
gpu->deviceId = 0;
63+
gpu->coreUtilizationRate = FF_GPU_CORE_UTILIZATION_RATE_UNSET;
6264

6365
if (ffStrbufContainS(&gpu->name, "Apple"))
6466
{

src/detection/gpu/gpu_apple.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
132132
ffCfDictGetString(properties, CFSTR("model"), &gpu->name);
133133
}
134134

135-
gpu->uuid = ffStrbufGetUUID(&gpu->name);
135+
ffStrbufInit(&gpu->uuid);
136136

137137
ffStrbufInit(&gpu->vendor);
138138
int vendorId;

src/detection/opencl/opencl.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,15 @@ static const char* openCLHandleData(OpenCLData* data, FFOpenCLResult* result)
7575
ffStrbufInit(&gpu->vendor);
7676
ffStrbufInit(&gpu->driver);
7777
ffStrbufInit(&gpu->platformApi);
78+
ffStrbufInit(&gpu->uuid);
79+
gpu->index = FF_GPU_INDEX_UNSET;
7880
gpu->temperature = FF_GPU_TEMP_UNSET;
7981
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
8082
gpu->type = FF_GPU_TYPE_UNKNOWN;
8183
gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET;
8284
gpu->deviceId = (size_t) deviceID;
8385
gpu->frequency = FF_GPU_FREQUENCY_UNSET;
86+
gpu->coreUtilizationRate = FF_GPU_CORE_UTILIZATION_RATE_UNSET;
8487

8588
if (data->ffclGetDeviceInfo(deviceID, CL_DEVICE_VERSION, sizeof(buffer), buffer, NULL) == CL_SUCCESS)
8689
{

src/detection/vulkan/vulkan.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ static const char* detectVulkan(FFVulkanResult* result)
220220
gpu->type = physicalDeviceProperties.properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED;
221221
ffStrbufInitS(&gpu->vendor, ffGetGPUVendorString(physicalDeviceProperties.properties.vendorID));
222222
ffStrbufInitS(&gpu->driver, driverProperties.driverInfo);
223+
ffStrbufInit(&gpu->uuid);
223224

224225
VkPhysicalDeviceMemoryProperties memoryProperties = {};
225226
ffvkGetPhysicalDeviceMemoryProperties(physicalDevices[i], &memoryProperties);
@@ -234,6 +235,7 @@ static const char* detectVulkan(FFVulkanResult* result)
234235
}
235236

236237
//No way to detect those using vulkan
238+
gpu->index = FF_GPU_INDEX_UNSET;
237239
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
238240
gpu->temperature = FF_GPU_TEMP_UNSET;
239241
gpu->frequency = FF_GPU_FREQUENCY_UNSET;

src/modules/gpu/gpu.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,13 @@ void ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_
329329
{
330330
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
331331

332+
if (gpu->index != FF_GPU_INDEX_UNSET){
332333
yyjson_mut_obj_add_uint8(doc, obj, "index", gpu->index);
334+
}
335+
else
336+
{
337+
yyjson_mut_obj_add_null(doc, obj, "index");
338+
}
333339

334340
yyjson_mut_obj_add_strbuf(doc, obj, "uuid", &gpu->uuid);
335341

@@ -398,6 +404,7 @@ void ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_
398404
ffStrbufDestroy(&gpu->name);
399405
ffStrbufDestroy(&gpu->driver);
400406
ffStrbufDestroy(&gpu->platformApi);
407+
ffStrbufDestroy(&gpu->uuid);
401408
}
402409
}
403410

0 commit comments

Comments
 (0)