Skip to content

Copy from ndarray #817

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
merged 3 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions dpctl/tensor/_copy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,12 @@ def _copy_from_numpy_into(dst, np_ary):
"Copies `np_ary` into `dst` of type :class:`dpctl.tensor.usm_ndarray"
if not isinstance(np_ary, np.ndarray):
raise TypeError("Expected numpy.ndarray, got {}".format(type(np_ary)))
src_ary = np.broadcast_to(np.asarray(np_ary, dtype=dst.dtype), dst.shape)
if src_ary.size and (dst.flags & 1) and src_ary.flags["C"]:
dpm.as_usm_memory(dst).copy_from_host(src_ary.reshape((-1,)).view("u1"))
return
if src_ary.size and (dst.flags & 2) and src_ary.flags["F"]:
dpm.as_usm_memory(dst).copy_from_host(src_ary.reshape((-1,)).view("u1"))
return
for i in range(dst.size):
mi = np.unravel_index(i, dst.shape)
host_buf = np.array(src_ary[mi], ndmin=1).view("u1")
usm_mem = dpm.as_usm_memory(dst[mi])
usm_mem.copy_from_host(host_buf)
if not isinstance(dst, dpt.usm_ndarray):
raise TypeError("Expected usm_ndarray, got {}".format(type(dst)))
src_ary = np.broadcast_to(np_ary, dst.shape)
ti._copy_numpy_ndarray_into_usm_ndarray(
src=src_ary, dst=dst, sycl_queue=dst.sycl_queue
)


def from_numpy(np_ary, device=None, usm_type="device", sycl_queue=None):
Expand Down
Loading