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

Implemented printing for usm_ndarrays #1013

Merged
merged 6 commits into from
Dec 11, 2022
Merged

Implemented printing for usm_ndarrays #1013

merged 6 commits into from
Dec 11, 2022

Conversation

ndgrigorian
Copy link
Collaborator

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

Closes #954

Implements __repr__ and __str__ for printing dpctl.tensor.usm_ndarray objects and options for printing.
For the sake of user convenience, dpctl stores its own print options separate from Numpy's.

For arrays large enough to be abbreviated (length > 1000 or whatever the user sets as the threshold), a copy of the nd corners is produced and as little data as possible is transferred to CPU while still leveraging np.array2string. This appeared to be faster than running dpctl.tensor.asnumpy on the array.

Some benchmarks using

q = dpctl.SyclQueue()
z = dpt.arange(10**7, sycl_queue=q)
%%time
repr(z);

CPU times: user 11.3 ms, sys: 765 µs, total: 12.1 ms
Wall time: 13 ms

%%time
q = dpt.asnumpy(z)
repr(q);

CPU times: user 6.18 ms, sys: 62.6 ms, total: 68.8 ms
Wall time: 95.8 ms

%%time
str(z);

CPU times: user 0 ns, sys: 9.63 ms, total: 9.63 ms
Wall time: 14.1 ms

%%time
q = dpt.asnumpy(z)
str(q);

CPU times: user 9.63 ms, sys: 50.3 ms, total: 59.9 ms
Wall time: 64.1 ms

Note that these were each run on new kernels, to avoid caching.

@github-actions
Copy link

github-actions bot commented Dec 9, 2022

@github-actions
Copy link

github-actions bot commented Dec 9, 2022

Array API standard conformance tests for dpctl=0.14.1dev0=py310h8c27c75_9 ran successfully.
Passed: 33
Failed: 801
Skipped: 280

@coveralls
Copy link
Collaborator

coveralls commented Dec 9, 2022

Coverage Status

Coverage increased (+0.2%) to 82.276% when pulling 23b3311 on print-feature into bc9c5be on master.

@github-actions
Copy link

github-actions bot commented Dec 9, 2022

Array API standard conformance tests for dpctl=0.14.1dev0=py310h8c27c75_10 ran successfully.
Passed: 33
Failed: 801
Skipped: 280

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.1dev0=py310h8c27c75_10 ran successfully.
Passed: 33
Failed: 801
Skipped: 280

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. This is an awesome addition.

Majority of the time of the printing comes from memory transfer:

In [12]: x = dpt.ones(10**7 + 2, dtype='i2', device='gpu')

In [13]: %timeit p._nd_corners(x, 4)
222 µs ± 6.9 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

In [14]: %timeit x.__repr__()
932 µs ± 50.6 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

In [15]: %timeit p._nd_corners(x, 4)
232 µs ± 10.1 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

In [16]: xx = p._nd_corners(x, 4)

In [17]: %timeit dpt.asnumpy(xx)
638 µs ± 10.2 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

Perhaps we can improve the code in the future by avoiding the concat call, and instead allocating the elided memory, and launching several concurrent copy kernels for each kernel, and then a copy to host dependent on those corner copying kernels.

This better be done in a separate PR though.

@ndgrigorian ndgrigorian merged commit a3f8141 into master Dec 11, 2022
@github-actions
Copy link

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

@ndgrigorian ndgrigorian deleted the print-feature branch December 11, 2022 21:12
@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.1dev0=py310h8c27c75_10 ran successfully.
Passed: 33
Failed: 801
Skipped: 280

@fcharras
Copy link
Contributor

TY for this. Was much needed 🙏

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.

Implement printing of usm_ndarray contents
4 participants