Skip to content

[None][feat] add globaltimer-based timing backend for autotuner profi…#11657

Merged
Tabrizian merged 6 commits into
NVIDIA:mainfrom
dhansen-nvidia:globaltimer_profiling
Feb 27, 2026
Merged

[None][feat] add globaltimer-based timing backend for autotuner profi…#11657
Tabrizian merged 6 commits into
NVIDIA:mainfrom
dhansen-nvidia:globaltimer_profiling

Conversation

@dhansen-nvidia
Copy link
Copy Markdown
Collaborator

@dhansen-nvidia dhansen-nvidia commented Feb 23, 2026

…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

    • Introduced GPU global timer support for autotuner profiling as an alternative to CUDA event-based timing
    • Added configurable timing backend selection via environment variable for explicit control
    • Autotuner now automatically detects and uses the optimal timing backend based on system capabilities
  • Chores

    • Refactored profiling timing logic to support dual timing backends

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 the stage-list parameter 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.md
and the scripts/test_to_stage_mapping.py helper.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip 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-pipeline

Reuse 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.

@dhansen-nvidia dhansen-nvidia requested a review from a team as a code owner February 23, 2026 18:40
@dhansen-nvidia dhansen-nvidia requested a review from hyukn February 23, 2026 18:40
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 23, 2026

📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
Global Timer Kernel Implementation
cpp/tensorrt_llm/kernels/globalTimerKernel.cu, cpp/tensorrt_llm/kernels/globalTimerKernel.h
New CUDA kernel readGlobalTimerKernel that reads the GPU's 64-bit global timer using inline assembly and host API invokeReadGlobalTimer that launches the kernel on a single thread with error checking.
Python Bindings
cpp/tensorrt_llm/nanobind/runtime/bindings.cpp
Adds nanobind module binding record_global_timer that converts Python parameters (data pointer and stream) to C++ types and invokes the global timer kernel, releasing the GIL during execution.
Autotuner Integration
tensorrt_llm/_torch/autotuner.py
Integrates dual timing backends with environment-driven selection: global timer (via device-side timestamps and record_global_timer) or CUDA events (existing behavior), with nanosecond-to-millisecond conversion for global timer path.

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
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete. While it explains the issue and solution, it is missing the required 'Description', 'Test Coverage', and partially filled checklist sections from the template. Complete the 'Description' and 'Test Coverage' sections, and verify all checklist items are properly addressed before merging.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: adding a globaltimer-based timing backend for autotuner profiling, with proper format [None][feat].
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🟡 Minor

Update 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 = 1e6 implies the globaltimer ticks in nanoseconds. While this is true for current NVIDIA GPUs (the %globaltimer register 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 to False, 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 to logger.info so 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

📥 Commits

Reviewing files that changed from the base of the PR and between d8d1169 and f029e94.

📒 Files selected for processing (4)
  • cpp/tensorrt_llm/kernels/globalTimerKernel.cu
  • cpp/tensorrt_llm/kernels/globalTimerKernel.h
  • cpp/tensorrt_llm/nanobind/runtime/bindings.cpp
  • tensorrt_llm/_torch/autotuner.py

@dhansen-nvidia
Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #36541 [ run ] triggered by Bot. Commit: 529ac18 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #36541 [ run ] completed with state SUCCESS. Commit: 529ac18
/LLM/main/L0_MergeRequest_PR pipeline #28277 completed with status: 'FAILURE'

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@dhansen-nvidia
Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #36593 [ run ] triggered by Bot. Commit: 529ac18 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #36593 [ run ] completed with state SUCCESS. Commit: 529ac18
/LLM/main/L0_MergeRequest_PR pipeline #28319 completed with status: 'SUCCESS'

Link to invocation

Comment thread tensorrt_llm/_torch/autotuner.py
Comment thread tensorrt_llm/_torch/autotuner.py Outdated
@dhansen-nvidia dhansen-nvidia force-pushed the globaltimer_profiling branch 3 times, most recently from e0007e1 to 6f8476c Compare February 25, 2026 14:55
mojombo and others added 6 commits February 26, 2026 15:10
…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>
@dhansen-nvidia
Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@dhansen-nvidia
Copy link
Copy Markdown
Collaborator Author

@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 pytest -s, the test will print out a table showing/comparing the results of both the cuda event-based timing and global timer-based timing.

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #36966 [ run ] triggered by Bot. Commit: 9e451d8 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #36966 [ run ] completed with state SUCCESS. Commit: 9e451d8
/LLM/main/L0_MergeRequest_PR pipeline #28623 completed with status: 'FAILURE'

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@dhansen-nvidia
Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #37082 [ run ] triggered by Bot. Commit: 9e451d8 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #37082 [ run ] completed with state SUCCESS. Commit: 9e451d8
/LLM/main/L0_MergeRequest_PR pipeline #28711 completed with status: 'SUCCESS'

Link to invocation

@Tabrizian Tabrizian merged commit 63c33c7 into NVIDIA:main Feb 27, 2026
5 checks passed
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Mar 9, 2026
tianyuz-nv pushed a commit to wanqian-nv/TensorRT-LLM that referenced this pull request Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants