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

ProxyObject to support matrix multiplication #849

Merged
merged 1 commit into from
Feb 2, 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
11 changes: 11 additions & 0 deletions dask_cuda/proxy_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,9 @@ def __xor__(self, other):
def __or__(self, other):
return self._pxy_deserialize() | other

def __matmul__(self, other):
return self._pxy_deserialize().__matmul__(unproxy(other))

def __radd__(self, other):
return other + self._pxy_deserialize()

Expand Down Expand Up @@ -741,6 +744,14 @@ def __ior__(self, other):
self._pxy_set(pxy)
return self

def __imatmul__(self, other):
pxy = self._pxy_get(copy=True)
proxied = pxy.deserialize(nbytes=self.__sizeof__())
proxied @= other
pxy.obj = proxied
self._pxy_set(pxy)
return self

def __neg__(self):
return -self._pxy_deserialize()

Expand Down
24 changes: 24 additions & 0 deletions dask_cuda/tests/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,3 +620,27 @@ def test_cupy_broadcast_to():

assert a_b.shape == p_b.shape
assert (a_b == p_b).all()


def test_cupy_matmul():
cupy = pytest.importorskip("cupy")
a, b = cupy.arange(10), cupy.arange(10)
c = a @ b
assert c == proxy_object.asproxy(a) @ b
assert c == a @ proxy_object.asproxy(b)
assert c == proxy_object.asproxy(a) @ proxy_object.asproxy(b)


def test_cupy_imatmul():
cupy = pytest.importorskip("cupy")
a = cupy.arange(9).reshape(3, 3)
c = a.copy()
c @= a

a1 = a.copy()
a1 @= proxy_object.asproxy(a)
assert (a1 == c).all()

a2 = proxy_object.asproxy(a.copy())
a2 @= a
assert (a2 == c).all()