Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permit "same_kind" casting for usm_ndarray element-wise in-place operators #1827

Merged
merged 10 commits into from
Sep 11, 2024

Conversation

ndgrigorian
Copy link
Collaborator

@ndgrigorian ndgrigorian commented Sep 10, 2024

This pull request proposes a new implementation for in-place element-wise operators which permits casting equivalent to "same_kind"

This allows such operations as

In [1]: import dpctl.tensor as dpt, dpctl, numpy as np

In [2]: x = dpt.ones((10, 10), dtype="i4")

In [3]: y = dpt.ones((10, 10), dtype="i8")

In [4]: x += y

In [5]: x
Out[5]:
usm_ndarray([[2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
             [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
             [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
             [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
             [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
             [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
             [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
             [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
             [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
             [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]], dtype=int32)

This PR maintains the inclusion of (conditionally used) in-place kernels in element-wise operators when dpt.bin_op(x, y, out=x) for some bin_op which has an in-place implementation.

Resolves #1757

  • 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?
  • If this PR is a work in progress, are you opening the PR as a draft?

@ndgrigorian ndgrigorian force-pushed the in-place-element-wise-func-casting branch 2 times, most recently from f81119f to 13fde04 Compare September 10, 2024 03:07
Copy link

github-actions bot commented Sep 10, 2024

Deleted rendered PR docs from intelpython.github.com/dpctl, latest should be updated shortly. 🤞

Copy link

Array API standard conformance tests for dpctl=0.19.0dev0=py310hdf72452_9 ran successfully.
Passed: 894
Failed: 1
Skipped: 119

2 similar comments
Copy link

Array API standard conformance tests for dpctl=0.19.0dev0=py310hdf72452_9 ran successfully.
Passed: 894
Failed: 1
Skipped: 119

Copy link

Array API standard conformance tests for dpctl=0.19.0dev0=py310hdf72452_9 ran successfully.
Passed: 894
Failed: 1
Skipped: 119

Copy link

Array API standard conformance tests for dpctl=0.19.0dev0=py310hdf72452_10 ran successfully.
Passed: 894
Failed: 1
Skipped: 119

@coveralls
Copy link
Collaborator

coveralls commented Sep 10, 2024

Coverage Status

coverage: 87.907% (+0.01%) from 87.893%
when pulling 7599b37 on in-place-element-wise-func-casting
into cd7d41c on master.

This method permits casting behavior equivalent to `"same_kind"` when using in-place operators by introducing the `_inplace_op` method

Expands this to `__imatmul__` as well through use of the already-implemented `dtype` keyword
@ndgrigorian ndgrigorian force-pushed the in-place-element-wise-func-casting branch from f1ac695 to 79208c8 Compare September 10, 2024 17:32
Copy link

Array API standard conformance tests for dpctl=0.19.0dev0=py310hdf72452_13 ran successfully.
Passed: 894
Failed: 1
Skipped: 119

Copy link

Array API standard conformance tests for dpctl=0.19.0dev0=py310hdf72452_14 ran successfully.
Passed: 894
Failed: 1
Skipped: 119

Also clean up and make some tests for in-place operators more efficient
Copy link

Array API standard conformance tests for dpctl=0.19.0dev0=py310hdf72452_16 ran successfully.
Passed: 894
Failed: 1
Skipped: 119

@ndgrigorian ndgrigorian marked this pull request as ready for review September 10, 2024 23:31
@ndgrigorian
Copy link
Collaborator Author

@oleksandr-pavlyk
Tests are adjusted for the new behavior, this is RFR

Copy link

Array API standard conformance tests for dpctl=0.19.0dev0=py310hdf72452_17 ran successfully.
Passed: 893
Failed: 2
Skipped: 119

Copy link
Collaborator

@oleksandr-pavlyk oleksandr-pavlyk left a comment

Choose a reason for hiding this comment

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

Overall this change looks good to me, modulo a nit! Thank you @ndgrigorian

Copy link

Array API standard conformance tests for dpctl=0.19.0dev0=py310hdf72452_18 ran successfully.
Passed: 893
Failed: 2
Skipped: 119

@vtavana
Copy link
Collaborator

vtavana commented Sep 11, 2024

I ran dpnp tests with this branch and they pass.

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link

Array API standard conformance tests for dpctl=0.19.0dev0=py310hdf72452_19 ran successfully.
Passed: 893
Failed: 2
Skipped: 119

Copy link

Array API standard conformance tests for dpctl=0.19.0dev0=py310hdf72452_20 ran successfully.
Passed: 893
Failed: 2
Skipped: 119

Copy link

Array API standard conformance tests for dpctl=0.19.0dev0=py310hdf72452_21 ran successfully.
Passed: 893
Failed: 2
Skipped: 119

Copy link
Collaborator

@oleksandr-pavlyk oleksandr-pavlyk left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you @ndgrigorian

@ndgrigorian ndgrigorian merged commit 8b25773 into master Sep 11, 2024
41 of 50 checks passed
@ndgrigorian ndgrigorian deleted the in-place-element-wise-func-casting branch September 11, 2024 21:51
@oleksandr-pavlyk oleksandr-pavlyk mentioned this pull request Sep 12, 2024
8 tasks
antonwolfy added a commit to IntelPython/dpnp that referenced this pull request Jan 11, 2025
The PR proposes to permit `"same_kind"` casting for element-wise
in-place operators. The implementation leverages on dpctl changes added
in scope of [PR#1827](IntelPython/dpctl#1827).

It also adds callbacks to support in-place bit-wise operators (leverages
on dpctl changes from
[RR#1447](IntelPython/dpctl#1447)).

The PR removes a temporary workaround from `dpnp.wrap` which depends on
the implemented changes.
github-actions bot added a commit to IntelPython/dpnp that referenced this pull request Jan 11, 2025
The PR proposes to permit `"same_kind"` casting for element-wise
in-place operators. The implementation leverages on dpctl changes added
in scope of [PR#1827](IntelPython/dpctl#1827).

It also adds callbacks to support in-place bit-wise operators (leverages
on dpctl changes from
[RR#1447](IntelPython/dpctl#1447)).

The PR removes a temporary workaround from `dpnp.wrap` which depends on
the implemented changes. 3d02b6b
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.

The in-place elementwise operator cannot operate on the largest dtype for the second value.
4 participants