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

Boolean reductions allocate int32 temporary as USM-device #1565

Conversation

oleksandr-pavlyk
Copy link
Collaborator

Closes gh-1563

Allocating the temporary as USM-device ensures that atomic updates are always possible.

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

Closes gh-1563

Allocating the temporary as USM-device ensures that atomic updates
are always possible.
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.

This fixes the problem for me locally

In [5]: x
Out[5]:
usm_ndarray([[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9],
             [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
             [20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
             [30, 31, 32, 33, 34, 35, 36, 37, 38, 39],
             [40, 41, 42, 43, 44, 45, 46, 47, 48, 49],
             [50, 51, 52, 53, 54, 55, 56, 57, 58, 59],
             [60, 61, 62, 63, 64, 65, 66, 67, 68, 69],
             [70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
             [80, 81, 82, 83, 84, 85, 86, 87, 88, 89],
             [90, 91, 92, 93, 94, 95, 96, 97, 98, 99]], dtype=int32)

In [6]: x.usm_type
Out[6]: 'host'

In [7]: dpt.all(x)
Out[7]: usm_ndarray(False)

In [8]: dpt.any(x)
Out[8]: usm_ndarray(True)

before:

In [3]: dpt.any(x)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[3], line 1
----> 1 dpt.any(x)

File ~/repos/dpctl/dpctl/tensor/_utility_functions.py:126, in any(x, axis, keepdims)
    101 def any(x, axis=None, keepdims=False):
    102     """any(x, axis=None, keepdims=False)
    103
    104     Tests whether any input array elements evaluate to True along a given axis.
   (...)
    124             containing the results of the logical OR reduction.
    125     """
--> 126     return _boolean_reduction(x, axis, keepdims, tri._any)

File ~/repos/dpctl/dpctl/tensor/_utility_functions.py:45, in _boolean_reduction(x, axis, keepdims, func)
     38 wait_list = []
     39 res_tmp = dpt.empty(
     40     res_shape,
     41     dtype=dpt.int32,
     42     usm_type=res_usm_type,
     43     sycl_queue=exec_q,
     44 )
---> 45 hev0, ev0 = func(
     46     src=x_tmp,
     47     trailing_dims_to_reduce=red_nd,
     48     dst=res_tmp,
     49     sycl_queue=exec_q,
     50 )
     51 wait_list.append(hev0)
     53 # copy to boolean result array

ValueError: This reduction is not supported for this device and usm_type.

Copy link

github-actions bot commented Feb 26, 2024

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

@coveralls
Copy link
Collaborator

Coverage Status

coverage: 91.148%. remained the same
when pulling b89b37f on boolean-reduction-always-allocate-reduction-temporary-as-usm-device
into 16f23f7 on master.

Copy link

Array API standard conformance tests for dpctl=0.17.0dev0=py310h15de555_22 ran successfully.
Passed: 904
Failed: 2
Skipped: 94

@oleksandr-pavlyk oleksandr-pavlyk merged commit be6bced into master Feb 26, 2024
46 of 49 checks passed
@oleksandr-pavlyk oleksandr-pavlyk deleted the boolean-reduction-always-allocate-reduction-temporary-as-usm-device branch February 26, 2024 22:30
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.

Any/all reductions without atomic aspect
3 participants