Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: "Xiang, Haihao" <haihao.xiang-at-intel.com@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Haihao Xiang <haihao.xiang@intel.com>
Subject: [FFmpeg-devel] [PATCH] hwcontext_opencl: choose the first device if multiple devices are available
Date: Wed, 17 Jan 2024 15:36:37 +0800
Message-ID: <20240117073637.1352890-1-haihao.xiang@intel.com> (raw)

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".

             reply	other threads:[~2024-01-17  7:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-17  7:36 Xiang, Haihao [this message]
2024-01-22 20:32 ` Mark Thompson
2024-01-23  2:52   ` Xiang, Haihao
2024-01-30  6:32     ` Xiang, Haihao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240117073637.1352890-1-haihao.xiang@intel.com \
    --to=haihao.xiang-at-intel.com@ffmpeg.org \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=haihao.xiang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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