← Back to Pull requests

Size the memory of empty DLPack tensors on oneAPI devices as one element #3203

Closed
unknown closed this pull request without merging on Nov 27, 2026 17:27 UTC
View on GitHub
unknown unknown commented on Nov 26, 2026 17:33 UTC
Author

This PR fixes the memory size that dpnp.tensor.from_dlpack and dpnp.from_dlpack give an empty DLPack tensor with more than one dimension on a oneAPI device.

from_dlpack_capsule sizes the memory of a tensor by the span from its lowest to its highest element offset. A dimension of length 0 added nothing to that span, but the other dimensions still did, so an empty tensor of shape (0, n) was sized as n elements. With a NULL data pointer, which DLPack asks for in a tensor of size zero and which #3197 made importable, that size is what gets allocated for the result: 4 MiB for shape (0, 220) of int32 and 8 GiB for (0, 231). With a data pointer, the imported memory claimed more than the producer allocated: 4 MiB for an empty dpnp.tensor array of shape (0, 2**20), whose buffer is 4 bytes. A tensor with a dimension of length 0 now spans no elements and gets one element, as usm_ndarray does for an empty shape.

Two tests are added. Importing an empty tensor with a NULL data pointer must allocate one element, and importing an empty dpnp.tensor array must not claim more memory than the array's buffer. Without the fix, all five cases fail.

#3183 changes the same loop to accept NULL strides, so whichever of the two PRs lands second needs a small rebase.

  • Have you provided a meaningful PR description?

  • Have you added a test, reproducer or referred to an issue with a reproducer?

  • Have you tested your changes locally for CPU and GPU devices?

  • Have you made sure that new changes do not introduce compiler warnings?

  • Have you checked performance impact of proposed changes?

  • Have you added documentation for your changes, if necessary?

  • Have you added your changes to the changelog?
  • Diff: 221 lines (+165 / -56) across 2 files Reviewer: vlad-perevezentsev Review duration: 1433m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.37) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 221 lines diff across 2 files
    0.37
    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.323
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3203"
    general weight: 0.35
    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: 36.8% (MEDIUM) · Higher = larger blast radius
    36.8%
    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: 14.5% · Safe to merge
    14.5%