Skip to content

Conversation

@vlad-perevezentsev
Copy link
Collaborator

Previously C-contiguous arrays with ndim > 0 were exported with NULL strides while F-contiguous strides were computed explicitly.
In #2193 NULL strides are no longer allowed due to DLPack v 1.2 and missing strides started to be
computed using only F-order logic so C-contiguous arrays were exported with incorrect strides

import dpctl.tensor as dpt

a = dpt.asarray([[1,2,3],[4,5,6]])
a.strides
# (3, 1)
b = dpt.from_dlpack(a)
b.strides
# (1, 2)

This PR adds stride computation for C-contiguous layouts and resolves #2213

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

@github-actions
Copy link

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.22.0dev0=py310h93fe807_77 ran successfully.
Passed: 1116
Failed: 42
Skipped: 82

@coveralls
Copy link
Collaborator

Coverage Status

coverage: 86.25% (-0.02%) from 86.269%
when pulling da72671 on resolve_gh_2213
into 2b3f1ec on master.

for i in range(nd):
shape_strides_ptr[i] = shape_ptr[i]
strides_ptr = usm_ary.get_strides()
flags = usm_ary.flags_
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can define this above with other Cython variables

cdef int flags = 0

which is how it was before the flags check was removed

Comment on lines +315 to +320
stdlib.free(shape_strides_ptr)
stdlib.free(dlm_tensor)
raise BufferError(
"to_dlpack_capsule: Could not reconstruct strides "
"for non-contiguous tensor"
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

good that we're covering this case, I think it would be better to be more specific about the problem though

in dpctl4pybind11.hpp we throw

  throw std::runtime_error("Invalid array encountered when "
                           "building strides");

something like this might make more sense, so it's understood the array is invalid

Comment on lines +443 to +448
stdlib.free(shape_strides_ptr)
stdlib.free(dlmv_tensor)
raise BufferError(
"to_dlpack_versioned_capsule: Could not reconstruct "
"strides for non-contiguous tensor"
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

same comment as above

Copy link
Collaborator

@ndgrigorian ndgrigorian left a comment

Choose a reason for hiding this comment

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

those are the only comments from me, everything else LGTM

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.

dpt.from_dlpack changes content of usm_ndarray

3 participants