Skip to content
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

Implements dpctl.tensor.logsumexp and dpctl.tensor.reduce_hypot #1446

Merged
merged 14 commits into from
Oct 26, 2023

Conversation

ndgrigorian
Copy link
Collaborator

@ndgrigorian ndgrigorian commented Oct 19, 2023

This pull request proposes the additions of logsumexp and reduce_hypot into dpctl.

reduce_hypot can be used to find the Euclidean distance in N-dimensional space

In [1]: import dpctl.tensor as dpt, numpy as np

In [2]: x1 = dpt.full(10, 3, dtype="f4")

In [3]: x2 = dpt.ones(10, dtype="f4")

In [4]: d = dpt.reduce_hypot(x1 - x2)

In [5]: d
Out[5]: usm_ndarray(6.324554, dtype=float32)

logsumexp can be used to sum probabilities stored as the logarithm of the probability.

This pull request also slips in a change to disable the use of sycl::atomic_ref for arithmetic reductions (sum and prod) of inexact data types due to concerns with numerical stability. To better support this change, dedicated kernels for tree reductions over contiguous inputs have been implemented.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • If this PR is a work in progress, are you opening the PR as a draft?

@coveralls
Copy link
Collaborator

coveralls commented Oct 19, 2023

Coverage Status

coverage: 85.748% (+0.01%) from 85.735% when pulling d88e78f on logsumexp-reduce-hypot-impl into 2eba93e on master.

@github-actions
Copy link

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.15.1dev0=py310ha25a700_48 ran successfully.
Passed: 934
Failed: 66
Skipped: 119

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.15.1dev0=py310ha25a700_50 ran successfully.
Passed: 934
Failed: 66
Skipped: 119

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.15.1dev0=py310ha25a700_69 ran successfully.
Passed: 935
Failed: 65
Skipped: 119

@ndgrigorian ndgrigorian force-pushed the logsumexp-reduce-hypot-impl branch from c8683e3 to e95ac44 Compare October 24, 2023 05:16
@github-actions
Copy link

Array API standard conformance tests for dpctl=0.15.1dev0=py310ha25a700_69 ran successfully.
Passed: 933
Failed: 67
Skipped: 119

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.15.1dev0=py310ha25a700_70 ran successfully.
Passed: 934
Failed: 66
Skipped: 119

@ndgrigorian ndgrigorian force-pushed the logsumexp-reduce-hypot-impl branch from 5e3a671 to fff36a1 Compare October 25, 2023 01:23
@github-actions
Copy link

Array API standard conformance tests for dpctl=0.15.1dev0=py310ha25a700_71 ran successfully.
Passed: 934
Failed: 66
Skipped: 119

1 similar comment
@github-actions
Copy link

Array API standard conformance tests for dpctl=0.15.1dev0=py310ha25a700_71 ran successfully.
Passed: 934
Failed: 66
Skipped: 119

@ndgrigorian
Copy link
Collaborator Author

@oleksandr-pavlyk
I've added the per-type per-function atomic support checks we've discussed.

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.15.1dev0=py310ha25a700_72 ran successfully.
Passed: 935
Failed: 65
Skipped: 119

ndgrigorian and others added 14 commits October 25, 2023 14:15
This change was made to improve the accuracy of these functions
This change is intended to improve the numerical stability of sum and prod
These variants were using ``sycl::maximum`` rather than ``sycl::minimum``
Use lambdas to ignore atomic-specific arguments to hypot and logsumexp dtype_supported functions
For add/multiplies reductions, use tree reduction for FP types, real and complex,
to get better round-off accumulation properties.
Reduces code repetition between logsumexp and logaddexp
@ndgrigorian ndgrigorian force-pushed the logsumexp-reduce-hypot-impl branch from 599fadb to d88e78f Compare October 25, 2023 21:25
@github-actions
Copy link

Array API standard conformance tests for dpctl=0.15.1dev0=py310ha25a700_77 ran successfully.
Passed: 935
Failed: 65
Skipped: 119

Copy link
Collaborator

@oleksandr-pavlyk oleksandr-pavlyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you @ndgrigorian

@ndgrigorian ndgrigorian merged commit 03fd737 into master Oct 26, 2023
26 checks passed
@oleksandr-pavlyk oleksandr-pavlyk deleted the logsumexp-reduce-hypot-impl branch October 27, 2023 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants