Skip to content

Instantly share code, notes, and snippets.

@vmoens
Created January 24, 2025 13:44
Show Gist options
  • Select an option

  • Save vmoens/2a681e2615e4e7e30c214a7b53996a9a to your computer and use it in GitHub Desktop.

Select an option

Save vmoens/2a681e2615e4e7e30c214a7b53996a9a to your computer and use it in GitHub Desktop.
import time
import torch
DELAY = 100000000
with torch.profiler.profile(
activities=[torch.profiler.ProfilerActivity.CPU, torch.profiler.ProfilerActivity.CUDA],
record_shapes=True,
profile_memory=True,
#with_stack=True
) as p:
x = torch.ones((1024, 1024),)# pin_memory=True)
torch.cuda.synchronize()
start = time.time()
torch.cuda._sleep(DELAY)
y1 = x.cuda(non_blocking=True)
x.zero_()
end = time.time()
print("not corrupted:", (y1 == 1).all().item())
p.export_chrome_trace("profiling_results_pageable.json")
with torch.profiler.profile(
activities=[torch.profiler.ProfilerActivity.CPU, torch.profiler.ProfilerActivity.CUDA],
record_shapes=True,
profile_memory=True,
#with_stack=True
) as p:
x = torch.ones((1024, 1024), pin_memory=True)
torch.cuda.synchronize()
start = time.time()
torch.cuda._sleep(DELAY)
y1 = x.cuda(non_blocking=True)
x.zero_()
end = time.time()
print("not corrupted:", (y1 == 1).all().item())
p.export_chrome_trace("profiling_results_pin.json")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment