Skip to content

Commit bd60be8

Browse files
corrected use of src_offset in copy_from_numpy_into_usm_ndarray
When figuring out the bytes-boundary of numpy array to form the sycl::buffer we use simplified strides and shapes, and hence must start with src_offset, not with zero. Now, both of these copy calls correctly populate the destination usm_ndarray. ``` In [2]: n, m = 10**2, 10**3 In [3]: a = np.hstack((np.arange(n, dtype=np.int32),) * m) In [4]: b = np.flipud(a) In [5]: In [5]: c = dpt.asarray(b, device='cpu') In [6]: c Out[6]: usm_ndarray([99, 98, 97, ..., 2, 1, 0], dtype=int32) In [7]: import dpctl.tensor._tensor_impl as ti In [8]: c = dpt.empty(b.shape, dtype=b.dtype)[::-1] In [9]: ti._copy_numpy_ndarray_into_usm_ndarray(src=b, dst=c, sycl_queue=c.sycl_queue) In [10]: c Out[10]: usm_ndarray([99, 98, 97, ..., 2, 1, 0], dtype=int32) In [11]: c = dpt.empty(b.shape, dtype=b.dtype) In [12]: ti._copy_numpy_ndarray_into_usm_ndarray(src=b, dst=c, sycl_queue=c.sycl_queue) In [13]: c Out[13]: usm_ndarray([99, 98, 97, ..., 2, 1, 0], dtype=int32) ```
1 parent eb97326 commit bd60be8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

dpctl/tensor/libtensor/source/copy_numpy_ndarray_into_usm_ndarray.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ void copy_numpy_ndarray_into_usm_ndarray(
211211
}
212212

213213
// Minumum and maximum element offsets for source np.ndarray
214-
py::ssize_t npy_src_min_nelem_offset(0);
215-
py::ssize_t npy_src_max_nelem_offset(0);
214+
py::ssize_t npy_src_min_nelem_offset(src_offset);
215+
py::ssize_t npy_src_max_nelem_offset(src_offset);
216216
for (int i = 0; i < nd; ++i) {
217217
if (simplified_src_strides[i] < 0) {
218218
npy_src_min_nelem_offset +=

0 commit comments

Comments
 (0)