Skip to content

Commit 68241fe

Browse files
author
Vincent Moens
committed
amend
1 parent ac5b5e4 commit 68241fe

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

intermediate_source/pinmem_nonblock.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -500,13 +500,18 @@ def pin_copy_to_device_nonblocking(*tensors):
500500
from torch.utils.benchmark import Timer
501501

502502
# Create the dataset
503-
td = TensorDict({str(i): torch.randn(1_000_000) for i in range(100)})
504-
505-
# Runtimes
506-
copy_blocking = timer("td.to('cuda:0', non_blocking=False)")
507-
copy_non_blocking = timer("td.to('cuda:0')")
508-
copy_pin_nb = timer("td.to('cuda:0', non_blocking_pin=True, num_threads=0)")
509-
copy_pin_multithread_nb = timer("td.to('cuda:0', non_blocking_pin=True, num_threads=4)")
503+
for s0 in (10, 100, 1000, 10_000, 100_000, 1_000_000):
504+
for s1 in (10, 100, 1000, 10_000):
505+
if s0 * s1 >= 1e9:
506+
continue
507+
print(f"\n\ns0={s0}, s1={s1}")
508+
td = TensorDict({str(i): torch.randn(1_000_000) for i in range(100)})
509+
510+
# Runtimes
511+
copy_blocking = timer("td.to('cuda:0', non_blocking=False)")
512+
copy_non_blocking = timer("td.to('cuda:0')")
513+
copy_pin_nb = timer("td.to('cuda:0', non_blocking_pin=True, num_threads=0)")
514+
copy_pin_multithread_nb = timer("td.to('cuda:0', non_blocking_pin=True, num_threads=4)")
510515

511516
# Rations
512517
r1 = copy_non_blocking / copy_blocking

0 commit comments

Comments
 (0)