Skip to content

Pass depends to the _place call in dpnp.tensor.place - #3164

Merged
antonwolfy merged 4 commits into
masterfrom
fix-place-missing-depends
Nov 5, 2026
Merged

antonwolfy merged 4 commits into
masterfrom
fix-place-missing-depends

Conversation

@ndgrigorian

@ndgrigorian ndgrigorian commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

dpnp.tensor.place casts vals to the array's data type with dpt.astype, which is asynchronous, and then called ti._place without depends. The kernel could start before the cast finished and write values from an incomplete buffer into the array. dpnp.place goes through the same path.

The mask_positions call earlier in the function is synchronous, so only the cast was unordered. This PR passes depends=_manager.submitted_events to ti._place.

The race is timing-dependent, so no test is added. On an out-of-order queue of an Intel CPU (OpenCL), place of an int32 vals into a float32 array, with the cast held back behind a few large copies, gave wrong values in 9 of 10 runs before this change and in 0 of 10 after. On a Level Zero iGPU it did not reproduce either way.

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

place() casts vals to the array's data type with dpt.astype, which is
asynchronous, and then called ti._place without depends, so the kernel
could read the cast buffer before the cast finished.
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

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

@coveralls

coveralls commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 84.396%. remained the same — fix-place-missing-depends into master

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.

🟡 Changes recommended

A deterministic regression test is still needed to verify that _place receives the cast event in depends, since the existing value-only assertion can pass when that dependency is missing.

1 open issue
What changed in this PR

This PR fixes asynchronous ordering in dpnp.tensor.place, also used by dpnp.place, so writes wait for the values’ dtype conversion to finish.

Changes:

  • Passes the queue’s submitted events to _place to prevent incorrect values on out-of-order queues.
  • Adds a changelog entry describing the fix.
File Description
dpnp/​tensor/​_indexing_functions.py Forwards pending event dependencies to _place.
CHANGELOG.md Documents the ordering fix for both public place functions.

Review effort: Balanced

Comment thread dpnp/tensor/_indexing_functions.py Resolved

@antonwolfy antonwolfy 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.

LGTM, thank you!

Comment thread CHANGELOG.md Resolved
@ndgrigorian ndgrigorian changed the title Pass depends to the _place call in dpnp.tensor.place Pass depends to the _place call in dpnp.tensor.place Nov 5, 2026
@ndgrigorian ndgrigorian changed the title Pass depends to the _place call in dpnp.tensor.place Pass depends to the _place call in dpnp.tensor.place Nov 5, 2026
@antonwolfy
antonwolfy merged commit 1439b19 into master Nov 5, 2026
89 of 97 checks passed
@antonwolfy
antonwolfy deleted the fix-place-missing-depends branch November 5, 2026 17:44
github-actions Bot added a commit that referenced this pull request Nov 5, 2026
`dpnp.tensor.place` casts `vals` to the array's data type with
`dpt.astype`, which is asynchronous, and then called `ti._place` without
`depends`. The kernel could start before the cast finished and write
values from an incomplete buffer into the array. `dpnp.place` goes
through the same path.

The `mask_positions` call earlier in the function is synchronous, so
only the cast was unordered. This PR passes
`depends=_manager.submitted_events` to `ti._place`.

The race is timing-dependent, so no test is added. On an out-of-order
queue of an Intel CPU (OpenCL), `place` of an `int32` `vals` into a
`float32` array, with the cast held back behind a few large copies, gave
wrong values in 9 of 10 runs before this change and in 0 of 10 after. On
a Level Zero iGPU it did not reproduce either way. 1439b19
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.

4 participants