Skip to content

order of output array for binary elementwise funcs, clip, and matmul defaults to C-contiguous #1678

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

Merged
merged 1 commit into from
May 15, 2024

Conversation

ndgrigorian
Copy link
Collaborator

This PR proposes a change to clip, matmul, and the BinaryElementwiseFunc class which makes C the default contiguity of outputs when order="K" and the input arrays must be cast.

This fixes a minor discrepancy where when multiple input arrays are both C- and F-contiguous and need to be cast, the output defaulted to F-contiguous instead of C-contiguous, creating unusual edge cases where type promotion (and therefore the selected device) became relevant to the output array's order, which should not be the case.

For example

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

In [2]: x1 = dpt.ones((10, 1), dtype="i4", device="cpu")

In [3]: x2 = dpt.ones((1, 5), dtype="f4", device="cpu")

In [4]: r = dpt.multiply(x1, x2)

In [5]: r.flags
Out[5]:
  C_CONTIGUOUS : False
  F_CONTIGUOUS : True
  WRITABLE : True

The selected device's type promotion graph contains float64, leading to F-contiguous outputs.

after this change:

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

In [2]: x1 = dpt.ones((10, 1), dtype="i4", device="cpu")
x
In [3]: x2 = dpt.ones((1, 5), dtype="f4", device="cpu")

In [4]: r = dpt.multiply(x1, x2)

In [5]: r.flags
Out[5]:
  C_CONTIGUOUS : True
  F_CONTIGUOUS : False
  WRITABLE : True
  • 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?
  • If this PR is a work in progress, are you opening the PR as a draft?

…se functions, clip, matmul

When multiple input arrays are both C- and F-contiguous and need to be cast, the output defaults to C-contiguous instead of F-contiguous
Copy link

github-actions bot commented May 15, 2024

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

@oleksandr-pavlyk
Copy link
Contributor

This looks uncontroversial enough for me.

@coveralls
Copy link
Collaborator

Coverage Status

coverage: 87.948%. remained the same
when pulling eacef28 on fix-elementwise-order-K-broadcasting
into 7bc3124 on master.

@ndgrigorian ndgrigorian marked this pull request as ready for review May 15, 2024 21:07
Copy link
Contributor

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

LGMT!

Copy link

Array API standard conformance tests for dpctl=0.17.0dev0=py310h15de555_352 ran successfully.
Passed: 888
Failed: 17
Skipped: 91

@ndgrigorian
Copy link
Collaborator Author

@vtavana confirmed that dpctl test suite was unaffected by this change, I will go ahead and merge it

Internal CI failures also unrelated

@ndgrigorian ndgrigorian merged commit d840cee into master May 15, 2024
60 of 63 checks passed
@ndgrigorian ndgrigorian deleted the fix-elementwise-order-K-broadcasting branch May 15, 2024 22:39
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.

3 participants