MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / gpu_timer

Function gpu_timer

python/1_GettingStarted/numpyVsCupy/numpyVsCupy.py:58–68  ·  view source on GitHub ↗

GPU timing context manager using cuda.core CUDA events.

(message, stream)

Source from the content-addressed store, hash-verified

56
57@contextlib.contextmanager
58def gpu_timer(message, stream):
59 """GPU timing context manager using cuda.core CUDA events."""
60 event_options = EventOptions(timing_enabled=True)
61 start_event = stream.record(options=event_options)
62 yield
63 end_event = stream.record(options=event_options)
64 end_event.sync()
65
66 elapsed_time_ms = end_event - start_event # Returns milliseconds
67 elapsed_time_s = elapsed_time_ms / 1000.0 # Convert to seconds
68 print(f"{message}: {elapsed_time_s:.6f} seconds")
69
70
71def warmup():

Callers 1

runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected