mirror of
https://github.com/NVIDIA/nvbench.git
synced 2026-04-19 22:38:52 +00:00
Expand examples/cpu_only.py
Benchmark function that sleeps for 1 seconda on the host using CPU-only timer, as well as CPU/GPU timer that does/doesn't use blocking kernel. All three methods must report consistent values close to 1 second.
This commit is contained in:
@@ -4,15 +4,31 @@ import time
|
||||
import cuda.nvbench as nvbench
|
||||
|
||||
|
||||
def throughput_bench(state: nvbench.State) -> None:
|
||||
def sleep_bench(state: nvbench.State) -> None:
|
||||
def launcher(launch: nvbench.Launch):
|
||||
time.sleep(1)
|
||||
|
||||
state.exec(launcher)
|
||||
|
||||
|
||||
def sleep_bench_sync(state: nvbench.State) -> None:
|
||||
sync = state.get_string("Sync")
|
||||
sync_flag = sync == "Do sync"
|
||||
|
||||
def launcher(launch: nvbench.Launch):
|
||||
time.sleep(1)
|
||||
|
||||
state.exec(launcher, sync=sync_flag)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
b = nvbench.register(throughput_bench)
|
||||
# time function sleeping on the host
|
||||
# using CPU timer only
|
||||
b = nvbench.register(sleep_bench)
|
||||
b.set_is_cpu_only(True)
|
||||
|
||||
# time the same function using both CPU/GPU timers
|
||||
b2 = nvbench.register(sleep_bench_sync)
|
||||
b2.add_string_axis("Sync", ["Do not sync", "Do sync"])
|
||||
|
||||
nvbench.run_all_benchmarks(sys.argv)
|
||||
|
||||
Reference in New Issue
Block a user