Skip to content

Add dlpack support #1296

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

Conversation

vlad-perevezentsev
Copy link
Collaborator

@vlad-perevezentsev vlad-perevezentsev commented Feb 14, 2023

This PR closes #1291

The PR adds dlpack and dlpack_device protocols to dpnp_array and implements dpnp.from_dlpack function including tests and docstrings.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to 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?
  • If this PR is a work in progress, are you filing the PR as a draft?

@vlad-perevezentsev vlad-perevezentsev self-assigned this Feb 14, 2023
@vlad-perevezentsev vlad-perevezentsev linked an issue Feb 14, 2023 that may be closed by this pull request
@oleksandr-pavlyk
Copy link
Contributor

Looks good to me. I built the branch, tested few inputs:


In [16]: x_dpt = dpt.reshape(dpt.arange(4*30),(10,12))[::2,::2]

In [17]: x_dpt.shape, x_dpt.strides, x_dpt.__sycl_usm_array_interface__['offset']
Out[17]: ((5, 6), (24, 2), 0)

In [18]: dpt.from_dlpack(x_dpt)
Out[18]:
usm_ndarray([[  0,   2,   4,   6,   8,  10],
             [ 24,  26,  28,  30,  32,  34],
             [ 48,  50,  52,  54,  56,  58],
             [ 72,  74,  76,  78,  80,  82],
             [ 96,  98, 100, 102, 104, 106]])

In [19]: dpnp.from_dlpack(x_dpt)
Out[19]:
array([[  0,   2,   4,   6,   8,  10],
       [ 24,  26,  28,  30,  32,  34],
       [ 48,  50,  52,  54,  56,  58],
       [ 72,  74,  76,  78,  80,  82],
       [ 96,  98, 100, 102, 104, 106]])

In [20]: _.strides
Out[20]: (24, 2)

While testing I also discovered an issue in dpctl: IntelPython/dpctl#1071

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.

LGTM! We should test that it works with mpi4py before merging though

@oleksandr-pavlyk oleksandr-pavlyk merged commit 6640e9e into IntelPython:master Feb 16, 2023
@vlad-perevezentsev vlad-perevezentsev deleted the dlpack_support branch August 10, 2023 09:22
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.

Add dlpack support for dpnp
3 participants