Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cudagraph mem #112

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 20 additions & 23 deletions tritonbench/utils/triton_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -1265,31 +1265,28 @@ def _init_extra_metrics() -> Dict[str, Any]:
def do_bench_cudagraph_mem(
self, fn, n_repeat=2, grad_to_none=None, device_type="cuda"
):
if torch.cuda.current_stream() == torch.cuda.default_stream():
raise RuntimeError(
"Cannot capture graph in default stream. Please use side stream in benchmark code."
)
# warmup
fn()
if grad_to_none is not None:
for x in grad_to_none:
x.detach_()
x.requires_grad_(True)
x.grad = None
g = torch.cuda.CUDAGraph()
with torch.cuda.graph(g):
with torch.cuda.stream(torch.cuda.Stream()):
# warmup
fn()
torch.cuda.synchronize()
g.replay()
torch.cuda.synchronize()
g = torch.cuda.CUDAGraph()
with torch.cuda.graph(g):
for _ in range(n_repeat):
if grad_to_none is not None:
for x in grad_to_none:
x.grad = None
if grad_to_none is not None:
for x in grad_to_none:
x.detach_()
x.requires_grad_(True)
x.grad = None
g = torch.cuda.CUDAGraph()
with torch.cuda.graph(g):
fn()
torch.cuda.synchronize()
torch.cuda.synchronize()
g.replay()
torch.cuda.synchronize()
g = torch.cuda.CUDAGraph()
with torch.cuda.graph(g):
for _ in range(n_repeat):
if grad_to_none is not None:
for x in grad_to_none:
x.grad = None
fn()
torch.cuda.synchronize()

def do_bench_mem(self, fn, n_repeat=2, grad_to_none=None, device_type="cuda"):
di = torch._dynamo.device_interface.get_interface_for_device(device_type)
Expand Down
Loading