简体   繁体   English

如何在不同设备上生成并行线程?

[英]How do I spawn parallel threads on different devices?

I want to run some threads on my CPU ( the localhost host ) and some other on a portable device connected ( like a USB ). 我想在我的CPU( localhost主机)上运行一些线程,并在连接的便携式设备(如USB)上运行其他线程。

I know that OpenCL supports parallelization, but how do I distribute a work onto a portable devices using OpenCL? 我知道OpenCL支持并行化,但是如何使用OpenCL将作品分发到便携式设备上?

Any other idea to do this other than OpenCL would also help. 除了OpenCL之外,任何其他执行此操作的想法也将有所帮助。

Any device which might run an OpenCL task must have an Installable Client Driver associated with it, which can be picked up by the OpenCL Driver on the computer in question. 任何可能运行OpenCL任务的设备都必须具有与其相关联的可安装客户端驱动程序,可以由有问题的计算机上的OpenCL驱动程序将其拾取。 Graphics Cards (especially if they're no older than half a decade) are nearly guaranteed to have a valid ICD, provided their drivers are up-to-date, and many Consumer-level CPUs have ICDs that are provided by their drivers. 只要显卡驱动程序是最新的,并且许多消费级CPU都具有由其驱动程序提供的ICD,则几乎可以保证图形卡(尤其是不超过五年的显卡)具有有效的ICD。

However, other devices like a Network Device or a USB device are considerably less guaranteed to have a valid ICD unless they've been specifically designed for use in a Heterogeneous Compute system. 但是,除非为网络计算设备或USB设备等其他设备专门设计用于异构计算系统,否则它们的保证将大大降低。 If they do have a valid ICD , then it's a mere matter of querying for their platform at runtime and choosing it to use when constructing your OpenCL Context, then using it the same way you'd use OpenCL normally: 如果他们确实拥有有效的ICD ,那么只需在运行时查询其平台并选择在构建OpenCL Context时要使用的平台,然后以与通常使用OpenCL相同的方式使用它即可:

//C++ OpenCL API
cl::Platform target_platform;
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
for(cl::Platform & platform : platforms) {
    std::string name = platform.getInfo<CL_PLATFORM_NAME>();
    if(name == /*Whatever the Name of the platform is*/) {
        target_platform = platform;
        break;
    }
}
std::vector<cl::Device> devices;
target_platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);
cl::Device target_device;
for(cl::Device & device : devices) {
    if(device.getInfo</*...*/>() == /*...*/) {//Whatever properties you need
        target_device = device;
        break;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM