Skip to content

Accept NULL strides in DLPack tensors on oneAPI devices - #3183

Draft
antonwolfy wants to merge 5 commits into
fix-dlpack-bugsfrom
dlpack-null-strides
Draft

antonwolfy wants to merge 5 commits into
fix-dlpack-bugsfrom
dlpack-null-strides

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

This PR fixes a segfault in dpnp.tensor.from_dlpack and dpnp.from_dlpack when importing a DLPack tensor on a oneAPI device with NULL strides.

To find the extent of the memory a kDLOneAPI tensor views, from_dlpack_capsule read strides[i] for every dimension without checking for NULL. DLPack before v1.2 allows strides to be NULL to mean a C-contiguous tensor, and the kDLCPU branch already handles that. The extent is now computed from C-contiguous strides when strides is NULL. The resulting array was already built with C-contiguous strides in that case.

dpnp's own capsules always set strides, so only tensors from other producers, through a legacy DLManagedTensor or a versioned tensor older than 1.2, reach this.

The test builds such tensors with the _dlpack_ctypes helper added in #3181, so this PR is stacked on #3181 and targets its branch; it is to be retargeted to master once #3181 is merged. Without the fix, every case of the new test segfaults, and computing the extent with a stride of 1 instead of the C-contiguous strides fails the 2-D case. The DLPack tests in dpnp/tests/tensor/test_usm_ndarray_dlpack.py and dpnp/tests/test_dlpack.py pass on a Level Zero iGPU and the OpenCL CPU device.

  • 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?

antonwolfy and others added 3 commits November 8, 2026 21:39
The `Run tests with oneMath develop branch` jobs build dpnp against the
head of oneMath `develop`. A failure there comes from upstream, not from
the PR under test, while the two jobs take 39-68 min each, about 105 min
of runner time per push (median of the last 6 `master` runs).

This PR moves them off pushes and PRs:
- `check-onemath.yaml` gets a nightly `schedule` (03:17 UTC) and a
`workflow_dispatch` trigger.
- `test_by_branch` runs only on `schedule` and `workflow_dispatch`.
`test_by_tag` keeps running on pushes and PRs, and is skipped on the
nightly run.
- The oneMath checkout uses the renamed `uxlfoundation/oneMath`
repository instead of the `oneapi-src/oneMKL` redirect (its default
branch is still `develop`), and the step names and the source directory
variable say oneMath.

Neither job is a required check. A failed nightly run shows in the
Actions tab, and GitHub sends its notification to the user who last
changed the `cron` line. On this PR the develop branch jobs show as
skipped; the first nightly run after merge, or a manual dispatch, is the
real check.
…mpiler (#3174)

DPC++ 2026.0 is the minimum compiler (the conda recipes reject anything
older), and every 2026.x release ships libsycl 9
(`__LIBSYCL_MAJOR_VERSION 9`). Two `__LIBSYCL_MAJOR_VERSION` checks in
the libtensor headers therefore always take the same branch.

This PR:
- drops the `__LIBSYCL_MAJOR_VERSION < 7` term from `needs_workaround`
in `kernels/reductions.hpp`, which kept `sycl::logical_or<bool>` off
reduce-over-group for older compilers. The term is always false; the
`int64`/`uint64` `sycl::multiplies` exclusion stays.
- removes `USE_GROUP_LOAD_STORE` from `utils/sycl_utils.hpp`, so
`sub_group_load` and `sub_group_store` always use
`group_load`/`group_store` from `sycl_ext_oneapi_group_load_store`. The
`__LIBSYCL_MAJOR_VERSION >= 8u` check already set the macro to 1 (DPC++
2026.0 doesn't define the `SYCL_EXT_ONEAPI_GROUP_LOAD_STORE`
feature-test macro the check looked at first). Setting it to 0 by hand
doesn't work either: the fallback calls the `sycl::sub_group` member
`load`/`store`, and icpx 2026.0 fails with `no member named 'load' in
'sycl::sub_group'`. The macro is defined in a header shipped with dpnp,
hence the changelog entry.

The default build compiles the same code as before. With icpx 2026.2, a
syntax-only compile of both headers passes without warnings, and static
asserts confirm that `needs_workaround` and `can_use_reduce_over_group`
keep their values for `logical_or<bool>` and for the `int64`/`uint64`
`multiplies`.
`from_dlpack_capsule` read `strides[i]` of a `kDLOneAPI` tensor without checking for NULL to find the extent of its memory, so importing a tensor with NULL strides segfaulted. Before DLPack 1.2, NULL strides mean the tensor is C-contiguous, and the `kDLCPU` branch already handled them. The extent is now computed from C-contiguous strides when `strides` is NULL.
@antonwolfy antonwolfy self-assigned this Nov 9, 2026
@antonwolfy
antonwolfy changed the base branch from master to fix-dlpack-bugs November 9, 2026 12:16
@antonwolfy
antonwolfy requested a balanced review from Copilot November 9, 2026 12:23
@antonwolfy
antonwolfy marked this pull request as draft November 9, 2026 12:23
@antonwolfy antonwolfy added this to the 0.22.0 release milestone Nov 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the DLPack NULL-stride fix and related maintenance updates.

No open issues 🎉

What changed in this PR

Fixes a crash in dpnp’s DLPack imports when a oneAPI tensor uses NULL strides to represent C-contiguous data, as allowed before DLPack 1.2. Regression tests build on the ctypes helper from #3181.

Changes:

  • Computes the memory extent using implicit C-contiguous strides and tests legacy and versioned capsules across several shapes.
  • Removes legacy SYCL load/store fallbacks and an older compiler workaround.
  • Moves oneMath develop-branch checks to nightly/manual runs and updates the upstream repository reference.
File Description
dpnp/​tests/​tensor/​test_usm_ndarray_dlpack.py Adds NULL-stride import regression tests, including empty arrays.
dpnp/​tensor/​_dlpack.pyx Handles NULL strides when calculating oneAPI tensor memory extent.
dpnp/​libtensor/​include/​utils/​sycl_utils.hpp Uses the group load/store extension unconditionally.
dpnp/​libtensor/​include/​kernels/​reductions.hpp Removes the pre-SYCL-7 Boolean reduction workaround.
CHANGELOG.md Records the DLPack fix and load/store fallback removal.
.github/​workflows/​check-onemath.yaml Schedules develop-branch checks and switches to uxlfoundation/oneMath.

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.22.0dev1=np2py314h8d9cdd5_11 ran successfully.
Passed: 1491
Failed: 0
Skipped: 6

This branch has not been deployed

No deployments
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.

2 participants