Skip to content

Commit

Permalink
Fixes #723
Browse files Browse the repository at this point in the history
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.
```
  • Loading branch information
oleksandr-pavlyk committed Dec 13, 2021
1 parent b7a15ed commit e0ff696
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions dpctl/tensor/_copy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ def _copy_from_numpy_into(dst, np_ary):
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 (dst.flags & 1) and src_ary.flags["C"]:
dst.usm_data.copy_from_host(src_ary.reshape((-1,)).view("u1"))
return
if (dst.flags & 2) and src_ary.flags["F"]:
dst.usm_data.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")
Expand Down

0 comments on commit e0ff696

Please sign in to comment.