Skip to content

Commit

Permalink
remove get_dev_buffer_to_proxies()
Browse files Browse the repository at this point in the history
  • Loading branch information
madsbk committed Nov 1, 2021
1 parent fdf02ff commit 572c9b7
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions dask_cuda/proxify_host_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,32 +285,35 @@ def proxify(self, obj: object) -> object:
self.maybe_evict()
return ret

def get_dev_buffer_to_proxies(self) -> DefaultDict[Hashable, List[ProxyObject]]:
def get_dev_access_info(self) -> List[Tuple[float, int, List[ProxyObject]]]:
"""Return a list of device buffers packed with associated info like:
`[(<access-time>, <size-of-buffer>, <list-of-proxies>), ...]
"""
with self.lock:
# Notice, multiple proxy object can point to different non-overlapping
# parts of the same device buffer.
ret = defaultdict(list)
# Map device buffers to proxy objects. Note, multiple proxy object can
# point to different non-overlapping parts of the same device buffer.
buffer_to_proxies = defaultdict(list)
for proxy in self._dev.get_proxies():
for dev_buffer in proxy._pxy_get_device_memory_objects():
ret[dev_buffer].append(proxy)
return ret
for buffer in proxy._pxy_get_device_memory_objects():
buffer_to_proxies[buffer].append(proxy)

def get_dev_access_info(self) -> List[Tuple[float, int, List[ProxyObject]]]:
with self.lock:
dev_buf_access = []
for dev_buf, proxies in self.get_dev_buffer_to_proxies().items():
ret = []
for dev_buf, proxies in buffer_to_proxies.items():
last_access = max(p._pxy_get().last_access for p in proxies)
size = sizeof(dev_buf)
dev_buf_access.append((last_access, size, proxies))
return dev_buf_access
ret.append((last_access, size, proxies))
return ret

def get_host_access_info(self) -> List[Tuple[float, int, List[ProxyObject]]]:
"""Return a list of device buffers packed with associated info like:
`[(<access-time>, <size-of-buffer>, <list-of-proxies>), ...]
"""
with self.lock:
access_info = []
ret = []
for p in self._host.get_proxies():
size = sizeof(p)
access_info.append((p._pxy_get().last_access, size, [p]))
return access_info
ret.append((p._pxy_get().last_access, size, [p]))
return ret

def evict(
self,
Expand All @@ -330,9 +333,10 @@ def evict(
Number of bytes to evict.
proxies_access: callable
Function that returns a list of proxies pack in a tuple like:
`[(<access-time>, <size-of-proxy>, proxies), ...]
`[(<access-time>, <size-of-buffer>, <list-of-proxies>), ...]
serializer: callable
Function that serialize the given proxy object.
Return
------
nbytes: int
Expand All @@ -358,6 +362,11 @@ def evict(
return freed_memory

def maybe_evict_from_device(self, extra_dev_mem=0) -> None:
"""Evict buffers until total memory usage is below device-memory-limit
Adds `extra_dev_mem` to the current total memory usage when comparing
against device-memory-limit.
"""
mem_over_usage = (
self._dev.mem_usage() + extra_dev_mem - self._device_memory_limit
)
Expand All @@ -369,6 +378,11 @@ def maybe_evict_from_device(self, extra_dev_mem=0) -> None:
)

def maybe_evict_from_host(self, extra_host_mem=0) -> None:
"""Evict buffers until total memory usage is below host-memory-limit
Adds `extra_host_mem` to the current total memory usage when comparing
against device-memory-limit.
"""
mem_over_usage = (
self._host.mem_usage() + extra_host_mem - self._host_memory_limit
)
Expand Down

0 comments on commit 572c9b7

Please sign in to comment.