CUDA:停止所有其他线程 [英] CUDA: Stop all other threads

查看:317
本文介绍了CUDA:停止所有其他线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,看起来可解决通过枚举所有可能的解决方案,然后找到最好的。为了做到这一点,我设计了一个回溯算法,枚举和存储最佳解决方案,如果发现。到目前为止它工作正常。

I have a problem that is seemingly solvable by enumerating all possible solutions and then finding the best. In order to do so, I devised a backtracking algorithm that enumerates and stores the best solution if found. It works fine so far.

现在,我想把这个算法移植到CUDA。因此,我创建了一个生成一些不同的基本情况的过程。这些基本情况应该在GPU上并行处理。如果其中一个CUDA线程找到一个最优解,所有其他线程当然可以停止他们的工作。

Now, I wanted to port this algorithm to CUDA. Therefore, I created a procedure that generates some distinct basic cases. These basic cases should be processed in parallel on the GPU. If one of the CUDA-threads finds an optimal solution, all the other threads can - of course - stop their work.

所以,我想要的类型如下:找到最佳解决方案的线程应停止全部运行我的程序的CUDA线程,从而完成计算。

So, I wanted kind of the following: The thread that finds the optimal solution should stop all running CUDA-threads of my program, thus finishing calculation.

线程只能在同一个块中进行通信。 (所以我想不可能停止其他阻塞线程。)

After some quick search, I found that threads can only communicate if they are in the same block. (So I suppose it's impossible to stop others blocks threads.)

我可以想到的唯一的方法是我有一个专用的标志 optimum_found ,这是在每个内核的开头检查。如果找到最佳解,此标志设置为 1 ,因此所有未来的线程都知道它们不必工作。但是,当然,线程已经运行不会注意到这个标志,如果他们不检查它在每次迭代。

The only method I could think of is that I have a dedicated flag optimum_found, which is checked at the beginning of every kernel. If an optimum solution is found, this flag is set to 1, so all future threads know that they do not have to work. But of course, threads already running do not notice this flag if they do not check it at every iteration.

所以,有可能停止所有剩余的CUDA线程?

So, is there a possibility to stop all remaining CUDA-threads?

推荐答案

我认为你有一个专用标志的方法可以工作,只要它是一个内存位置在全局内存。这样,你可以检查这一点,正如你所说,在每个内核调用的开始。

I think that your method of having a dedicated flag could work provided that it was a memory location in global memory. That way you can check this, as you said, at the beginning of each kernel call.

内核调用通常应该相对较短,因此让其他线程批处理完成,即使一个最佳解决方案发现其中一个线程不应该影响你的性能太多。

Kernel calls should generally be relatively short anyways, therefore letting the other threads in a batch finish even though an optimal solution was found by one of those threads shouldn't affect your performance too much.

这是说,我相当确定没有CUDA调用这可以杀死其他正在执行的线程。

That said, I am fairly sure there is no CUDA call that can kill off other actively executing threads.

这篇关于CUDA:停止所有其他线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆