[英]How to specify particular GPU Device to be used at the time of running a program in SYCL/DPC++?
I was trying the code with SYCL/DPC++.我正在尝试使用 SYCL/DPC++ 编写代码。 I have two GPUs present on my device.
我的设备上有两个 GPU。 How can I specify that my code needs to run on a particular GPU device?
如何指定我的代码需要在特定 GPU 设备上运行? When I am trying to run my code using "gpu-selector" only one default one is used to run.
当我尝试使用“gpu-selector”运行我的代码时,只使用一个默认值来运行。 How can I use the other GPU device in order to run my code?
如何使用其他 GPU 设备来运行我的代码?
Here is my code.这是我的代码。
#include <iostream>
#include <CL/sycl.hpp>
using namespace sycl;
using namespace std;
int main() {
queue my_gpu( gpu_selector{} );
cout << "My GPU Device: " <<
my_gpu.get_device().get_info<info::device::name>() << "\n";
return 0;
}
Can someone help me out with how can I run my code on a particular GPU device?有人可以帮助我解决如何在特定 GPU 设备上运行我的代码吗?
Thanks in Advance!提前致谢!
Yes, it is possible to select a particular GPU device.是的,可以选择特定的 GPU 设备。 Please find the below code to get the results from a specific GPU device.
请找到以下代码以从特定 GPU 设备获取结果。
class my_selector : public device_selector {
public:
int operator()(const device &dev) const override {
if (
dev.get_info<info::device::name>().find("gpu_vendor_name")
!= std::string::npos &&
dev.get_info<info::device::vendor>().find("gpu_device_name")
!= std::string::npos)
return 1;
}
return -1;
}
};
In this code, we can specify the name of the GPU vendor in ("gpu_vendor_name") as per your requirement.在此代码中,我们可以根据您的要求在 ("gpu_vendor_name") 中指定 GPU 供应商的名称。 If we have two GPU devices with the same vendor then we can also specify the one we want to run code in the GPU device("gpu_device_name").
如果我们有两个具有相同供应商的 GPU 设备,那么我们还可以指定我们想要在 GPU 设备中运行代码的一个(“gpu_device_name”)。
The highest return value will be selected to run the code on the GPU device which we want.将选择最高的返回值在我们想要的 GPU 设备上运行代码。
The answer by Varsha is a good general solution. Varsha的答案是一个很好的通用解决方案。
But since your question is tagged with DPC++, I think it is worth mentioning an alternative approach:但是由于您的问题是用 DPC++ 标记的,我认为值得一提的是另一种方法:
You can set SYCL_DEVICE_FILTER
environment variable to control device detection results.您可以设置
SYCL_DEVICE_FILTER
环境变量来控制设备检测结果。 Eg, SYCL_DEVICE_FILTER=opencl:gpu:1
will make it so only the second GPU in the OpenCL backend is visible by the application.例如,
SYCL_DEVICE_FILTER=opencl:gpu:1
将使应用程序只能看到 OpenCL 后端中的第二个 GPU。 It will even hide the Host device.它甚至会隐藏主机设备。
That is DPC++-specific, and will not work with other implementations.这是特定于 DPC++ 的,不适用于其他实现。 But, for example, with hipSYCL you can use
CUDA_VISIBLE_DEVICES
or HIP_VISIBLE_DEVICES
to achieve similar results.但是,例如,通过 hipSYCL,您可以使用
CUDA_VISIBLE_DEVICES
或HIP_VISIBLE_DEVICES
来实现类似的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.