Skip to content

Fix memory consumption by PyTorch in dlpack zero-copy perf test. #5891

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

Merged
merged 2 commits into from
Apr 24, 2025
Merged
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
17 changes: 8 additions & 9 deletions dali/test/python/dlpack/test_torch_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@ def test_pipe():
return ext + row + col


stream = torch.cuda.Stream(0)


def bench_dlpack(verbose=False):
if verbose:
print("Testing dlpack")
pipe = test_pipe(exec_dynamic=True)
pipe.run()

s = torch.cuda.Stream(0)
with torch.cuda.stream(s):
with torch.cuda.stream(stream):
sum = torch.zeros((), dtype=torch.float32).cuda()
sum -= 318
start = time.time_ns()
for i in range(10):
(out,) = pipe.run(s)
(out,) = pipe.run(stream)
batch = [torch.from_dlpack(t) for t in out]
sum += torch.mean(torch.stack(batch))
batch_tensor = torch.stack(batch)
sum += torch.mean(batch_tensor)
sum_cpu = sum.cpu()
assert sum_cpu == 2137, sum_cpu
end = time.time_ns()
Expand Down Expand Up @@ -56,8 +59,7 @@ def to_torch(dali_tensor):
dali_pyt.feed_ndarray(dali_tensor, t, stream)
return t

s = torch.cuda.Stream(0)
with torch.cuda.stream(s):
with torch.cuda.stream(stream):
sum = torch.zeros((), dtype=torch.float32).cuda()
sum -= 318
start = time.time_ns()
Expand All @@ -71,9 +73,6 @@ def to_torch(dali_tensor):
if verbose:
print((end - start) * 1e-6)
pipe._shutdown()
del pipe
del sum
del sum_cpu
return (end - start) * 1e-6


Expand Down
Loading