Richard Schulze
Richard Schulze

Reputation: 113

Launch CUDA-Kernel with a timeout

I'm trying to launch a CUDA-kernel with a specific timeout. 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.

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? Thanks in advance!

Upvotes: 2

Views: 1379

Answers (1)

Richard Schulze
Richard Schulze

Reputation: 113

Thanks to the link posted by tera I was able to implement a timeout myself. 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.

Upvotes: 2

Related Questions