Search code examples
pythoncudagpupycuda

PyCUDA kernel timing errors


Simple enough

start=cuda.Event()
func(args,block=blockdims)
cuda.memcpy_dtoh(d,h)
end=cuda.Event()

dur=start.time_till(end)
print dur

But I'm getting this error

File "gpu.py", line 161, in gpu_test
    dur=start.time_till(end)
pycuda._driver.LogicError: cuEventElapsedTime failed: invalid handle

This is as far as I can tell from the docs the correct usage. Anyone got any idea what I'm doing wrong?


Solution

  • Take a look at SimpleSpeedTest.py:

    start=cuda.Event()
    end=cuda.Event()
    
    start.record() # start timing
    func(args,block=blockdims)
    cuda.memcpy_dtoh(d,h)
    end.record() # end timing
    # calculate the run length
    end.synchronize()
    millis = start.time_till(end)
    print millis