Skip to content

MemoryUSM* constructors should be able to handle objects with __sycl_usm_array_interface__ and non-trivial strides. #396

@oleksandr-pavlyk

Description

@oleksandr-pavlyk

For Python object suai_obj exposing __sycl_usm_array_interface__ the call dpctl.memory.MemoryUSMShared(suai_obj) currently requires that strides entry in the interface dictionary be empty (implying C-contiguous data).

This issue is to request that support for arbitrary 'strides' and 'offset' settings be added.

The dpctl.memory objects will then assume ownership of memory with

  • pointer = char_ptr + itemsize * minimum(offset + dot(element_strides, indexes), indexes for shape)
  • nbytes = itemsize*(1 + maximum(offset + dot(element_strides, indexes), indexes for shape) - minimum(offset + dot(element_strides, indexes), indexes for shape).

For example, for sua_obj which is a (2,2) view of (4, 5) array corresponding to starred elements of the table below:

0 1 2 3 4
0
1 * *
2
3 * *

The interface dictionary will have offset = 6 and strides=(10, 2) and data=(address_of(ar[0,0]), WRITEABLE).

The MemoryUSMShared(sual_obj) will map memory from a[1,1] to a[3, 3] including 13 elements, namely {a[1,1], a[1,2], a[1, 3], a[1,4], a[2, 0], a[2, 1], a[2,2], a[2, 3], a[2,4], a[3,0], a[3, 1], a[3,2], a[3,3]}.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions