[None][feat] add globaltimer-based timing backend for autotuner profi…#11657
Conversation
📝 WalkthroughWalkthroughThis PR introduces GPU global timer support to TensorRT-LLM. It adds CUDA kernel implementations for reading the GPU's global timer, Python bindings to expose this functionality, and integrates global timer-based profiling into the autotuner with fallback to traditional CUDA events. Changes
Sequence Diagram(s)sequenceDiagram
participant Python as Python Application
participant Binding as Nanobind Binding
participant CUDA as CUDA Kernel
participant GPU as GPU Memory
Python->>Binding: record_global_timer(data_ptr, stream)
Binding->>Binding: Convert pointer & extract stream
Binding->>Binding: Release Python GIL
Binding->>CUDA: invokeReadGlobalTimer(d_timestamp, stream)
CUDA->>CUDA: readGlobalTimerKernel launches
CUDA->>GPU: Read global timer via inline asm
GPU-->>CUDA: 64-bit timestamp
CUDA->>GPU: Write timestamp to device memory
CUDA-->>Binding: Kernel complete
Binding->>Binding: Reacquire Python GIL
Binding-->>Python: Return
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
cpp/tensorrt_llm/nanobind/runtime/bindings.cpp (1)
2-2:⚠️ Potential issue | 🟡 MinorUpdate copyright year to include 2026.
The file is being modified in 2026, but the copyright header still says
2022-2025. As per coding guidelines, the year should be updated on modified files.Proposed fix
- * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-FileCopyrightText: Copyright (c) 2022-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cpp/tensorrt_llm/nanobind/runtime/bindings.cpp` at line 2, Update the SPDX copyright header string "SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved." to include 2026 (e.g., change 2022-2025 to 2022-2026) in the top-of-file header in bindings.cpp so the file's copyright years reflect the current modification year.
🧹 Nitpick comments (2)
tensorrt_llm/_torch/autotuner.py (2)
716-716: Consider adding a brief comment clarifying the globaltimer unit assumption.
_NS_PER_MS = 1e6implies the globaltimer ticks in nanoseconds. While this is true for current NVIDIA GPUs (the%globaltimerregister is documented as a nanosecond-resolution counter), a short inline comment would help future readers understand the assumption.Suggested improvement
- _NS_PER_MS = 1e6 + _NS_PER_MS = 1e6 # GPU %globaltimer counts in nanoseconds🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tensorrt_llm/_torch/autotuner.py` at line 716, Add a short inline comment above the _NS_PER_MS constant explaining the unit assumption: note that _NS_PER_MS = 1e6 converts nanoseconds to milliseconds and that this relies on the GPU/globaltimer (%globaltimer) being a nanosecond-resolution counter (as on current NVIDIA GPUs); update the comment to mention the dependency so future readers know the timing source and assumption when using globaltimer anywhere in autotuner.py.
731-744: Timer backend selection logic is clean and well-structured.The three-tier resolution (env var override → auto-detect via CC state → default) is a sound pattern. The
confidential_compute_enabled()function (from_utils.py) handles errors internally and defaults toFalse, so the fallback to CUDA events is safe.One minor note: the log on Line 744 uses
logger.debug, which is appropriate for normal operation but may be hard to spot during initial deployment. Consider upgrading tologger.infoso operators can confirm which backend was selected without changing log levels.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tensorrt_llm/_torch/autotuner.py` around lines 731 - 744, Change the logging level so operators can see which timer backend was selected: replace the logger.debug call that logs the resolved _use_global_timer (after reading TLLM_PROFILING_TIMER and computing confidential_compute_enabled()) with logger.info so the chosen backend is visible at default info level and includes the same message content.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@cpp/tensorrt_llm/nanobind/runtime/bindings.cpp`:
- Line 2: Update the SPDX copyright header string "SPDX-FileCopyrightText:
Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved."
to include 2026 (e.g., change 2022-2025 to 2022-2026) in the top-of-file header
in bindings.cpp so the file's copyright years reflect the current modification
year.
---
Nitpick comments:
In `@tensorrt_llm/_torch/autotuner.py`:
- Line 716: Add a short inline comment above the _NS_PER_MS constant explaining
the unit assumption: note that _NS_PER_MS = 1e6 converts nanoseconds to
milliseconds and that this relies on the GPU/globaltimer (%globaltimer) being a
nanosecond-resolution counter (as on current NVIDIA GPUs); update the comment to
mention the dependency so future readers know the timing source and assumption
when using globaltimer anywhere in autotuner.py.
- Around line 731-744: Change the logging level so operators can see which timer
backend was selected: replace the logger.debug call that logs the resolved
_use_global_timer (after reading TLLM_PROFILING_TIMER and computing
confidential_compute_enabled()) with logger.info so the chosen backend is
visible at default info level and includes the same message content.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
cpp/tensorrt_llm/kernels/globalTimerKernel.cucpp/tensorrt_llm/kernels/globalTimerKernel.hcpp/tensorrt_llm/nanobind/runtime/bindings.cpptensorrt_llm/_torch/autotuner.py
59c1d92 to
529ac18
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #36541 [ run ] triggered by Bot. Commit: |
|
PR_Github #36541 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #36593 [ run ] triggered by Bot. Commit: |
|
PR_Github #36593 [ run ] completed with state |
e0007e1 to
6f8476c
Compare
…ling CUDA event timing (cudaEventElapsedTime) is unreliable when confidential compute (CC) is enabled (see https://nvbugs/4159316 for details). This adds an alternative timing backend that uses a small CUDA kernel reading %globaltimer before and after the profiled work, then computes elapsed time on the host. The timing backend is auto-selected based on CC state, with an env var override (TLLM_PROFILING_TIMER=globaltimer|cuda_event) for manual control. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Dan Hansen <1+dhansen-nvidia@users.noreply.github.com>
Signed-off-by: Dan Hansen <1+dhansen-nvidia@users.noreply.github.com>
Profiles existing GemmRunner tactics with both backends and asserts the measured times agree within 5%. Parametrized over use_cuda_graph to cover both graph-replay and loop-based profiling paths. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Dan Hansen <1+dhansen-nvidia@users.noreply.github.com>
…ith the comment that describes its function Signed-off-by: Dan Hansen <1+dhansen-nvidia@users.noreply.github.com>
Signed-off-by: Dan Hansen <1+dhansen-nvidia@users.noreply.github.com>
Signed-off-by: Dan Hansen <1+dhansen-nvidia@users.noreply.github.com>
ea81d10 to
9e451d8
Compare
|
/bot run --disable-fail-fast |
|
@hyukn The original comparison approach was not reliable due to quite a lot of variance in both timers. I've added a more statistically robust/rigorous comparison that is much more stable in testing. Also, when run with |
|
PR_Github #36966 [ run ] triggered by Bot. Commit: |
|
PR_Github #36966 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #37082 [ run ] triggered by Bot. Commit: |
|
PR_Github #37082 [ run ] completed with state |
NVIDIA#11657) Signed-off-by: tianyuz-nv <tianyuz@nvidia.com>
…ling
CUDA event timing (cudaEventElapsedTime) is unreliable when confidential compute (CC) is enabled (see https://nvbugs/4159316 for details). This adds an alternative timing backend that uses a small CUDA kernel reading %globaltimer before and after the profiled work, then computes elapsed time on the host.
The timing backend is auto-selected based on CC state, with an env var override (TLLM_PROFILING_TIMER=globaltimer|cuda_event) for manual control.
Summary by CodeRabbit
Release Notes
New Features
Chores
Description
Test Coverage
PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...Provide a user friendly way for developers to interact with a Jenkins server.
Run
/bot [-h|--help]to print this help message.See details below for each supported subcommand.
Details
run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]Launch build/test pipelines. All previously running jobs will be killed.
--reuse-test (optional)pipeline-id(OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.--disable-reuse-test(OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.--disable-fail-fast(OPTIONAL) : Disable fail fast on build/tests/infra failures.--skip-test(OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.--stage-list "A10-PyTorch-1, xxx"(OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.--gpu-type "A30, H100_PCIe"(OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.--test-backend "pytorch, cpp"(OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.--only-multi-gpu-test(OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.--disable-multi-gpu-test(OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.--add-multi-gpu-test(OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.--post-merge(OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx"(OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".--detailed-log(OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.--debug(OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in thestage-listparameter to access the appropriate container environment. Note: Does NOT update GitHub check status.For guidance on mapping tests to stage names, see
docs/source/reference/ci-overview.mdand the
scripts/test_to_stage_mapping.pyhelper.kill
killKill all running builds associated with pull request.
skip
skip --comment COMMENTSkip testing for latest commit on pull request.
--comment "Reason for skipping build/test"is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.reuse-pipeline
reuse-pipelineReuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.