Skip to content

Commit

Permalink
Improve race condition check for unary functions
Browse files Browse the repository at this point in the history
Of out array is logically the same as input array, there is no
race condition, so avoid performing the temporary copy.
  • Loading branch information
oleksandr-pavlyk committed Jul 17, 2023
1 parent d81b917 commit fde917a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion dpctl/tensor/_elementwise_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ def __call__(self, x, out=None, order="K"):
f" got {out.dtype}"
)

if buf_dt is None and ti._array_overlap(x, out):
if (
buf_dt is None
and ti._array_overlap(x, out)
and not ti._same_logical_tensors(x, out)
):
# Allocate a temporary buffer to avoid memory overlapping.
# Note if `buf_dt` is not None, a temporary copy of `x` will be
# created, so the array overlap check isn't needed.
Expand Down

0 comments on commit fde917a

Please sign in to comment.