Skip to content

Implement product #1426

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

Merged
merged 7 commits into from
Oct 3, 2023
Merged

Conversation

oleksandr-pavlyk
Copy link
Contributor

This is PR builds on top of work of #1399 and implements _prod_over_axis and the satellite associated type query function.

In [1]: import dpctl.tensor as dpt

In [2]: import dpctl.tensor._tensor_impl as ti

In [4]: x = dpt.linspace(1, 2, num=32, dtype="f4")

In [5]: x
Out[5]:
usm_ndarray([1.       , 1.032258 , 1.0645161, 1.0967741, 1.1290323,
             1.1612903, 1.1935483, 1.2258065, 1.2580645, 1.2903225,
             1.3225806, 1.3548386, 1.3870968, 1.4193548, 1.4516128,
             1.483871 , 1.516129 , 1.548387 , 1.5806451, 1.6129032,
             1.6451613, 1.6774192, 1.7096773, 1.7419355, 1.7741935,
             1.8064516, 1.8387096, 1.8709677, 1.9032258, 1.9354837,
             1.9677418, 2.       ], dtype=float32)

In [6]: z = dpt.empty(tuple(), dtype="f4")

In [7]: ti._prod_over_axis(src=x, trailing_dims_to_reduce=1, dst=z, sycl_queue=x.sycl_queue)[0].wait()

In [8]: z
Out[8]: usm_ndarray(224213.45, dtype=float32)

In [9]: dpt.asnumpy(x).prod()
Out[9]: 224213.47

The product runs into problems for complex types, and does not give the expected output for integral types, so this is a work-in-progress.

  • 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?

Implementation of Identity trait should call sycl::known_identity
if trait sycl::has_known_identity is a true_type.

Added IsMultiplies, and identity value for it, since sycl::known_identity
for multiplies is only defined for real-valued types.
@github-actions
Copy link

github-actions bot commented Oct 1, 2023

Array API standard conformance tests for dpctl=0.15.1dev0=py310ha25a700_23 ran successfully.
Passed: 930
Failed: 70
Skipped: 119

1 similar comment
@github-actions
Copy link

github-actions bot commented Oct 1, 2023

Array API standard conformance tests for dpctl=0.15.1dev0=py310ha25a700_23 ran successfully.
Passed: 930
Failed: 70
Skipped: 119

@ndgrigorian
Copy link
Collaborator

@oleksandr-pavlyk In testing out a prod implementation, I ran into the same issue with integers. It seems to only happen for 64-bit integers on GPU, CPU worked fine. I believe it's a bug. I didn't test it for 64-bit floats, but I suspect it may have the same problem.

The workaround that I used was a Multiplies struct that returns x * y.

…icable

Passing these function pointers around allows to turn atomic off altogether
if desired.

Use custom trait to check if reduce_over_groups can be used. This allows to
work-around bug, or switch to custom code for reduction over group if desired.

Such custom trait type works around issue with incorrect result returned from
sycl::reduce_over_group for sycl::multiplies operator for 64-bit integral types.
Also tweaked docstring for sum.
@github-actions
Copy link

github-actions bot commented Oct 2, 2023

@github-actions
Copy link

github-actions bot commented Oct 2, 2023

Array API standard conformance tests for dpctl=0.15.1dev0=py310ha25a700_24 ran successfully.
Passed: 930
Failed: 70
Skipped: 119

@github-actions
Copy link

github-actions bot commented Oct 2, 2023

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

@github-actions
Copy link

github-actions bot commented Oct 3, 2023

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

Small tweaks to sum, min, and max docstrings
Copy link
Collaborator

@ndgrigorian ndgrigorian left a comment

Choose a reason for hiding this comment

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

@oleksandr-pavlyk
I pushed a small change with a tweak to some docstrings.

I think this is good to go in.

@github-actions
Copy link

github-actions bot commented Oct 3, 2023

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

@oleksandr-pavlyk oleksandr-pavlyk merged commit 04ec23b into feature/reductions-custom-ops Oct 3, 2023
@oleksandr-pavlyk oleksandr-pavlyk deleted the implement-product branch October 3, 2023 02:11
@github-actions
Copy link

github-actions bot commented Oct 3, 2023

Deleted rendered PR docs from intelpython.github.com/dpctl, latest should be updated shortly. 🤞

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.

2 participants