Skip to content

Commit

Permalink
Merge pull request #1143 from IntelPython/use-array-overlap
Browse files Browse the repository at this point in the history
Used ti._array_overlap instead of local implementation
  • Loading branch information
oleksandr-pavlyk authored Mar 28, 2023
2 parents bd9e465 + 1a0cf15 commit ede58f6
Showing 1 changed file with 1 addition and 18 deletions.
19 changes: 1 addition & 18 deletions dpctl/tensor/_copy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,6 @@
)


def _has_memory_overlap(x1, x2):
if x1.size and x2.size:
m1 = dpm.as_usm_memory(x1)
m2 = dpm.as_usm_memory(x2)
# can only overlap if bound to the same context
if m1.sycl_context == m2.sycl_context:
p1_beg = m1._pointer
p1_end = p1_beg + m1.nbytes
p2_beg = m2._pointer
p2_end = p2_beg + m2.nbytes
# may intersect if not ((p1_beg >= p2_end) or (p2_beg >= p2_end))
return (p1_beg < p2_end) and (p2_beg < p1_end)
return False
# zero element array do not overlap anything
return False


def _copy_to_numpy(ary):
if not isinstance(ary, dpt.usm_ndarray):
raise TypeError
Expand Down Expand Up @@ -209,7 +192,7 @@ def _copy_overlapping(dst, src):
def _copy_same_shape(dst, src):
"""Assumes src and dst have the same shape."""
# check that memory regions do not overlap
if _has_memory_overlap(dst, src):
if ti._array_overlap(dst, src):
_copy_overlapping(src=src, dst=dst)
return

Expand Down

0 comments on commit ede58f6

Please sign in to comment.