Skip to content

Use linspace() function from dpctl.tensor. #1281

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 18 commits into from
Feb 28, 2023
Merged

Conversation

npolina4
Copy link
Contributor

@npolina4 npolina4 commented Jan 27, 2023

Use linspace() function from dpctl.tensor module instead of DPNP backend implementation.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to 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?
  • If this PR is a work in progress, are you filing the PR as a draft?

@oleksandr-pavlyk
Copy link
Contributor

oleksandr-pavlyk commented Jan 31, 2023

My experiment that ran into an error:

In [24]: x0, x1 = dpnp.ones((2,2)), dpnp.full((2,2,), 3)

In [25]: x0.device, x1.device
Out[25]: (Device(level_zero:gpu:0), Device(level_zero:gpu:0))

In [26]: x0.dtype, x1.dtype
Out[26]: (dtype('float32'), dtype('int64'))

In [27]: dpnp.linspace(x0, x1, num=5)   # raises ValueError: Device Intel(R) Graphics [0x9a49] does not provide native support for double-precision floating point type.

A variation dpnp.linspace(x0, dpnp.asarray(x1, 'f4'), num=5) works as expected.

I should also note that dpnp.linspace(x0[0,0], dpnp.asarray(x1, 'f4')[0,0], num=5) fails while attempting to fall back to NumPy.

When the array support works, it is rather slow. It would be nice to understand why.

In [54]: x2 = dpnp.asarray(x1, dtype=x0.dtype)

In [55]: %time dpnp.linspace(0.0, 3.0, num=1_000_000)
CPU times: user 9.2 ms, sys: 0 ns, total: 9.2 ms
Wall time: 9.95 ms
Out[55]: <dpnp.dpnp_array.dpnp_array at 0x7f4d75cd37f0>

In [56]: %time dpnp.linspace(x0, x2, num=1_000_000)
CPU times: user 133 ms, sys: 7.55 ms, total: 140 ms
Wall time: 187 ms
Out[56]: <dpnp.dpnp_array.dpnp_array at 0x7f4d6693f340>

@npolina4 npolina4 marked this pull request as ready for review February 17, 2023 01:33
@oleksandr-pavlyk
Copy link
Contributor

x = dpnp.linspace(0, 3 + 2j, num=1000) throws TypeError: can't convert complex to float.

x = dpt.linspace(0, 3 + 2j, num=1000) works as expected.

Comment on lines 230 to 231
_start = dpnp.asarray(start, dtype=dt, usm_type=usm_type, sycl_queue=sycl_queue_normalized)
_stop = dpnp.asarray(stop, dtype=dt, usm_type=usm_type, sycl_queue=sycl_queue_normalized)
Copy link
Contributor

@antonwolfy antonwolfy Feb 21, 2023

Choose a reason for hiding this comment

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

In case start and stop are both dpnp_array or usm_ndarray, we might change usm_type type here for resulting _start and _stop and so zero copy will not be applied (i.e. extra memory copy might take place).

Copy link
Contributor

@antonwolfy antonwolfy left a comment

Choose a reason for hiding this comment

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

Thank you! LGMT!

Copy link
Contributor

@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.

Thank you @npolina4 !

@antonwolfy
Copy link
Contributor

The PR is going to resolve issue #1249 .

Co-authored-by: Oleksandr Pavlyk <oleksandr.pavlyk@intel.com>
@antonwolfy antonwolfy merged commit f85a362 into master Feb 28, 2023
@antonwolfy antonwolfy deleted the use_dpctl_linspace branch February 28, 2023 13:33
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