首页 > 解决方案 > 如何让 SYCL“default_selector”选择 Intel GPU 而不是 NVIDIA GPU?

问题描述

我目前正在使用 SYCL 对图像应用非锐化蒙版的项目。我的机器里面有一个 NVIDIA 和一个 Intel GPU。我从以下代码开始:

default_selector deviceSelector;
queue myQueue(deviceSelector);

问题是代码行“default_selector deviceSelector;” 自动抓取我机器内的 NVIDIA GPU,这会破坏后面的所有代码,因为 SYCL 不适用于 NVIDIA。

因此我的问题是 - 我如何强制“default_selector deviceSelector;” 获取我的 Intel GPU 而不是 NVIDIA GPU?也许我可以这样说:

if (device.has_extension(cl::sycl::string_class("Intel"))) 
   if (device.get_info<info::device::device_type>() == info::device_type::gpu)
       then select this GPU;//pseudo code 

从而使代码跳过NVIDIA GPU并保证选择我的Intel GPU。

标签: gpusycl

解决方案


您正在检查扩展是否包含一个名为“Intel”的条目,但它不会。扩展是设备支持的东西,比如 SPIR-V 你可以通过在命令行调用 clinfo 来查看支持的扩展。要选择英特尔 GPU,您需要检查设备制造商以选择正确的。

所以在自定义设备选择的示例代码中https://github.com/codeplaysoftware/computecpp-sdk/blob/master/samples/custom-device-selector.cpp#L46

你只需要有类似的东西

if (device.get_info<info::device::name>() == "Name of device") {
        return 100;
      }

你可以打印出价值

device.get_info<info::device::name>

获取要检查的值。


推荐阅读