From fde917a6bd10d364f801db7d36e5bc9a22b55927 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Mon, 17 Jul 2023 12:27:25 -0500 Subject: [PATCH] Improve race condition check for unary functions Of out array is logically the same as input array, there is no race condition, so avoid performing the temporary copy. --- dpctl/tensor/_elementwise_common.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dpctl/tensor/_elementwise_common.py b/dpctl/tensor/_elementwise_common.py index 1137fad2e8..55c95f5360 100644 --- a/dpctl/tensor/_elementwise_common.py +++ b/dpctl/tensor/_elementwise_common.py @@ -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.