I have a CUDA kernel that calls out to a series of device functions.
What is the best way to get the execution time for each of the device functions?
What is the best way to get the execution time for a section of code in one of the device functions?
In my own code, I use the
clock()
function to get precise timings. For convenience, I have the macrosThese can then be used to instrument the device code as follows:
You can then read the
cuda_timers
in the host code.A few notes:
#ifdef USETIMERS
so you can switch them off easily.clock()
returns integer values of typeclock_t
, I store the accumulated values asfloat
, otherwise the values will wrap around for kernels that take longer than a few seconds (accumulated over all blocks).( toc > tic ) ? (toc - tic) : ( toc + (0xffffffff - tic) ) )
is necessary in case the clock counter wraps around.P.S. This is a copy of my reply to this question, which didn't get many points there since the timing required was for the whole kernel.