Skip to content

[libcu++] Add stream debugger pretty-printers - #10520

Merged
Jacobfaib merged 17 commits into
NVIDIA:mainfrom
JJordan0C:feat/add-stream-pretty-printers
Aug 6, 2026
Merged

[libcu++] Add stream debugger pretty-printers#10520
Jacobfaib merged 17 commits into
NVIDIA:mainfrom
JJordan0C:feat/add-stream-pretty-printers

Conversation

@JJordan0C

Copy link
Copy Markdown
Contributor

Description

closes #10095

Add GDB and LLDB pretty-printers for cuda::stream and cuda::stream_ref.

The formatters expose the wrapped native handle without invoking CUDA APIs in the inferior, and provide stable descriptions for default, legacy, per-thread, invalid, and moved-from stream states. The debugger test matrix covers owning streams, references, aliases, and each special handle state.

Validation

  • All pre-commit hooks passed on the nine changed files.
  • Built the libcudacxx.test.debugging target with CUDA 13.3, GCC 15.2, and SM 89.
  • Ran the debugging CTest suite with GDB 17.1 and LLDB 23.0: 6/6 tests passed.

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@JJordan0C
JJordan0C requested review from a team as code owners July 28, 2026 21:17
@JJordan0C
JJordan0C requested a review from arhag23 July 28, 2026 21:17
@JJordan0C
JJordan0C requested a review from ericniebler July 28, 2026 21:17
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jul 28, 2026
@copy-pr-bot

copy-pr-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jul 28, 2026
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added CUDA stream (cuda::stream) and stream reference (cuda::stream_ref) pretty-printers for GDB and LLDB.
    • Stream details now include handle information, device, priority, flags, capture state, and a stable unique_id when available.
    • LLDB exposes stream properties as synthetic debugger fields.
  • Bug Fixes
    • Improved debugger behavior during active CUDA graph capture.
  • Tests
    • Added coverage for stream states, aliases, transitions, and capture scenarios.
    • Normalized dynamic stream IDs in test output.

Walkthrough

Adds GDB and LLDB pretty-printers for cuda::stream and cuda::stream_ref. Registers both printers and adds tests for stream handles, metadata, aliases, invalid states, updates, and capture transitions.

Changes

CUDA stream debugger support

Layer / File(s) Summary
GDB stream printer
libcudacxx/share/libcudacxx/gdb/stream.py, libcudacxx/share/libcudacxx/gdb/__init__.py
Recognizes stream types, queries metadata with capture-aware behavior, exposes printer children, and registers the printer with GDB.
LLDB stream formatter
libcudacxx/share/libcudacxx/lldb/stream.py, libcudacxx/share/libcudacxx/lldb/__init__.py
Recognizes stream types, formats handles and metadata, exposes synthetic children, and registers LLDB formatters.
Stream debugger test coverage
libcudacxx/test/debugging/CMakeLists.txt, libcudacxx/test/debugging/stream/*, libcudacxx/test/debugging/run_pretty_printer_test.py
Adds stream scenarios, expected GDB and LLDB output, capture and update cases, and normalization for runtime-generated unique IDs.

Assessment against linked issues

Objective Addressed Explanation
Create GDB and LLDB pretty-printers for cuda::stream and cuda::stream_ref under the specified debugger directories [#10095]
Add exhaustive tests under libcudacxx/test/debugging/stream [#10095]

Suggested reviewers: ericniebler


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

Comment thread libcudacxx/test/debugging/stream/lldb.expected Outdated
Comment thread libcudacxx/test/debugging/stream/source.cu
@github-project-automation github-project-automation Bot moved this from In Review to In Progress in CCCL Jul 29, 2026
@JJordan0C
JJordan0C requested a review from Jacobfaib July 29, 2026 13:40

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
libcudacxx/share/libcudacxx/lldb/stream.py (1)

230-289: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Capture status (and full metadata) is queried twice per print.

stream_summary queries _CUDA_STREAM_IS_CAPTURING and, when not capturing, _unique_id. StreamSyntheticProvider.update() then calls _stream_info, which re-queries capture status independently before fetching device/priority/flags. Since both are registered together (type summary add --expand + type synthetic add), a single print/frame variable -A on a stream triggers this capture-status query at least twice, plus separate malloc/free round-trips for the same logical data.

♻️ Suggested approach

Cache the combined StreamInfo (and handle/unique_id) per (process, load-address, stop-id) the first time either callback runs for a given stop, and have both stream_summary and StreamSyntheticProvider.update() read from that cache instead of re-issuing inferior calls.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 5f905598-abbe-4273-99d8-de9a178d8b30

📥 Commits

Reviewing files that changed from the base of the PR and between dc42460 and 0cd5482.

📒 Files selected for processing (7)
  • libcudacxx/share/libcudacxx/gdb/stream.py
  • libcudacxx/share/libcudacxx/lldb/stream.py
  • libcudacxx/test/debugging/run_pretty_printer_test.py
  • libcudacxx/test/debugging/stream/CMakeLists.txt
  • libcudacxx/test/debugging/stream/gdb.expected
  • libcudacxx/test/debugging/stream/lldb.expected
  • libcudacxx/test/debugging/stream/source.cu
🚧 Files skipped from review as they are similar to previous changes (1)
  • libcudacxx/test/debugging/stream/CMakeLists.txt

…y-printers

# Conflicts:
#	libcudacxx/share/libcudacxx/gdb/__init__.py
#	libcudacxx/share/libcudacxx/lldb/__init__.py
Comment thread libcudacxx/share/libcudacxx/lldb/stream.py Outdated
Comment thread libcudacxx/test/debugging/stream/source.cu
@Jacobfaib

Copy link
Copy Markdown
Contributor

/ok to test 2aa22cd

@github-actions

This comment has been minimized.

@JJordan0C
JJordan0C requested a review from Jacobfaib July 29, 2026 20:52
@github-project-automation github-project-automation Bot moved this from In Progress to In Review in CCCL Jul 30, 2026
@Jacobfaib

Copy link
Copy Markdown
Contributor

/ok to test 44b233e

@Jacobfaib
Jacobfaib enabled auto-merge (squash) July 30, 2026 18:03
@JJordan0C
JJordan0C requested a review from Jacobfaib July 30, 2026 18:23
@Jacobfaib

Copy link
Copy Markdown
Contributor

/ok to test df63bda

@JJordan0C

Copy link
Copy Markdown
Contributor Author

@Jacobfaib, apologies for the delayed response. I live near Naples, close to the area affected by the earthquake a couple of days ago. Fortunately, I am safe, and I have now been able to get back to this PR.

I reworked the LLDB printer based on your feedback and replied to the inline comments. In summary:

  • Removed the CUDA context push/pop paths from both formatters.
  • Replaced the _BitInt packing with a typed Clang vector returned by a single expression.
  • Reduced the LLDB implementation from 488 to 350 lines.
  • Preserved the fallback for CUDA runtimes without cudaStreamGetDevice, without changing the current context.

Across 15 separate LLDB runs, the initial metadata evaluation took 10.5 to 15.7 ms, with a 12.2 ms median. All stream pretty-printer cases pass with both LLDB and GDB after merging the latest main.

When you have time, could you please take another look?

@JJordan0C
JJordan0C requested a review from Jacobfaib August 2, 2026 17:53
@Jacobfaib

Copy link
Copy Markdown
Contributor

/ok to test 6e4f734

@Jacobfaib Jacobfaib left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Almost there

Comment thread libcudacxx/share/libcudacxx/lldb/stream.py Outdated
Comment thread libcudacxx/share/libcudacxx/lldb/stream.py Outdated
…y-printers

# Conflicts:
#	libcudacxx/share/libcudacxx/gdb/__init__.py
#	libcudacxx/share/libcudacxx/lldb/__init__.py
@JJordan0C

Copy link
Copy Markdown
Contributor Author

@Jacobfaib, I addressed both follow-up comments in b447d46, added an explicit no-current-context regression for both debuggers, and merged the latest main. The updated stream tests pass with LLDB and GDB. Could you please take another look when you have time?

@JJordan0C
JJordan0C requested a review from Jacobfaib August 3, 2026 15:03
@github-actions

This comment has been minimized.

@Jacobfaib

Copy link
Copy Markdown
Contributor

/ok to test b447d46

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Jacobfaib Jacobfaib left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OK it is still a bit... overengineered, but at this point I feel it is relatively feature complete and the complexity is something we will just have to live with.

Thanks for the contribution!

@github-project-automation github-project-automation Bot moved this from In Progress to In Review in CCCL Aug 4, 2026
@Jacobfaib

Copy link
Copy Markdown
Contributor

@JJordan0C can you rebase the branch over latest main to resolve the conflicts? Then we can merge

…y-printers

# Conflicts:
#	libcudacxx/share/libcudacxx/gdb/__init__.py
#	libcudacxx/share/libcudacxx/lldb/__init__.py
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
libcudacxx/share/libcudacxx/gdb/stream.py (1)

137-149: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

suggestion: When cudaStreamIsCapturing cannot be called (capture_status is None), line 148 takes the capture branch and drops device, priority, flags, and unique ID. On a runtime or build where only that one query fails, the printer reports nothing instead of the metadata it could still obtain. Separate the two cases:

-        if capture_status != _CUDA_STREAM_CAPTURE_STATUS_NONE:
+        if (
+            capture_status is not None
+            and capture_status != _CUDA_STREAM_CAPTURE_STATUS_NONE
+        ):
             return StreamInfo(handle, description, None, None, None, is_capturing, None)
libcudacxx/share/libcudacxx/lldb/stream.py (2)

172-183: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

suggestion: The fallback retries the whole expression when the first evaluation fails for any reason, not only for a missing cudaStreamGetDevice. That doubles the cost of every genuinely failing print (unresolvable cuStreamGetId, no driver symbols, hung expression). Cache the outcome of the device-query probe once per target so that later prints skip the first form after it fails.


142-149: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

suggestion: Configure formatter expressions with SetSuppressPersistentResult(True) to prevent $N variables from accumulating, and SetTryAllThreads(False) to prevent LLDB from resuming other threads. Do not add a two-second timeout: LLDB’s default timeout is unlimited, and a fixed limit could interrupt valid CUDA calls.

libcudacxx/test/debugging/stream/source.cu (1)

13-17: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

suggestion: Add a shared debugging-test header for keep_for_debugger and include it from all nine fixtures. No existing common header provides this identical helper.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c64fc71d-a2c9-4a53-a2e4-a3bf37a1b5ca

📥 Commits

Reviewing files that changed from the base of the PR and between 48a83ba and 22c817f.

📒 Files selected for processing (10)
  • libcudacxx/share/libcudacxx/gdb/__init__.py
  • libcudacxx/share/libcudacxx/gdb/stream.py
  • libcudacxx/share/libcudacxx/lldb/__init__.py
  • libcudacxx/share/libcudacxx/lldb/stream.py
  • libcudacxx/test/debugging/CMakeLists.txt
  • libcudacxx/test/debugging/run_pretty_printer_test.py
  • libcudacxx/test/debugging/stream/CMakeLists.txt
  • libcudacxx/test/debugging/stream/gdb.expected
  • libcudacxx/test/debugging/stream/lldb.expected
  • libcudacxx/test/debugging/stream/source.cu
🚧 Files skipped from review as they are similar to previous changes (5)
  • libcudacxx/share/libcudacxx/lldb/init.py
  • libcudacxx/share/libcudacxx/gdb/init.py
  • libcudacxx/test/debugging/stream/CMakeLists.txt
  • libcudacxx/test/debugging/CMakeLists.txt
  • libcudacxx/test/debugging/run_pretty_printer_test.py

Comment thread libcudacxx/test/debugging/stream/gdb.expected
@Jacobfaib
Jacobfaib enabled auto-merge (squash) August 5, 2026 20:27
@JJordan0C
JJordan0C requested review from Jacobfaib and arhag23 August 6, 2026 12:39
@Jacobfaib

Copy link
Copy Markdown
Contributor

/ok to test dd262c4

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

⏱️ CCCL compile-time benchmark comparison: Public headers compile-time bench

Result: 0 regression row(s), 24 improvement row(s) above threshold.

Run Value
Config public-headers-gcc13
Baseline origin/main
Preset all-dev
Targets cub.headers.base, thrust.cpp.cuda.headers.base, libcudacxx.test.public_headers
GPU / launch args rtx2080 / --cuda 13.3 --host gcc13

Artifacts: reports and traces

TU total compilation

-f total-compilation inclusive --sort total

🟢 TU total compilation — Improvements
Rank Improvement impact Selected Δ Baseline Current Event Matched traces
1 4.853418 -4.853418 15.854499 11.001081 Total Compilation Time: cub/device/device_segmented_scan.cuh 1
2 3.770863 -3.770863 10.467698 6.696835 Total Compilation Time: cub/agent/agent_merge.cuh 1
3 3.653777 -3.653777 7.702122 4.048345 Total Compilation Time: cuda/iterator 1
4 3.634007 -3.634007 20.671292 17.037285 Total Compilation Time: cuda/std/execution 1
5 3.590263 -3.590263 9.151802 5.561539 Total Compilation Time: cub/device/dispatch/dispatch_adjacent_difference.cuh 1
6 3.565514 -3.565514 14.424884 10.859370 Total Compilation Time: cub/device/device_scan.cuh 1
7 3.269102 -3.269102 15.415997 12.146895 Total Compilation Time: cub/device/device_reduce.cuh 1
8 3.114929 -3.114929 10.306442 7.191513 Total Compilation Time: cub/block/block_load_to_shared.cuh 1
9 3.083556 -3.083556 12.017904 8.934348 Total Compilation Time: cub/device/dispatch/dispatch_find.cuh 1

Direct file processing

-f file-processing exclusive --sort total

🟢 Direct file processing — Improvements
Rank Improvement impact Selected Δ Baseline Current Event Matched traces
1 1.666588 -1.666588 10.688863 9.022275 Processing Header File: libcudacxx/include/cuda/std/__cccl/prologue.h 550
2 1.230787 -1.230787 13.062101 11.831314 Processing Header File: libcudacxx/include/cuda/std/__type_traits/type_list.h 477
3 1.132158 -1.132158 12.576779 11.444621 Processing Header File: libcudacxx/include/cuda/std/__iterator/concepts.h 437
4 1.011998 -1.011998 22.685565 21.673567 Processing Header File: libcudacxx/include/cuda/__device/physical_device.h 94
5 0.727058 -0.727058 3.868754 3.141696 Processing Header File: libcudacxx/include/cuda/std/__cccl/epilogue.h 550
6 0.598939 -0.598939 8.455653 7.856714 Processing Header File: cub/cub/util_type.cuh 279
7 0.576654 -0.576654 6.347313 5.770659 Processing Header File: libcudacxx/include/cuda/std/__iterator/iterator_traits.h 464
8 0.465813 -0.465813 3.282891 2.817078 Processing Header File: libcudacxx/include/cuda/std/__atomic/functions/cuda_ptx_generated.h 57
9 0.437030 -0.437030 4.608606 4.171576 Processing Header File: libcudacxx/include/cuda/std/__utility/pair.h 404
10 0.311703 -0.311703 3.389622 3.077919 Processing Header File: libcudacxx/include/cuda/std/__ranges/concepts.h 405
11 0.275804 -0.275804 2.443390 2.167586 Processing Header File: libcudacxx/include/cuda/std/__chrono/duration.h 116
12 0.269864 -0.269864 2.407841 2.137977 Processing Header File: libcudacxx/include/cuda/std/__functional/invoke.h 450
13 0.222615 -0.222615 1.572567 1.349952 Processing Header File: libcudacxx/include/cuda/std/__concepts/swappable.h 465
14 0.221467 -0.221467 2.237662 2.016195 Processing Header File: libcudacxx/include/cuda/std/__ranges/access.h 405
15 0.221446 -0.221446 1.912305 1.690859 Processing Header File: libcudacxx/include/cuda/std/__iterator/reverse_iterator.h 406

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 1h 23m: Pass: 100%/68 | Total: 1d 18h | Max: 1h 23m | Hits: 63%/663120

See results here.

@Jacobfaib
Jacobfaib merged commit 8574d65 into NVIDIA:main Aug 6, 2026
95 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Aug 6, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Aug 6, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[FEA]: Debugger pretty-printers: cuda::stream/cuda::stream_ref

3 participants