Skip to content

Fix missing strides validation in dpnp.tensor.usm_ndarray#2927

Open
vlad-perevezentsev wants to merge 5 commits into
masterfrom
extend_stride_validation
Open

Fix missing strides validation in dpnp.tensor.usm_ndarray#2927
vlad-perevezentsev wants to merge 5 commits into
masterfrom
extend_stride_validation

Conversation

@vlad-perevezentsev

Copy link
Copy Markdown
Contributor

This PR proposes to fix #2881 issue.

The problem was that usm_ndarray constructor did not validate user-provided strides when allocating new memory.
This made it possible to create arrays with invalid stride patterns producing negative memory displacement or oversized memory footprints.

This PR adds validation for invalid stride configurations when allocating new memory and raises ValueError for unsupported strides.
It also adds a new test_ctor_invalid_strides in test_usm_ndarray_ctor.py to cover these cases

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

@github-actions

Copy link
Copy Markdown
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/pull/2927/index.html

@github-actions

github-actions Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.21.0dev3=py314h509198e_16 ran successfully.
Passed: 1376
Failed: 1
Skipped: 5

@vlad-perevezentsev
vlad-perevezentsev marked this pull request as draft May 20, 2026 14:54
Comment thread dpnp/tensor/_usmarray.pyx Outdated
Comment thread dpnp/tensor/_usmarray.pyx Outdated
@vlad-perevezentsev

Copy link
Copy Markdown
Contributor Author

#2939 to fix fft falling test

vlad-perevezentsev added a commit that referenced this pull request Jun 26, 2026
…y allocation (#2939)

This PR fixes an issue discovered while implementing #2927 where several
FFT tests started failing after adding validation for stride
configurations with oversized memory footprints.

The problem was that FFT could allocate output arrays using the same
strided layout as a non-contiguous input. For inputs such as `a[::2`,
this resulted in oversized allocations followed by an additional copy to
a contiguous array.

This fix checks whether the memory footprint implied by the input
strides exceeds the number of elements in the array. If so, the input is
copied to a contiguous layout before configuring the FFT descriptor
allowing oneMKL FFT to produce a contiguous output directly

By avoiding oversized allocations and the extra copy this significantly
improves the performance of all FFT operations in dpnp with complex
strided inputs

Additionally, the cuFFT C-contiguous requirement is now enforced for all
code paths. Previously it was only applied within `batch_fft` branch
which was a latent bug for 1D non-batch inputs on CUDA.
github-actions Bot added a commit that referenced this pull request Jun 26, 2026
…y allocation (#2939)

This PR fixes an issue discovered while implementing #2927 where several
FFT tests started failing after adding validation for stride
configurations with oversized memory footprints.

The problem was that FFT could allocate output arrays using the same
strided layout as a non-contiguous input. For inputs such as `a[::2`,
this resulted in oversized allocations followed by an additional copy to
a contiguous array.

This fix checks whether the memory footprint implied by the input
strides exceeds the number of elements in the array. If so, the input is
copied to a contiguous layout before configuring the FFT descriptor
allowing oneMKL FFT to produce a contiguous output directly

By avoiding oversized allocations and the extra copy this significantly
improves the performance of all FFT operations in dpnp with complex
strided inputs

Additionally, the cuFFT C-contiguous requirement is now enforced for all
code paths. Previously it was only applied within `batch_fft` branch
which was a latent bug for 1D non-batch inputs on CUDA. 77e000b
@vlad-perevezentsev
vlad-perevezentsev marked this pull request as ready for review July 23, 2026 14:22
@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 78.375% (-0.01%) from 78.386% — extend_stride_validation into master

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.

Missing strides validation for usm_ndarray constructor

3 participants