← Back to Pull requests

Add DWARF variant part support for polymorphic variables in CUDA debug info #544

Closed
unknown closed this pull request without merging on Nov 19, 2025 15:50 UTC
View on GitHub
unknown unknown commented on Oct 23, 2025 19:34 UTC
Author

Overview


This PR implements proper DWARF debug information generation for polymorphic variables in Numba CUDA kernels using DW_TAG_variant_part (discriminated unions). This enables debuggers like cuda-gdb to correctly inspect polymorphic variables that can hold different types throughout their lifetime.

Key Changes

1. Enhanced Polymorphic Variable Lowering (lowering.py)


  • With CUDA_DEBUG_POLY enabled:

  • - Allocates storage for discriminant + data
    - Stores discriminant at offset 0 and data at offset sizeof(fetype)
    - Retrieves data pointer with proper offset calculation
    - Memory layout:
    ``[discriminant: 8 bits][padding][data: varies by type]
    
    #### 2. DWARF Variant Part Metadata Generation (`debuginfo.py`)
    - Generate proper debug info metadata for variant types:
      - Creates `DW_TAG_variant_part` with discriminator field
      - Emits variant members with `extraData` field containing discriminant values
      - Wraps variant part in a structure type with proper size calculations
      - Each variant member includes correct offset (equals element's width in bits)
      The final DWARF structure: after this change would look like the following e.g.,
      

    variant_wrapper_struct (DW_TAG_structure_type)
    ├── discriminator (DW_TAG_member, 8 bits)
    └── variant_part (DW_TAG_variant_part)
    ├── _bool (DW_TAG_member, extraData: 0, offset: 8)
    ├── _float64 (DW_TAG_member, extraData: 1, offset: 64)
    ├── _int32 (DW_TAG_member, extraData: 2, offset: 32)
    └── _int64 (DW_TAG_member, extraData: 3, offset: 64)
    `
  • Added llvmlite version-dependent logic for extraData emission:

  • - Typed constant (
    i8 N) for newer llvmlite versions (> 0.45)
    - Metadata node reference for older versions (<= 0.45), requires an in progress nvvm patch
    - Controlled by
    CUDA_DEBUG_POLY_USE_TYPED_CONST config flag
  • Added CTK version threshold check:

  • - Feature enabled: When CTK > 13.1
    - Feature disabled: When CTK <= 13.1

    3. Test Coverage (test_debuginfo.py)


  • Added a new test test_poly_variant_part() to verify DWARF output:

  • - Conditionally turns on, opt-in via
    CUDA_DEBUG_POLY configuration flag
    - Validates complete hierarchical structure: DILocalVariable → wrapper struct → elements list → discriminator + variant_part → variant members
    - Dynamically adapts FileCheck patterns based on
    CUDA_DEBUG_POLY_USE_TYPED_CONST
    - Verifies all variant members (_bool, _float64, _int32, _int64) with correct offsets

    4. Backward Compatibility


  • Without CUDA_DEBUG_POLY: Falls back to existing behavior, i.e. user mentally choose runtime type from a union like types wrapper in a debugging session.

  • Older test (test_union_poly_types`) preserved and conditionally skipped
  • This change implements issue#520.

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    Summary by CodeRabbit

    New Features
    Added support for polymorphic debug information for CUDA union types, enabling enhanced debugging capabilities with structured variant metadata.
    Introduced new configuration flags to control polymorphic debug behavior and data representation modes.

    Tests
    * Added test coverage for polymorphic variant-part debugging information under various configuration scenarios.

    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 431 lines (+323 / -108) across 5 files Reviewer: jiel-nv Review duration: 38655m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 431 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.363
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #544"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.2% (MEDIUM) · Higher = larger blast radius
    45.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.8% · Safe to merge
    17.8%