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

WIP: Simplify DeviceSerialized and usage thereof #268

Closed
Closed
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
30 changes: 8 additions & 22 deletions dask_cuda/device_host_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,24 @@ class DeviceSerialized:
that are in host memory
"""

def __init__(self, header, parts):
def __init__(self, header, frames):
self.header = header
self.parts = parts
self.frames = frames

def __sizeof__(self):
return sum(map(nbytes, self.parts))
return sum(map(nbytes, self.frames))


@dask_serialize.register(DeviceSerialized)
def device_serialize(obj):
headers = []
all_frames = []
for part in obj.parts:
header, frames = serialize(part)
header["frame-start-stop"] = [len(all_frames), len(all_frames) + len(frames)]
headers.append(header)
all_frames.extend(frames)

header = {"sub-headers": headers, "main-header": obj.header}

return header, all_frames
header = {"main-header": dict(obj.header)}
frames = list(obj.frames)
return header, frames


@dask_deserialize.register(DeviceSerialized)
def device_deserialize(header, frames):
parts = []
for sub_header in header["sub-headers"]:
start, stop = sub_header.pop("frame-start-stop")
part = deserialize(sub_header, frames[start:stop])
parts.append(part)

return DeviceSerialized(header["main-header"], parts)
return DeviceSerialized(header["main-header"], frames)


def device_to_host(obj: object) -> DeviceSerialized:
Expand All @@ -71,7 +57,7 @@ def device_to_host(obj: object) -> DeviceSerialized:


def host_to_device(s: DeviceSerialized) -> object:
return deserialize(s.header, s.parts)
return deserialize(s.header, s.frames)


class DeviceHostFile(ZictBase):
Expand Down