Skip to content

Commit d020fac

Browse files
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.
1 parent f861c4a commit d020fac

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

python/examples/cpu_only.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,31 @@
44
import cuda.nvbench as nvbench
55

66

7-
def throughput_bench(state: nvbench.State) -> None:
7+
def sleep_bench(state: nvbench.State) -> None:
88
def launcher(launch: nvbench.Launch):
99
time.sleep(1)
1010

1111
state.exec(launcher)
1212

1313

14+
def sleep_bench_sync(state: nvbench.State) -> None:
15+
sync = state.get_string("Sync")
16+
sync_flag = sync == "Do sync"
17+
18+
def launcher(launch: nvbench.Launch):
19+
time.sleep(1)
20+
21+
state.exec(launcher, sync=sync_flag)
22+
23+
1424
if __name__ == "__main__":
15-
b = nvbench.register(throughput_bench)
25+
# time function sleeping on the host
26+
# using CPU timer only
27+
b = nvbench.register(sleep_bench)
1628
b.set_is_cpu_only(True)
1729

30+
# time the same function using both CPU/GPU timers
31+
b2 = nvbench.register(sleep_bench_sync)
32+
b2.add_string_axis("Sync", ["Do not sync", "Do sync"])
33+
1834
nvbench.run_all_benchmarks(sys.argv)

0 commit comments

Comments
 (0)