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

dpt.from_dlpack doesn't preserve flag values of an input array #1755

Open
antonwolfy opened this issue Jul 24, 2024 · 1 comment
Open

dpt.from_dlpack doesn't preserve flag values of an input array #1755

antonwolfy opened this issue Jul 24, 2024 · 1 comment

Comments

@antonwolfy
Copy link
Collaborator

The below example:

import dpnp, dpctl, dpctl.tensor as dpt

dpctl.__version__
# Out: '0.18.0dev0+158.g7450558d25'

a = dpnp.ones(10)
a.flags
# Out:
#   C_CONTIGUOUS : True
#   F_CONTIGUOUS : True
#   WRITABLE : True

a.flags["W"] = False
a.flags
# Out:
#   C_CONTIGUOUS : True
#   F_CONTIGUOUS : True
#   WRITABLE : False

b = dpt.from_dlpack(a)
b.flags
# Out:
#   C_CONTIGUOUS : True
#   F_CONTIGUOUS : True
#   WRITABLE : True

demonstrates that writable flag set to False for dpnp array a was not preserved after dpt.from_dlpack(a) call.

@oleksandr-pavlyk
Copy link
Collaborator

@antonwolfy This is because dpnp,ndarray does not yet support max_version keyword in its __dlpack__ method:

(dev_dpctl) opavlyk@sprpvcbenchlin01:/localdisk/work/opavlyk/repos/dpctl$ ipython
Python 3.12.4 | packaged by conda-forge | (main, Jun 17 2024, 10:23:07) [GCC 12.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.26.0 -- An enhanced Interactive Python. Type '?' for help.

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

In [2]: x = dpt.linspace(100, 0, num=101, dtype="f8")

In [3]: x.flags["W"] = False

In [4]: y = dpnp.linspace(100, 0, num=101, dtype="f8")

In [5]: y.flags["W"] = False

In [6]: x.__dlpack__(max_version=(1, 0))
Out[6]: <capsule object "dltensor_versioned" at 0x7f71dcefa8e0>

In [7]: y.__dlpack__(max_version=(1, 0))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[7], line 1
----> 1 y.__dlpack__(max_version=(1, 0))

TypeError: dpnp_array.__dlpack__() got an unexpected keyword argument 'max_version'

Once added, from_dlpack would preserve the flag as it does for dpctl.tensor.

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

No branches or pull requests

2 participants