-
Notifications
You must be signed in to change notification settings - Fork 23
Update dpnp.isclose
with scalar-specific SYCL kernels
#2540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
View rendered docs @ https://intelpython.github.io/dpnp/pull/2540/index.html |
Array API standard conformance tests for dpnp=0.19.0dev2=py313h509198e_40 ran successfully. |
dpnp/backend/extensions/ufunc/elementwise_functions/isclose.cpp
Outdated
Show resolved
Hide resolved
dpnp/backend/extensions/ufunc/elementwise_functions/isclose.cpp
Outdated
Show resolved
Hide resolved
dpnp/backend/extensions/ufunc/elementwise_functions/isclose.cpp
Outdated
Show resolved
Hide resolved
dpnp/backend/extensions/ufunc/elementwise_functions/isclose.cpp
Outdated
Show resolved
Hide resolved
dpnp/backend/extensions/ufunc/elementwise_functions/isclose.cpp
Outdated
Show resolved
Hide resolved
dpnp/backend/extensions/ufunc/elementwise_functions/isclose.cpp
Outdated
Show resolved
Hide resolved
try: | ||
a, b = dpnp.broadcast_arrays(a, b) | ||
except ValueError: | ||
raise ValueError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason reissuing the same exception ?
Can we just call a, b = dpnp.broadcast_arrays(a, b)
without any try/except?
out_dtype = dpnp.bool | ||
output = dpnp.empty( | ||
a.shape, dtype=out_dtype, sycl_queue=exec_q, usm_type=usm_type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out_dtype = dpnp.bool | |
output = dpnp.empty( | |
a.shape, dtype=out_dtype, sycl_queue=exec_q, usm_type=usm_type | |
output = dpnp.empty( | |
a.shape, dtype=dpnp.bool, sycl_queue=exec_q, usm_type=usm_type |
b.get_array(), | ||
rtol, | ||
atol, | ||
equal_nan, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems there is no check above that equal_nan
is bool scalar. Should we add that?
@@ -870,6 +940,10 @@ def isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False): | |||
rtol, atol, scalar_type=True, all_scalars=True | |||
) | |||
|
|||
# Use own SYCL kernel for scalar rtol/atol | |||
if dpnp.isscalar(rtol) and dpnp.isscalar(atol): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in above docstrings there is missing mentioning that equal_nan
is optional
"atol", [1e-8, dpnp.array(1e-8), dpnp.full((10,), 1e-8)] | ||
) | ||
def test_isclose(self, dtype, rtol, atol): | ||
a = numpy.random.rand(10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to use generate_random_numpy_array
which has seeding?
a = numpy.random.rand(10) | ||
b = a + numpy.random.rand(10) * 1e-8 | ||
class TestIsClose: | ||
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to exclude None from list of dtypes?
assert_allclose(dpnp_res, np_res) | ||
np_res = numpy.isclose(a, b, rtol=1e-5, atol=1e-8) | ||
dpnp_res = dpnp.isclose(dpnp_a, dpnp_b, rtol=rtol, atol=atol) | ||
assert_allclose(dpnp_res, np_res) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the result is always a bool array:
assert_allclose(dpnp_res, np_res) | |
assert_equal(dpnp_res, np_res) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same below
This PR suggests updating
dpnp.isclose()
function adding a scalar-specific SYCL kernels for both contiguous and stride cases to improve performance whenrtol
andatol
are scalars.Also extends and updates tests for
dpnp.isclose()
The new kernel improves performance by up to 10x compared to the previous implementation when
rtol
andatol
are scalars (tested on PVC).CPU results:

GPU results:
