From patchwork Wed Jan 17 07:36:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 45625 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c58a:b0:199:de12:6fa6 with SMTP id gn10csp190812pzb; Tue, 16 Jan 2024 23:36:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IGB6K3sYZ1NnX7cS+cu5so2yFozgk5Wxr6Wsi9UBGGp91bjObeQIOY3aChfH6W9XUmISDt5 X-Received: by 2002:a05:6402:17cd:b0:559:d1a6:38b8 with SMTP id s13-20020a05640217cd00b00559d1a638b8mr340438edy.19.1705477019689; Tue, 16 Jan 2024 23:36:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705477019; cv=none; d=google.com; s=arc-20160816; b=aEmK0sD28AUknzqEhy/T0SHm1AItA5rZBLDjb493zo0njMXIKg5qaQCj/f0kq+xnKt grUXkxkPhcu1URQiSqVQznDZyu4BZzWN+SvxvBY04lijM1mAKYyS8t/NAbWL3i3ThNPh kdFqxORk31lT92UozRw/jFELEzYPfv1BXG4khDBr7napvZui2SuxVoeZjjrwou+Sh7Jr gthlpSnTngz0GpGf4JXqiYV+ei3/pIL7rStgAHNav7vqu69/hpubDwfn/Ou6EhzJbDwh Kz23VfQ8Of478CgL6nZSCoKfpwSs+RfFwGjbIyb2gI1fqkgqVPk5SBSN2Uxm9CMV3fWi Tslg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=bcr6BRjbg6FSD65915rufaQgZb+hyvy8LlroWPdBe5o=; fh=1kpmTRI1sW42eNCnNMby7VLIISQBX6KJuVYxOEG0t2A=; b=nwZ5zguG8q5nAQEcGDw7G8StQBWgBc/d/R73Otcs3n/Ty91iqd+IeHGb1QqB0UNxWc H7GSprqYIfOAGVz/bfiC1WNkON8E8QFudEFl4BhBeOMdOfypWORsVyOyvw3Kum+1YO+5 W08KOgSa6KQbyxtsIC33uf0wZAVwDH7yIbAz0zw829D5bW+CzvdfdXNZ8VIihmyPlDKo U+tXvvfvDwvfiE+8sCVO4NSLlwNlD/wDeJYcU0fwyzwU9xIbL9z0iJtijUTZi/MqYvtv JVFaxoY311ZJISwYGWfC+MwUbCrPaNXGZncoSu4Nd7ADaJCz/W6Jxu1dbYykX6H0516C eyOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b="nnCIfgs/"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id u21-20020a50a415000000b00559b89b2fe5si1084439edb.564.2024.01.16.23.36.59; Tue, 16 Jan 2024 23:36:59 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b="nnCIfgs/"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1A1EB68D01F; Wed, 17 Jan 2024 09:36:56 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1A5BB68CEC1 for ; Wed, 17 Jan 2024 09:36:48 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705477014; x=1737013014; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Ypi313fOyiec6z/HXL1xV399zgPR4asWoRfFA5AFUFk=; b=nnCIfgs/VnteWhP18kE1OH+sBjOwmPAMFgIK83aciz33CjJvgFErh2rc sMVVT9GGJpWnvaWxEG0bIXUfKMDM0tmLwsm6CREnZgByDBgUn1zY9NUQr rmdYZWe1to0gjRkotoZRGfYMmAblAJarJ407CDvWua/xFO7DD54wupnHe 5+Y1Ktk6ic3HuSp5iUqy25n6m2eWP1gjhABjxNvD5sm42zWXcaqnGUs87 FyVcownTjuyH88Pd/chmcxtEZyNUsL69m2o5/NnxGrK1NQOzpHVVcsEi5 QuE255NkWJRXQ73UWYGVg5RDrNpWNSj+nprPC2oieA4hsODiQWVetKU9l A==; X-IronPort-AV: E=McAfee;i="6600,9927,10955"; a="397255090" X-IronPort-AV: E=Sophos;i="6.05,200,1701158400"; d="scan'208";a="397255090" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 23:36:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10955"; a="927757903" X-IronPort-AV: E=Sophos;i="6.05,200,1701158400"; d="scan'208";a="927757903" Received: from xhh-dg264.sh.intel.com ([10.238.2.76]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 23:36:45 -0800 From: "Xiang, Haihao" To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 Jan 2024 15:36:37 +0800 Message-Id: <20240117073637.1352890-1-haihao.xiang@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] hwcontext_opencl: choose the first device if multiple devices are available X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Haihao Xiang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ASoJitCvJYsg From: Haihao Xiang This makes '-init_hw_device opencl' work in a multiple-device system. Signed-off-by: Haihao Xiang --- 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) {