7

According to the CUDA programming guide, you can disable asynchronous kernel launches at run time by setting an environment variable (CUDA_LAUNCH_BLOCKING=1).

This is a helpful tool for debugging. I also want to determine the benefit in my code from using concurrent kernels and transfers.

I want to also disable other concurrent calls, in particular cudaMemcpyAsync.

Does CUDA_LAUNCH_BLOCKING affect these kinds of calls in addition to kernel launches? I suspect not. What would be the best alternative? I can add cudaStreamSynchronize calls, but I would prefer a run time solution. I can run in the debugger, but that will affect the timing and defeat the purpose.

2
  • 1
    Running in the debugger will affect the timing, but serialising everything won't?!
    – Tom
    Jan 22, 2011 at 18:20
  • Of course serialising everything will affect timing, and that's what I want to know.
    – jmilloy
    Jan 22, 2011 at 22:55

1 Answer 1

1

Setting CUDA_LAUNCH_BLOCKING won't effect the streams API at all. If you add some debug code to force all your streams code to use stream 0, all the calls other than kernel calls will revert to synchronous behaviour.

7
  • I am interested not only in synchronous kernel execution, but also achieving NO concurrency between gpu and cpu. I think using cudaMemcpyAsync on stream 0 is sufficient for the first goal, but not the latter one.
    – jmilloy
    Apr 6, 2011 at 17:37
  • @jmilloy: CUDA_LAUNCH_BLOCKING with for all kernel launches to be synchronous to the host, and redirecting the streams API to stream 0 will stop any other asynchronous API operations to be synchronous as well. If you do both of those things, every CUDA operation should be blokcing/serialised. Isn't that what you are trying to achieve?
    – talonmies
    Apr 6, 2011 at 19:47
  • @talonmies: The cuda docs say that CUDA_LAUNCH_BLOCKING blocks all kernel launches from launching asynchronously. Is cudaMemcpyAsync a kernel launch? If CUDA_LAUNCH_BLOCKING blocks not only kernel launches but other CUDA operations, then yes, it is what I want. Truthfully, I ought to have just written something up to test it myself!!
    – jmilloy
    Apr 6, 2011 at 19:53
  • @jmilloy: You need both CUDA_LAUNCH_BLOCKING to serialise kernel launches, and using only stream 0 to stop any asynchronous API calls from overlapping with anything. cudaMemcpyAsync is a DMA operation, it doesn't run a kernel (in the sense that the driver API kernel launch calls are not used).
    – talonmies
    Apr 6, 2011 at 20:31
  • @talonmies I don't think using stream 0 stops cudamemcpyAsync from executing asynchronously with the cpu. If stream 0 doesn't block cudaMemcpyAsync, and CUDA_LAUNCH_BLOCKING doesn't block cudaMemcpyAsync, then I will still have asynchronous launches resulting on concurrent gpu and cpu execution.
    – jmilloy
    Apr 6, 2011 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.