Skip to content

Commit c377872

Browse files
committed
GPU (Linux): correctly call radeon driver
1 parent 4f42d38 commit c377872

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

src/detection/gpu/gpu_drm.c

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,43 @@ const char* ffDrmDetectRadeon(const FFGPUOptions* options, FFGPUResult* gpu, con
1919
FF_AUTO_CLOSE_FD int fd = open(renderPath, O_RDONLY);
2020
if (fd < 0) return "Failed to open DRM render device";
2121

22-
struct drm_radeon_info info;
23-
info.request = RADEON_INFO_ACTIVE_CU_COUNT;
24-
if (ioctl(fd, DRM_IOCTL_RADEON_INFO, &info) >= 0)
25-
gpu->coreCount = (int32_t) info.value;
22+
uint32_t value;
23+
24+
// https://github.com/torvalds/linux/blob/fb4d33ab452ea254e2c319bac5703d1b56d895bf/drivers/gpu/drm/radeon/radeon_kms.c#L231
25+
26+
if (ioctl(fd, DRM_IOCTL_RADEON_INFO, &(struct drm_radeon_info) {
27+
.request = RADEON_INFO_ACTIVE_CU_COUNT,
28+
.value = (uintptr_t) &value,
29+
}) >= 0)
30+
gpu->coreCount = (int32_t) value;
2631

2732
if (options->temp)
2833
{
29-
info.request = RADEON_INFO_CURRENT_GPU_TEMP; // millidegrees C
30-
if (ioctl(fd, DRM_IOCTL_RADEON_INFO, &info) >= 0)
31-
gpu->temperature = (double) info.value / 1000.0;
34+
if (ioctl(fd, DRM_IOCTL_RADEON_INFO, &(struct drm_radeon_info) {
35+
.request = RADEON_INFO_CURRENT_GPU_TEMP, // millidegrees C
36+
.value = (uintptr_t) &value,
37+
}) >= 0 && value != 0) // 0 means unavailable
38+
gpu->temperature = (double) value / 1000.0;
3239
}
3340

34-
info.request = RADEON_INFO_MAX_SCLK; // MHz
35-
if (ioctl(fd, DRM_IOCTL_RADEON_INFO, &info) >= 0)
36-
gpu->frequency = (uint32_t) (info.value / 1000u);
41+
if (ioctl(fd, DRM_IOCTL_RADEON_INFO, &(struct drm_radeon_info) {
42+
.request = RADEON_INFO_MAX_SCLK, // MHz
43+
.value = (uintptr_t) &value,
44+
}) >= 0)
45+
gpu->frequency = (uint32_t) (value / 1000u);
3746

38-
struct drm_radeon_gem_info gemInfo;
39-
if (ioctl(fd, DRM_IOCTL_RADEON_GEM_INFO, &gemInfo) >= 0 && gemInfo.vram_visible > 0)
47+
if (options->driverSpecific)
4048
{
41-
gpu->type = FF_GPU_TYPE_DISCRETE;
42-
if (options->driverSpecific)
49+
struct drm_radeon_gem_info gemInfo;
50+
if (ioctl(fd, DRM_IOCTL_RADEON_GEM_INFO, &gemInfo) >= 0 && gemInfo.vram_visible > 0)
4351
{
4452
gpu->dedicated.total = gemInfo.vram_visible;
45-
info.request = RADEON_INFO_VRAM_USAGE;
46-
if (ioctl(fd, DRM_IOCTL_RADEON_INFO, &info) >= 0)
47-
gpu->dedicated.used = info.value;
53+
uint64_t memSize;
54+
if (ioctl(fd, DRM_IOCTL_RADEON_INFO, &(struct drm_radeon_info) {
55+
.request = RADEON_INFO_VRAM_USAGE, // uint64_t
56+
.value = (uintptr_t) &memSize,
57+
}) >= 0)
58+
gpu->dedicated.used = memSize;
4859
}
4960
}
5061

0 commit comments

Comments
 (0)