-
Notifications
You must be signed in to change notification settings - Fork 274
cuda.bindings latency benchmarks - part 3 #1948
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
Open
danielfrg
wants to merge
10
commits into
main
Choose a base branch
from
cuda-bindings-bench-3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9a83e1d
Migrate to /benchmarks directory
danielfrg dcf93f8
Add Memory benchmarks
danielfrg 4097d74
Add memory benchmarks
danielfrg a368a48
Move to top level of the repo
danielfrg 5ecba20
lint
danielfrg e468263
lint
danielfrg ddd3248
lint
danielfrg f2c0838
Recover missing SPDX follow-ups from PR 1913
rwgk efc34e8
Fix benchmarks/cuda_bindings/pytest-legacy license identifiers
rwgk e176817
Move legacy benchmark Ruff suppressions with code move
rwgk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # cuda.bindings benchmarks | ||
|
|
||
| Read the README.md in this directory for more details about the benchmarks. | ||
|
|
||
| When generating code verify that that the code is correct based on the source for cuda-bindings | ||
| that can be found in ../../cuda_bindings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import time | ||
|
|
||
| import numpy as np | ||
| from runner.runtime import alloc_persistent, ensure_context | ||
|
|
||
| from cuda.bindings import driver as cuda | ||
|
|
||
| ensure_context() | ||
|
|
||
| # Allocation size for alloc/free benchmarks | ||
| ALLOC_SIZE = 1024 | ||
|
|
||
| # Small transfer size (8 bytes) to measure call overhead, not bandwidth | ||
| COPY_SIZE = 8 | ||
|
|
||
| # Pre-allocate device memory and host buffers for memcpy benchmarks | ||
| DST_DPTR = alloc_persistent(COPY_SIZE) | ||
| SRC_DPTR = alloc_persistent(COPY_SIZE) | ||
| HOST_SRC = np.zeros(COPY_SIZE, dtype=np.uint8) | ||
| HOST_DST = np.zeros(COPY_SIZE, dtype=np.uint8) | ||
|
|
||
| # Stream for async operations | ||
| _err, STREAM = cuda.cuStreamCreate(cuda.CUstream_flags.CU_STREAM_NON_BLOCKING.value) | ||
|
|
||
|
|
||
| def bench_mem_alloc_free(loops: int) -> float: | ||
| _alloc = cuda.cuMemAlloc | ||
| _free = cuda.cuMemFree | ||
| _size = ALLOC_SIZE | ||
|
|
||
| t0 = time.perf_counter() | ||
| for _ in range(loops): | ||
| _, ptr = _alloc(_size) | ||
| _free(ptr) | ||
| return time.perf_counter() - t0 | ||
|
|
||
|
|
||
| def bench_mem_alloc_async_free_async(loops: int) -> float: | ||
| _alloc = cuda.cuMemAllocAsync | ||
| _free = cuda.cuMemFreeAsync | ||
| _size = ALLOC_SIZE | ||
| _stream = STREAM | ||
|
|
||
| t0 = time.perf_counter() | ||
| for _ in range(loops): | ||
| _, ptr = _alloc(_size, _stream) | ||
| _free(ptr, _stream) | ||
| return time.perf_counter() - t0 | ||
|
|
||
|
|
||
| def bench_memcpy_htod(loops: int) -> float: | ||
| _fn = cuda.cuMemcpyHtoD | ||
| _dst = DST_DPTR | ||
| _src = HOST_SRC | ||
| _size = COPY_SIZE | ||
|
|
||
| t0 = time.perf_counter() | ||
| for _ in range(loops): | ||
| _fn(_dst, _src, _size) | ||
| return time.perf_counter() - t0 | ||
|
|
||
|
|
||
| def bench_memcpy_dtoh(loops: int) -> float: | ||
| _fn = cuda.cuMemcpyDtoH | ||
| _dst = HOST_DST | ||
| _src = SRC_DPTR | ||
| _size = COPY_SIZE | ||
|
|
||
| t0 = time.perf_counter() | ||
| for _ in range(loops): | ||
| _fn(_dst, _src, _size) | ||
| return time.perf_counter() - t0 | ||
|
|
||
|
|
||
| def bench_memcpy_dtod(loops: int) -> float: | ||
| _fn = cuda.cuMemcpyDtoD | ||
| _dst = DST_DPTR | ||
| _src = SRC_DPTR | ||
| _size = COPY_SIZE | ||
|
|
||
| t0 = time.perf_counter() | ||
| for _ in range(loops): | ||
| _fn(_dst, _src, _size) | ||
| return time.perf_counter() - t0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were duplicated before. Cleaning up.