CUDA: cudaEventElapsedTime returns device not ready error?

It's because cudaEventRecord is asynchronous. It finishes its execution immediately, regardless of the status. Asynchronous functions simply put an order on a "CUDA execution queue".

When GPU finishes its current assignment, it pops the next order and executes it. It is all done in a separate thread, handled by the CUDA driver, separate of your program host thread.

Up vote 3 down vote favorite share g+ share fb share tw.

I tried to measure the elapsed time on Tesla (T10 processors) and cudaEventElapsedTime returns device not ready error. But when I tested it on Fermi (Tesla M2090), it gave me the result. Can anyone tell me what is happening... Here is my code cudaError_t err; cudaEvent_t start, stop; cudaEventCreate(&start); cudaEventCreate(&stop); err = cudaEventRecord(start, 0); f(err!

= cudaSuccess) { printf ("\n\n 1. Error: %s\n\n", cudaGetErrorString(err)); exit(1); } // actual code cudaThreadSynchronize(); err = cudaEventRecord(stop, 0); if(err! = cudaSuccess) { printf ("\n\n2.

Error: %s\n\n", cudaGetErrorString(err)); exit(1); } err = cudaEventElapsedTime(&elapsed_time, start, stop); f(err! = cudaSuccess) { printf ("\n\n 3. Error: %s\n\n", cudaGetErrorString(err)); exit(1); } cuda link|improve this question asked Jul 1 '11 at 17:14veda647419 70% accept rate.

I figured out the solution for this problem but it would be good if someone tells me why it is happening. So I will keep this question open. The solution is cudaThreadSynchronize() should be after cudaEventRecord(stop,0) .

If anyone knows what is the reason and why it didn't happen on fermi, let me know. – veda Jul 1 '11 at 18:57.

It's because cudaEventRecord is asynchronous. It finishes its execution immediately, regardless of the status. Asynchronous functions simply put an order on a "CUDA execution queue".

When GPU finishes its current assignment, it pops the next order and executes it. It is all done in a separate thread, handled by the CUDA driver, separate of your program host thread. CudaEventRecord is an order which says more-or-less something like this: "When you are done all previous work, flag me in this variable".

If your host thread then asks for cudaEventElapsedTime, but the GPU didn't finish its work yet, it gets confused and reports "not ready yet! ". CudaEventSynchronize() stalls the current host thread until the GPU reaches the cureEventRecord order that you placed earlier.

After that you are guaranteed that cudaEventElapsedTime will have a meaningful answer for you. CudaThreadSynchronize() is just a stronger tool: it stalls current thread until GPU finishes all assigned tasks, and not just those until the event.

Thanks. But why Fermi didn't face that problem? I mean the same code ran successfully and gave the results on Fermi architecture.

Why is that so? – veda Jul 6 '11 at 15:30 Don't know. Maybe Fermi was fast enough?

:) – CygnusX1 Jul 6 '11 at 15:40.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions