Skip to content

Commit 4580c71

Browse files
Fixes #723
Restores parity in performance of two scenarios in time_copy.py script ``` (idp_2021.4) [13:33:21 ansatnuc04 python]$ python time_copy.py Wall time: 0.0004440806806087494 sec. Device time: 9.926800000000001e-05 sec. Wall time: 0.0006928546354174614 sec. Device time: 0.000150562 sec. ```
1 parent b7a15ed commit 4580c71

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

dpctl/tensor/_copy_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ def _copy_from_numpy_into(dst, np_ary):
117117
if not isinstance(np_ary, np.ndarray):
118118
raise TypeError("Expected numpy.ndarray, got {}".format(type(np_ary)))
119119
src_ary = np.broadcast_to(np.asarray(np_ary, dtype=dst.dtype), dst.shape)
120+
if src_ary.size and (dst.flags & 1) and src_ary.flags["C"]:
121+
dpm.as_usm_memory(dst).copy_from_host(src_ary.reshape((-1,)).view("u1"))
122+
return
123+
if src_ary.size and (dst.flags & 2) and src_ary.flags["F"]:
124+
dpm.as_usm_memory(dst).copy_from_host(src_ary.reshape((-1,)).view("u1"))
125+
return
120126
for i in range(dst.size):
121127
mi = np.unravel_index(i, dst.shape)
122128
host_buf = np.array(src_ary[mi], ndmin=1).view("u1")

0 commit comments

Comments
 (0)