Skip to content

to_device array method impl #1143

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 2 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions dpnp/dpnp_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ def T(self):
else:
return dpnp.transpose(self)

def to_device(self, target_device):
"""
Transfer array to target device
"""

return dpnp_array(shape=self.shape, buffer=self.get_array().to_device(target_device))
Copy link
Contributor

Choose a reason for hiding this comment

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

Other option is usage of method __new__ to create dpnp_array. As an example there is method flatten.


def __abs__(self):
return dpnp.abs(self)

Expand Down
15 changes: 15 additions & 0 deletions tests/test_sycl_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,18 @@ def test_2in_1out(func, device):

assert_sycl_queue_equal(result_queue, expected_queue)
assert result_queue.sycl_device == expected_queue.sycl_device


@pytest.mark.parametrize("device_from",
valid_devices,
ids=[device.filter_string for device in valid_devices])
@pytest.mark.parametrize("device_to",
valid_devices,
ids=[device.filter_string for device in valid_devices])
def test_to_device(device_from, device_to):
data = [1., 1., 1., 1., 1.]

x = dpnp.array(data, device=device_from)
y = x.to_device(device_to)

assert y.get_array().sycl_device == device_to