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

New dependency finding #683

Closed
wants to merge 21 commits into from
Closed

Conversation

a-alveyblanc
Copy link
Contributor

No description provided.

@a-alveyblanc a-alveyblanc changed the title Temp commit New dependency finding Sep 26, 2022
a-alveyblanc and others added 4 commits October 1, 2022 21:04
- Changed function that generates access relations.
  (`generate_access_relations()`)
- Changed function that generates dependency relations.
  (`generate_dependency_relations()`)
- Added data classes that store information relevant to.
    - (`RelationInfo`, `AccessRelation(RelationInfo)`,
      `DependencyRelation(RelationInfo)`
Copy link
Owner

@inducer inducer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! Looks great, just a few comments below.

@@ -80,6 +80,20 @@ class _BoundsRecord:
upper_bound_pw_aff: isl.PwAff
size: isl.PwAff

@dataclass(frozen=True)
class RelationInfo:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add docstrings, specifying what variables are in the map, what the two ends of the map mean, what naming conventions are used.

@@ -80,6 +80,20 @@ class _BoundsRecord:
upper_bound_pw_aff: isl.PwAff
size: isl.PwAff

@dataclass(frozen=True)
class RelationInfo:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add into documentation.

Comment on lines 89 to 91
@dataclass(frozen=True)
class AccessRelation(RelationInfo):
access_type: str
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this want to be an enum?

relation: isl.Map

@dataclass(frozen=True)
class AccessRelation(RelationInfo):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should access relations be long-lived?

relation: isl.Map

@dataclass(frozen=True)
class AccessRelation(RelationInfo):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"has-a happier than is-a"

@@ -640,6 +654,81 @@ def _remove_inames_for_shared_hw_axes(self, cond_inames):

# {{{ dependency wrangling

def generate_access_relations(self):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def generate_access_relations(self):
def generate_access_relations(self) -> ...:

for insn in self.instructions:
for relation in write_read:
if relation.dependent_id == insn.id:
insn.update_depends_on(relation.insn_id)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
insn.update_depends_on(relation.insn_id)
insn = insn.copy(depends_on=...)

Comment on lines 698 to 699
for read in read_maps
if write.var_name == read.var_name]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary quadratic complexity?

Comment on lines 729 to 730
def dep_finder(self):
pass
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#self_dependency = x.relation.apply_range(x.relation.reverse())

dependency_relation = x.relation.apply_range(y.relation.reverse())
#dependency_relation -= self_dependency
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subtract the diagonal instead: $\{[i,j] \to [i',j']: i=i' \land j=j'\}$

Comment on lines 48 to 50
variable_name: str
relation: isl.Map
dependency_type: DependencyType
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
variable_name: str
relation: isl.Map
dependency_type: DependencyType
variable_name: Optional[str]
relation: isl.Map
dependency_type: Optional[DependencyType]

(But probably better to make a data-mediated dependency a separate type, maybe a subclass.)

Comment on lines 13 to 15
WRITE_READ = 0
READ_WRITE = 1
WRITE_WRITE = 2
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
WRITE_READ = 0
READ_WRITE = 1
WRITE_WRITE = 2
WRITE_AFTER_READ = 0
READ_AFTER_WRITE = 1
WRITE_AFTER_WRITE = 2

from dataclasses import dataclass
from enum import Enum

class DependencyType(Enum):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure whether we'll want this, or whether we'll want all those union'd together.

dependency_type: DependencyType

@dataclass(frozen=True)
class AccessRelation:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class AccessRelation:
class _AccessRelation:

Comment on lines 174 to 179
union_of_dependencies = None
for rel in write_read:
if union_of_dependencies is None:
union_of_dependencies = rel.relation
else:
union_of_dependencies = union_of_dependencies | rel.relation
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functools.reduce

domain: isl.BasicSet = knl.get_inames_domain(insn.within_inames)
insn_order: isl.Map = domain.lex_lt_set(domain)

# v FIXME: there must be a better way
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think about transitive dependencies.


for insn in knl.instructions:
domain: isl.BasicSet = knl.get_inames_domain(insn.within_inames)
insn_order: isl.Map = domain.lex_lt_set(domain)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't start from lexicographic, but rather from an already-existing happens-before.

:returns: True or false depending on whether the provided execution order
respects the dependencies in the loopy program.
"""
pass
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at James's prior work.

insn_order = insn_order & union_of_dependencies
execution_order = execution_order | frozenset({insn_order})

return execution_order
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this into the LoopKernel data structure.

given kernel transformation respects the data dependencies in a given
program.

.. attribute:: happens_before
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. attribute:: happens_before
.. attribute:: after_id

from dataclasses import dataclass

@dataclass(frozen=True)
class HappensBefore:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class HappensBefore:
class HappensAfter:

@a-alveyblanc a-alveyblanc mentioned this pull request Nov 14, 2022
@inducer
Copy link
Owner

inducer commented Nov 14, 2022

Does #704 supersede this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants