Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] hwcontext_opencl: choose the first device if multiple devices are available
@ 2024-01-17  7:36 Xiang, Haihao
  2024-01-22 20:32 ` Mark Thompson
  0 siblings, 1 reply; 4+ messages in thread
From: Xiang, Haihao @ 2024-01-17  7:36 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Haihao Xiang

From: Haihao Xiang <haihao.xiang@intel.com>

This makes '-init_hw_device opencl' work in a multiple-device system.

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
 doc/ffmpeg.texi              | 5 +++++
 libavutil/hwcontext_opencl.c | 9 ++++-----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 7246a46d2f..edda0d5d9b 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1424,6 +1424,8 @@ Choose the GPU subdevice with type @samp{dxva2} and create QSV device with @samp
 The set of devices can also be filtered using the key-value pairs to find only
 devices matching particular platform or device strings.
 
+If more than one matching device found, choose the first one from the set of devices.
+
 The strings usable as filters are:
 @table @option
 @item platform_profile
@@ -1444,6 +1446,9 @@ The indices and filters must together uniquely select a device.
 
 Examples:
 @table @emph
+@item -init_hw_device opencl
+Choose the first device on the first platform.
+
 @item -init_hw_device opencl:0.1
 Choose the second device on the first platform.
 
diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
index 247834aaf6..98e35919bf 100644
--- a/libavutil/hwcontext_opencl.c
+++ b/libavutil/hwcontext_opencl.c
@@ -515,7 +515,7 @@ static int opencl_device_create_internal(AVHWDeviceContext *hwdev,
         return err;
 
     found = 0;
-    for (p = 0; p < nb_platforms; p++) {
+    for (p = nb_platforms - 1; p >= 0; p--) {
         const char *platform_name;
 
         if (selector->platform_index >= 0 &&
@@ -546,7 +546,7 @@ static int opencl_device_create_internal(AVHWDeviceContext *hwdev,
         if (err < 0)
             continue;
 
-        for (d = 0; d < nb_devices; d++) {
+        for (d = nb_devices - 1; d >= 0; d--) {
             const char *device_name;
 
             if (selector->device_index >= 0 &&
@@ -588,9 +588,8 @@ static int opencl_device_create_internal(AVHWDeviceContext *hwdev,
         goto fail;
     }
     if (found > 1) {
-        av_log(hwdev, AV_LOG_ERROR, "More than one matching device found.\n");
-        err = AVERROR(ENODEV);
-        goto fail;
+        av_log(hwdev, AV_LOG_VERBOSE,
+               "More than one matching device found, choose the first device.\n");
     }
 
     if (!props) {
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-01-30  6:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-17  7:36 [FFmpeg-devel] [PATCH] hwcontext_opencl: choose the first device if multiple devices are available Xiang, Haihao
2024-01-22 20:32 ` Mark Thompson
2024-01-23  2:52   ` Xiang, Haihao
2024-01-30  6:32     ` Xiang, Haihao

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git