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

Task Fusion #113

Open
wants to merge 57 commits into
base: branch-24.03
Choose a base branch
from
Open
Changes from 4 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
8ff0261
task fusion and legality constraints
shivsundram Sep 27, 2021
4a9248f
makeshift serializer for inline ops
shivsundram Sep 27, 2021
99cd51c
reductions scalars, opids, need to remove dynamic allocations
shivsundram Sep 29, 2021
a4e21d8
fusion metadata passed via serialization now
shivsundram Sep 29, 2021
9b57fc8
remove redundant store partitioning
shivsundram Sep 30, 2021
bf7973a
remove creation of deferred arrays
shivsundram Oct 1, 2021
b6121e7
optimized packing, some transform packing
shivsundram Oct 1, 2021
e3708bf
more stuff
shivsundram Oct 4, 2021
8eca06f
partial fusion
Oct 14, 2021
dbf8ea9
merge attempt
Oct 14, 2021
a2c3874
second merge attempt
Oct 15, 2021
303866b
finishing merge
Oct 15, 2021
e8b9021
fix future stuff
Oct 15, 2021
7b0ee30
merge conflict
Oct 15, 2021
8238083
re add serializer, fix horrible merge bug
Oct 15, 2021
46856c7
debugging crap
Oct 22, 2021
6b4182b
trying merge
Oct 22, 2021
db65e43
op registry working
Oct 25, 2021
ddd8dc7
Change the pip package name to match the conda package and update ver…
marcinz Oct 27, 2021
ef677e6
Fix the version of Legion to a particular commit
marcinz Oct 28, 2021
ba955e2
Do not find a default branch for the release
marcinz Oct 28, 2021
de337cf
Change the Legion checkout target
marcinz Oct 28, 2021
78335cc
Bumped up the version of pyarrow
marcinz Oct 28, 2021
369909d
gpu descriptors
Nov 1, 2021
ab0c044
Remove back edges from partition symbols back to operations to avoid
magnatelee Nov 1, 2021
a9e1014
Merge branch 'branch-21.10' into cycle-fix
magnatelee Nov 1, 2021
54d3bb8
Make sure we don't create cycles between region fields and attachments
magnatelee Nov 1, 2021
dd46bdd
Merge pull request #84 from magnatelee/cycle-fix
magnatelee Nov 2, 2021
02103ad
Merge pull request #78 from lightsighter/interpreter-check
magnatelee Nov 3, 2021
d6ccdd2
Handle cases where one instance is used by multiple mappings
magnatelee Nov 3, 2021
94a1fba
Merge branch 'branch-21.10' into mapper-bug-fix
magnatelee Nov 3, 2021
12d13d1
Merge pull request #91 from magnatelee/mapper-bug-fix
magnatelee Nov 3, 2021
51dd00f
Fix import of legion CFFI
manopapad Nov 5, 2021
f348080
Merge pull request #97 from manopapad/fixinit
manopapad Nov 5, 2021
f388f07
Make sure we flush deferred detachments
magnatelee Nov 5, 2021
345f275
reduction fix
Nov 6, 2021
ab96ebc
Merge pull request #99 from magnatelee/detachment-fix
magnatelee Nov 6, 2021
1f9a655
put new constraint stuff back in
Nov 13, 2021
e2afa73
constant optimization
Nov 15, 2021
80aa90f
better constant opt
Nov 22, 2021
f9eb119
terminal dots
Nov 22, 2021
ba55358
useless merge
Nov 22, 2021
78366c8
merging new branch
Nov 22, 2021
f07381e
reuse partitions
Dec 1, 2021
ea12377
install.py
Dec 3, 2021
d7a8dab
new way of applying constraints
Dec 6, 2021
fe66dad
minor cleanup
Dec 7, 2021
a73dec1
more cleanup
Dec 7, 2021
437e67e
use alignment info when fusing
Dec 12, 2021
9594cb5
new apply methods
Dec 12, 2021
239ae35
removing serializer code
Dec 13, 2021
b49557b
more cleanup
Dec 13, 2021
e05e3ff
remove fusion reference from core
Dec 13, 2021
a59e142
remove comments
Dec 13, 2021
399d070
more cleanup
Dec 13, 2021
5bb4df5
partitioning fix
Apr 20, 2022
36c40cb
choose midpoint partition
Jun 14, 2022
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
13 changes: 9 additions & 4 deletions legate/core/constraints.py
Original file line number Diff line number Diff line change
@@ -55,8 +55,9 @@ def reduce(self):


class PartSym(Expr):
def __init__(self, op, store, id, disjoint, complete):
self._op = op
def __init__(self, op_hash, op_name, store, id, disjoint, complete):
self._op_hash = op_hash
self._op_name = op_name
self._store = store
self._id = id
self._disjoint = disjoint
@@ -66,17 +67,21 @@ def __init__(self, op, store, id, disjoint, complete):
def ndim(self):
return self._store.ndim

@property
def store(self):
return self._store

@property
def closed(self):
return False

def __repr__(self):
disj = "D" if self._disjoint else "A"
comp = "C" if self._complete else "I"
return f"X{self._id}({disj},{comp})@{self._op.get_name()}"
return f"X{self._id}({disj},{comp})@{self._op_name}"

def __hash__(self):
return hash((self._op, self._id))
return hash((self._op_hash, self._id))

def subst(self, mapping):
return Lit(mapping[self])
3 changes: 2 additions & 1 deletion legate/core/operation.py
Original file line number Diff line number Diff line change
@@ -158,7 +158,8 @@ def _get_symbol_id(self):

def declare_partition(self, store, disjoint=True, complete=True):
sym = PartSym(
self,
self._op_id,
self.get_name(),
store,
self._get_symbol_id(),
disjoint=disjoint,
60 changes: 45 additions & 15 deletions legate/core/runtime.py
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import gc
import math
import struct
import weakref
from collections import deque
from functools import reduce

@@ -319,11 +320,19 @@ def __init__(self, ptr, extent, region_field):
self.ptr = ptr
self.extent = extent
self.end = ptr + extent - 1
self.region_field = region_field
self._region_field = weakref.ref(region_field)

def overlaps(self, other):
return not (self.end < other.ptr or other.end < self.ptr)

@property
def region_field(self):
return self._region_field()

@region_field.setter
def region_field(self, region_field):
self._region_field = weakref.ref(region_field)


class AttachmentManager(object):
def __init__(self, runtime):
@@ -359,30 +368,55 @@ def attachment_key(alloc):

def has_attachment(self, alloc):
key = self.attachment_key(alloc)
return key in self._attachments
attachment = self._attachments.get(key, None)
return attachment is not None and attachment.region_field

def reuse_existing_attachment(self, alloc):
key = self.attachment_key(alloc)
if key not in self._attachments:
attachment = self._attachments.get(key, None)
if attachment is None:
return None
attachment = self._attachments[key]
return attachment.region_field
rf = attachment.region_field
# If the region field is already collected, we don't need to keep
# track of it for de-duplication.
if rf is None:
del self._attachments[key]
return rf

def attach_external_allocation(self, alloc, region_field):
key = self.attachment_key(alloc)
if key in self._attachments:
attachment = self._attachments.get(key, None)
if not (attachment is None or attachment.region_field is None):
raise RuntimeError(
"Cannot attach two different RegionFields to the same buffer"
)
attachment = Attachment(*key, region_field)
if attachment is None:
attachment = Attachment(*key, region_field)
else:
attachment.region_field = region_field
# We temporary remove the attachment from the map for
# the following alias checking
del self._attachments[key]
for other in self._attachments.values():
if other.overlaps(attachment):
raise RuntimeError(
"Aliased attachments not supported by Legate"
)
self._attachments[key] = attachment

def detach_external_allocation(self, alloc, detach, defer):
def _remove_allocation(self, alloc):
key = self.attachment_key(alloc)
if key not in self._attachments:
raise RuntimeError("Unable to find attachment to remove")
del self._attachments[key]

def detach_external_allocation(
self, alloc, detach, defer=False, previously_deferred=False
):
# If the detachment was previously deferred, then we don't
# need to remove the allocation from the map again.
if not previously_deferred:
self._remove_allocation(alloc)
if defer:
# If we need to defer this until later do that now
self._deferred_detachments.append((alloc, detach))
@@ -391,12 +425,6 @@ def detach_external_allocation(self, alloc, detach, defer):
# Dangle a reference to the field off the future to prevent the
# field from being recycled until the detach is done
future.field_reference = detach.field
# We also need to tell the core legate library that this buffer
# is no longer attached
key = self.attachment_key(alloc)
if key not in self._attachments:
raise RuntimeError("Unable to find attachment to remove")
del self._attachments[key]
# If the future is already ready, then no need to track it
if future.is_ready():
return
@@ -417,7 +445,9 @@ def perform_detachments(self):
detachments = self._deferred_detachments
self._deferred_detachments = list()
for alloc, detach in detachments:
self.detach_external_allocation(alloc, detach, defer=False)
self.detach_external_allocation(
alloc, detach, defer=False, previously_deferred=True
)

def prune_detachments(self):
to_remove = []
18 changes: 9 additions & 9 deletions legate/core/solver.py
Original file line number Diff line number Diff line change
@@ -114,16 +114,16 @@ def launch_domain(self):

def get_projection(self, part):
partition = self.get_partition(part)
return partition.get_requirement(self._launch_shape, part._store)
return partition.get_requirement(self._launch_shape, part.store)

def get_partition(self, part):
assert not part._store.unbound
assert not part.store.unbound
if part not in self._strategy:
raise ValueError(f"No strategy is found for {part}")
return self._strategy[part]

def get_field_space(self, part):
assert part._store.unbound
assert part.store.unbound
if part not in self._fspaces:
raise ValueError(f"No strategy is found for {part}")
return self._fspaces[part]
@@ -160,7 +160,7 @@ def _solve_broadcast_constraints(
):
to_remove = OrderedSet()
for unknown in unknowns:
store = unknown._store
store = unknown.store
if not (store.kind is Future or unknown in broadcasts):
continue

@@ -183,7 +183,7 @@ def _solve_unbound_constraints(
):
to_remove = OrderedSet()
for unknown in unknowns:
store = unknown._store
store = unknown.store
if not store.unbound:
continue

@@ -193,7 +193,7 @@ def _solve_unbound_constraints(
continue

cls = constraints.find(unknown)
assert all(to_align._store.unbound for to_align in cls)
assert all(to_align.store.unbound for to_align in cls)

fspace = self._runtime.create_field_space()
for to_align in cls:
@@ -206,7 +206,7 @@ def _solve_unbound_constraints(
def _find_restrictions(cls):
merged = None
for unknown in cls:
store = unknown._store
store = unknown.store
restrictions = store.find_restrictions()
if merged is None:
merged = restrictions
@@ -268,7 +268,7 @@ def partition_stores(self):
all_restrictions = self._find_all_restrictions(unknowns, constraints)

def cost(unknown):
store = unknown._store
store = unknown.store
return (
-store.comm_volume(),
not store.has_key_partition(all_restrictions[unknown]),
@@ -284,7 +284,7 @@ def cost(unknown):
elif unknown in dependent:
continue

store = unknown._store
store = unknown.store
restrictions = all_restrictions[unknown]

if isinstance(prev_part, NoPartition):