简体   繁体   English

启动 CUDA-Kernel 超时

[英]Launch CUDA-Kernel with a timeout

I'm trying to launch a CUDA-kernel with a specific timeout.我正在尝试启动具有特定超时的 CUDA 内核。 I know there is a device timeout for CUDA-kernels, but as I am working on a shared server I have no access to set this timeout, even if it was possible.我知道 CUDA 内核存在设备超时,但是当我在共享服务器上工作时,即使有可能,我也无权设置此超时。

I need this for an auto tuning application.我需要这个用于自动调整应用程序。 I'd like to set a timeout to cancel kernel runs that are not going to be faster than the already found fastest runtime.我想设置一个超时来取消不会比已经找到的最快运行时更快的内核运行。

Is there any way to launch a CUDA kernel with a timeout like that?有什么办法可以像这样超时启动 CUDA 内核? Thanks in advance!提前致谢!

Thanks to the link posted by tera I was able to implement a timeout myself.感谢tera发布的链接,我能够自己实现超时。 As stated in that thread it can be done as follows:正如该线程中所述,可以按如下方式完成:

const int timeout = 2000000;
int progressed = 0;
while (cudaEventQuery(stop) != cudaSuccess) {
    usleep(20000);
    progressed += 20000;
    if (progressed >= timeout) {
        cudaDeviceReset();

        throw std::runtime_error("timeout");
    }
}
// No timeout occured

In this case stop is the event recorded after kernel execution.在这种情况下,停止是内核执行后记录的事件。

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

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