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

Periodically flush region managers in the LRU queue #395

Open
wants to merge 1 commit into
base: branch-24.03
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions legate/core/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,8 @@ def get_cpu_communicator(self) -> Communicator:
class Runtime:
_legion_runtime: Union[legion.legion_runtime_t, None]
_legion_context: Union[legion.legion_context_t, None]
# TODO: do we want this to be configurable?
_LRU_FLUSH_THRESHOLD: int = 10

def __init__(self, core_library: CoreLib) -> None:
"""
Expand Down Expand Up @@ -940,6 +942,7 @@ def __init__(self, core_library: CoreLib) -> None:
self.region_managers_by_region: dict[Region, RegionManager] = {}
# LRU for free region managers
self.lru_managers: Deque[RegionManager] = deque()
self.lru_flush_counter: int = 0
# map from (shape,dtype) to field managers
self.field_managers: dict[tuple[Shape, Any], FieldManager] = {}

Expand Down Expand Up @@ -1081,6 +1084,7 @@ def destroy(self) -> None:
# Remove references to our legion resources so they can be collected
self.active_region_managers = {}
self.region_managers_by_region = {}
self.lru_managers = deque()
self.field_managers = {}
self.index_spaces = {}

Expand Down Expand Up @@ -1245,6 +1249,15 @@ def find_region_manager(self, region: Region) -> RegionManager:
assert region in self.region_managers_by_region
return self.region_managers_by_region[region]

def flush_unused_region_managers(self) -> None:
self.lru_flush_counter += 1

if self.lru_flush_counter > self._LRU_FLUSH_THRESHOLD:
for region_mgr in self.lru_managers:
self.destroy_region_manager(region_mgr, False)
self.lru_managers = deque()
self.lru_flush_counter = 0

def revive_manager(self, region_mgr: RegionManager) -> None:
lru_managers: Deque[RegionManager] = deque()
for to_check in self.lru_managers:
Expand Down Expand Up @@ -1312,6 +1325,11 @@ def allocate_field(self, shape: Shape, dtype: Any) -> RegionField:
field_id = None
field_mgr = self.find_or_create_field_manager(shape, dtype.size)
region, field_id = field_mgr.allocate_field()

# After allocating fields for an enough number of times,
# flush any region managers that are still unused
self.flush_unused_region_managers()

return RegionField.create(region, field_id, dtype.size, shape)

def free_field(
Expand Down