Message ID | 20240117073637.1352890-1-haihao.xiang@intel.com |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel] hwcontext_opencl: choose the first device if multiple devices are available | expand |
Context | Check | Description |
---|---|---|
yinshiyou/make_loongarch64 | success | Make finished |
yinshiyou/make_fate_loongarch64 | success | Make fate finished |
andriy/make_x86 | success | Make finished |
andriy/make_fate_x86 | success | Make fate finished |
On 17/01/2024 07:36, Xiang, Haihao wrote: > From: Haihao Xiang <haihao.xiang@intel.com> > > This makes '-init_hw_device opencl' work in a multiple-device system. Under what circumstances is this more useful than the existing behaviour which prompts the user to select the device they intend? There is no particular ordering to devices, the first one is just random. Having your process fail with an opaque message (because the device picked lacks some operation) or run many times slower than expected (because the smallest device happened to be first in the list) or do something different on a machine which looks the same (because it has an extra driver for something else) rather than just saying up front that there are multiple devices and the user needs to pick seems worse to me, since it is much harder to see where the problem is. Thanks, - Mark
On Ma, 2024-01-22 at 20:32 +0000, Mark Thompson wrote: > On 17/01/2024 07:36, Xiang, Haihao wrote: > > From: Haihao Xiang <haihao.xiang@intel.com> > > > > This makes '-init_hw_device opencl' work in a multiple-device system. > > Under what circumstances is this more useful than the existing behaviour which > prompts the user to select the device they intend? @item -init_hw_device @var{type}[=@var{name}][:@var{device}[,@var{key=value}...]] My understanding is that only @var{type} is mandatory, @var{device} (and others) is optional, indeed '-init_hw_device opencl' works well in a single-device system, however the same command doesn't work in a multiple-device system. It is not a good experience for me. > > There is no particular ordering to devices, the first one is just random. > Having your process fail with an opaque message (because the device picked > lacks some operation) or run many times slower than expected (because the > smallest device happened to be first in the list) or do something different on > a machine which looks the same (because it has an extra driver for something > else) rather than just saying up front that there are multiple devices and the > user needs to pick seems worse to me, since it is much harder to see where the > problem is. I understand your concern, how about making the default works while prompting a warning about the device selection ? Thanks Haihao
On Di, 2024-01-23 at 02:52 +0000, Xiang, Haihao wrote: > On Ma, 2024-01-22 at 20:32 +0000, Mark Thompson wrote: > > On 17/01/2024 07:36, Xiang, Haihao wrote: > > > From: Haihao Xiang <haihao.xiang@intel.com> > > > > > > This makes '-init_hw_device opencl' work in a multiple-device system. > > > > Under what circumstances is this more useful than the existing behaviour > > which > > prompts the user to select the device they intend? > > @item -init_hw_device > @var{type}[=@var{name}][:@var{device}[,@var{key=value}...]] > > My understanding is that only @var{type} is mandatory, @var{device} (and > others) > is optional, indeed '-init_hw_device opencl' works well in a single-device > system, however the same command doesn't work in a multiple-device system. It > is > not a good experience for me. > > > > > There is no particular ordering to devices, the first one is just random. > > Having your process fail with an opaque message (because the device picked > > lacks some operation) or run many times slower than expected (because the > > smallest device happened to be first in the list) or do something different > > on > > a machine which looks the same (because it has an extra driver for something > > else) rather than just saying up front that there are multiple devices and > > the > > user needs to pick seems worse to me, since it is much harder to see where > > the > > problem is. > > I understand your concern, how about making the default works while prompting > a > warning about the device selection ? Hi Mark, Do you have more comments ? Thanks Haihao
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) {