2

I want to stop the Gpu kernel for a certain amount of time, but the only function I found was assert().

I want to use timer or events to control the amount of time the gpu is going to be halted, but I don't know how!

Thanks.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
Zeinab
  • 35
  • 1
  • 9
  • `assert()` almost certainly doesn't do what you want. For just about all languages and libraries that have it, it (1) is used solely for sanity checks, (2) tries to kill the process if the check failed, and (3) is often disabled for performance reasons. I don't know Cuda, but if `assert()` there does something different, then it's very, very stupidly named. – cHao Dec 03 '12 at 16:15
  • (As a side note, generally if you want to stop for "a certain amount of time", you're doing something wrong. That's how race conditions happen. You're generally waiting for something to happen (or to finish); wait on that instead. Check out `cudaStreamWaitEvent` and `cudaStreamSynchronize`. Both look promising.) – cHao Dec 03 '12 at 16:30
  • Just agreeing with @cHao [assert in kernel code will not do what you want](http://stackoverflow.com/questions/5114449/cuda-how-to-assert-in-kernel-code) and using it to halt and then resume (anything) is a strange idea. If you want to exit a kernel, all threads must exit. The only suggestion I can offer is to cause your kernel to exit/finish, then wait for however long you want to on the host side, then launch another kernel. The cudaStream... functions will also not halt or suspend a running kernel. Why do you need to halt a kernel? – Robert Crovella Dec 03 '12 at 16:41

1 Answers1

1

You can use clock() or clock64() to generate busy cycles, see the answers here: Equivalent of usleep() in CUDA kernel?

Community
  • 1
  • 1
Adam27X
  • 889
  • 1
  • 7
  • 16
  • 1
    clock(), clock64(), or the PTX special registers %clock, %clock64, %globaltimer can be used to implement a polling wait. This is not the same as idling or halting the GPU. – Greg Smith Dec 03 '12 at 21:09
  • From the OP it isn't entirely clear if he wants a busy wait or a complete stop, so I'll let him be the one to judge. – Adam27X Dec 03 '12 at 22:03
  • yeah, actually assert is used in cuda, but using clock helps me control the amount of time I want. Thanks guys;) – Zeinab Dec 06 '12 at 20:37