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

Check new dependencies against SIO #264

Open
wants to merge 96 commits into
base: statement-instance-order-and-lex-order-map
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
cd59be5
add dependencies attribute to instruction (copying in changes from do…
jdsteve2 Apr 2, 2021
c03636d
create function to add new dependencies, add_stmt_inst_dependency() (…
jdsteve2 Apr 2, 2021
8a2e7ff
create function to ensure linearization satisfies deps, check_lineari…
jdsteve2 Apr 2, 2021
10f2ff5
make check_linearization_validity() and add_stmt_inst_dependency() gl…
jdsteve2 Apr 2, 2021
a4deb28
create test for adding dependencies to statements (copying in changes…
jdsteve2 Apr 2, 2021
b62e109
rename check_linearization_validity()->check_dependency_satisfaction()
jdsteve2 Apr 2, 2021
0f48ba6
fixing merge conflicts
jdsteve2 Apr 5, 2021
a6feb6d
return info about unsatisfied deps from check_dependency_satisfaction…
jdsteve2 Apr 5, 2021
daedf10
rename check_dependency_satisfaction()->find_unsatisfied_dependencies…
jdsteve2 Apr 5, 2021
bfa61f0
fix merge conflicts
jdsteve2 Apr 5, 2021
0446d3d
renaming instruction->statement
jdsteve2 Apr 5, 2021
03fa0c9
add update_for_Map to LoopyKeyBuilder
jdsteve2 Apr 5, 2021
3b990b0
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Apr 5, 2021
50332c3
change BEFORE_MARK to underscore since ISL ignores apostrophes; now c…
jdsteve2 Apr 5, 2021
31783ee
add todo
jdsteve2 Apr 9, 2021
da77260
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Apr 11, 2021
82670e8
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Apr 14, 2021
f42f2ac
switch BEFORE_MARK back to apostrophe now that isl can handle it duri…
jdsteve2 Apr 14, 2021
a202ffe
fix doctest after projecting out unused inames from sched dims
jdsteve2 Apr 14, 2021
5206882
add test for dep checking with finite differences dependency example,…
jdsteve2 Apr 14, 2021
988041e
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Apr 15, 2021
1b61319
add docstring for find_unsatisfied_dependencies()
jdsteve2 Apr 15, 2021
00d9737
add docstring to add_stmt_inst_dependency()
jdsteve2 Apr 15, 2021
887f64e
add dependencies attribute to docstring for InstructionBase; handle d…
jdsteve2 Apr 15, 2021
8cc3545
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Apr 17, 2021
e2d8477
fixing merge conflicts
jdsteve2 Apr 17, 2021
e796475
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Apr 23, 2021
bc1c27b
rename add_stmt_inst_dependency->add_dependency_v2
jdsteve2 Apr 23, 2021
28a01b4
fix merge conflicts
jdsteve2 Apr 25, 2021
1615991
reduce duplicated code in tests by using _process_and_linearize(knl) …
jdsteve2 Apr 25, 2021
1109b1a
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Apr 26, 2021
520d1ac
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Apr 27, 2021
9c8901b
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 May 23, 2021
48b4dfb
make helper function for dep creation that adds marks and inserts sta…
jdsteve2 May 23, 2021
36793bd
use make_dep_map() instead of _isl_map_with_marked_dims (still need t…
jdsteve2 May 23, 2021
ec3185d
allow dep checking to work if lin_items is not provided
jdsteve2 May 27, 2021
f17f282
make sure dep checking works even when linearization items are not pr…
jdsteve2 May 27, 2021
77bed8f
add TODO
jdsteve2 Jun 2, 2021
493c8e8
make make_dep_map smart enough to get relevant iname domains from ker…
jdsteve2 Jun 2, 2021
d7e9342
some initial tests for make_dep_map
jdsteve2 Jun 2, 2021
83e35d3
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Jun 6, 2021
fb4c43d
fix make_dep_map so it handles automatic domain creation correctly wh…
jdsteve2 Jun 6, 2021
473116c
add dedicated test for make_dep_map
jdsteve2 Jun 6, 2021
871ccae
don't check deps on/by barriers at the moment
jdsteve2 Jun 10, 2021
a8ec66d
set obj_bigger_ok=True when aligning inames domain with dep in make_d…
jdsteve2 Jun 10, 2021
71c93b1
fix merge conflicts
jdsteve2 Jul 15, 2021
31718ae
after callables update, use knl[loopy_kernel] where needed
jdsteve2 Jul 15, 2021
150576a
use @for_each_kernel with add_dependency_v2
jdsteve2 Jul 15, 2021
39a8429
fixing merge conflict
jdsteve2 Jul 19, 2021
d46cf80
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Jul 19, 2021
139fa2c
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Jul 20, 2021
1d61ecf
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Jul 20, 2021
f0e90d1
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Jul 23, 2021
d94cfa4
for some reason, I need to commit 'changes' to the submodule (but did…
jdsteve2 Jul 26, 2021
215fc1c
clarify docstring for new dependencies
jdsteve2 Aug 2, 2021
0f85942
update docstring for find_unsatisfied_dependencies and clarify commen…
jdsteve2 Aug 2, 2021
011ffd5
when checking dependencies, don't ignore dependencies on/by barrier s…
jdsteve2 Aug 2, 2021
2cddff9
document and clean up make_dep_map
jdsteve2 Aug 2, 2021
516a7d0
clean up add_dependency
jdsteve2 Aug 2, 2021
77e031c
one more test for make_dep_map; clean up dep checking tests
jdsteve2 Aug 2, 2021
63a4c39
add 'returns' to docstring for add_dependency_v2
jdsteve2 Aug 2, 2021
e0d601a
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Aug 13, 2021
56d51ba
use dim_type to abbreviate isl.dim_type class and dt to refer to a pa…
jdsteve2 Aug 13, 2021
78a3236
fix merge conflicts
jdsteve2 Sep 13, 2021
9d03f63
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Sep 13, 2021
ead908b
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Sep 15, 2021
19e51d9
improve comment
jdsteve2 Sep 15, 2021
70c9bb3
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Sep 15, 2021
4f47cce
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Sep 15, 2021
d3b6079
eliminate duplicated code in subtraction map creation by adding funct…
jdsteve2 Sep 16, 2021
eb58df3
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Sep 16, 2021
4392849
fix merge conflicts
jdsteve2 Sep 16, 2021
2139ec8
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Sep 16, 2021
9d740ff
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Sep 16, 2021
67b52e4
fix weird merging issue
jdsteve2 Sep 16, 2021
8d64b2b
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Sep 16, 2021
883df76
revise docstring for dependencies attribute of instruction
jdsteve2 Sep 17, 2021
2ba8a2a
revise docstring for dependencies attribute of instruction
jdsteve2 Sep 17, 2021
fef6322
handle dependencies in instruction.__setstate__
jdsteve2 Sep 17, 2021
cb52c10
combine add_dependency_v2 with add_dependency by accepting a two-tupl…
jdsteve2 Sep 17, 2021
fea47e8
remove add_dependency_v2 from imports
jdsteve2 Sep 17, 2021
b05d5de
placate flake8
jdsteve2 Sep 17, 2021
a44e4b6
more details in docstring for stmt.dependencies attribute
jdsteve2 Sep 17, 2021
c0890f5
add stop_on_first_violation arg to find_unsatisfied_dependencies()
jdsteve2 Sep 17, 2021
73f832c
add FIXME about potentially checking individual parts of deps/sios
jdsteve2 Sep 17, 2021
539c39c
add helpful comments/docstrings to dependency checking test functions
jdsteve2 Sep 17, 2021
c7b3d18
also describe statement dims of instruction.dependencies attribute
jdsteve2 Sep 17, 2021
b151403
add get_pairwise_statement_orderings to loopy.__init__
jdsteve2 Sep 17, 2021
d99d8ba
add new dep checking stuff to documentation
jdsteve2 Sep 17, 2021
08cc0a9
fix merge conflicts
jdsteve2 Sep 17, 2021
ab55b38
fix merge conflicts
jdsteve2 Sep 17, 2021
f147478
fix merge conflicts
jdsteve2 Sep 17, 2021
7755f6a
add autofunction find_unsatisfied_deps
jdsteve2 Sep 17, 2021
68a242f
Fix up schedule checker docs
inducer Sep 17, 2021
206b41a
Merge branch 'statement-instance-order-and-lex-order-map' into check-…
jdsteve2 Sep 17, 2021
a887ff2
fix reference in docstrings loopy.kernel.LoopKernel->loopy.LoopKernel
jdsteve2 Sep 17, 2021
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
2 changes: 2 additions & 0 deletions doc/ref_other.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Automatic Testing
Checking Dependencies at the Statement-Instance Level
-----------------------------------------------------

See also :func:`~loopy.add_dependency` for how to add dependencies.

.. automodule:: loopy.schedule.checker

Troubleshooting
Expand Down
10 changes: 7 additions & 3 deletions loopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@

from loopy.transform.instruction import (
find_instructions, map_instructions,
set_instruction_priority, add_dependency,
set_instruction_priority,
add_dependency,
remove_instructions,
replace_instruction_ids,
tag_instructions,
Expand Down Expand Up @@ -131,7 +132,8 @@
get_one_linearized_kernel, linearize)
from loopy.schedule.checker import (
get_pairwise_statement_orderings,
)
find_unsatisfied_dependencies,
)
from loopy.statistics import (ToCountMap, ToCountPolynomialMap, CountGranularity,
stringify_stats_mapping, Op, MemAccess, get_op_map, get_mem_access_map,
get_synchronization_map, gather_access_footprints,
Expand Down Expand Up @@ -215,7 +217,8 @@
"rename_argument", "set_temporary_scope",

"find_instructions", "map_instructions",
"set_instruction_priority", "add_dependency",
"set_instruction_priority",
"add_dependency",
"remove_instructions",
"replace_instruction_ids",
"tag_instructions",
Expand Down Expand Up @@ -272,6 +275,7 @@
"get_one_scheduled_kernel", "get_one_linearized_kernel",
"linearize",
"get_pairwise_statement_orderings",
"find_unsatisfied_dependencies",

"GeneratedProgram", "CodeGenerationResult",
"PreambleInfo",
Expand Down
89 changes: 79 additions & 10 deletions loopy/kernel/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class UseStreamingStoreTag(Tag):
# {{{ instructions: base class

class InstructionBase(ImmutableRecord, Taggable):
"""A base class for all types of instruction that can occur in
r"""A base class for all types of instruction that can occur in
a kernel.

.. attribute:: id
Expand All @@ -87,7 +87,7 @@ class InstructionBase(ImmutableRecord, Taggable):

.. attribute:: depends_on

a :class:`frozenset` of :attr:`id` values of :class:`InstructionBase`
A :class:`frozenset` of :attr:`id` values of :class:`InstructionBase`
instances that *must* be executed before this one. Note that
:func:`loopy.preprocess_kernel` (usually invoked automatically)
augments this by adding dependencies on any writes to temporaries read
Expand All @@ -106,6 +106,40 @@ class InstructionBase(ImmutableRecord, Taggable):
:func:`loopy.make_kernel`. Note, that this is not meant as a user-facing
interface.

.. attribute:: dependencies

A :class:`dict` mapping :attr:`id` values
instances, each referring to a dependee statement (i.e., a statement
with statement instances that must be executed before instances of this
statement), to lists (one list per key) of class:`islpy.Map`\ s that
express dependency relationships by mapping each instance of the
dependee statement to all instances of this statement that must occur
later.

The name of the first dimension in the `in_` and `out` spaces must be
:data:`loopy.schedule.checker.schedule.STATEMENT_VAR_NAME`, suffixed by
:data:`loopy.schedule.checker.schedule.BEFORE_MARK` for the `in_`
dimension. This dimension in the `in_` space must be assigned the value
0, and in the `out` space it must be assigned 0 for self-dependencies
(dependencies describing instances of a statement that must happen
before other instances of the same statement) and 1 otherwise.

In addition to the statement dimension, the `in_` space of a dependency
map must contain one dimension per iname in :attr:`within_inames` for
the dependee, and the `out` space must contain one dimension per iname
in :attr:`within_inames` for this statement. The dimension names should
match the corresponding iname, with those in the `in_` space suffixed
by :data:`loopy.schedule.checker.schedule.BEFORE_MARK`. Reduction
inames are not considered (for now). Only dependencies involving
instances of statements within the domain on either end of the map are
expected to be represented.

Creation of these maps may be facilitated with
:func:`loopy.schedule.checker.utils.make_dep_map`.

This dict expresses the new statement-instance-level dependencies and
will eventually replace :attr:`depends_on`.

.. attribute:: depends_on_is_final

A :class:`bool` determining whether :attr:`depends_on` constitutes
Expand Down Expand Up @@ -212,6 +246,7 @@ class InstructionBase(ImmutableRecord, Taggable):
pymbolic_set_fields = {"predicates"}

def __init__(self, id, depends_on, depends_on_is_final,
dependencies,
groups, conflicts_with_groups,
no_sync_with,
within_inames_is_final, within_inames,
Expand Down Expand Up @@ -241,6 +276,9 @@ def __init__(self, id, depends_on, depends_on_is_final,
if depends_on is None:
depends_on = frozenset()

if dependencies is None:
dependencies = {}

if groups is None:
groups = frozenset()

Expand Down Expand Up @@ -297,6 +335,7 @@ def __init__(self, id, depends_on, depends_on_is_final,
id=id,
depends_on=depends_on,
depends_on_is_final=depends_on_is_final,
dependencies=dependencies,
no_sync_with=no_sync_with,
groups=groups, conflicts_with_groups=conflicts_with_groups,
within_inames_is_final=within_inames_is_final,
Expand Down Expand Up @@ -392,6 +431,8 @@ def get_str_options(self):

if self.depends_on:
result.append("dep="+":".join(self.depends_on))
if self.dependencies:
result.append("dependencies="+":".join(self.dependencies.keys()))
if self.no_sync_with:
result.append("nosync="+":".join(
"%s@%s" % entry for entry in self.no_sync_with))
Expand Down Expand Up @@ -461,6 +502,9 @@ def __setstate__(self, val):
if self.id is not None: # pylint:disable=access-member-before-definition
self.id = intern(self.id)
self.depends_on = intern_frozenset_of_ids(self.depends_on)
self.dependencies = {
intern(dependee_id): deps
for dependee_id, deps in self.dependencies.items()}
self.groups = intern_frozenset_of_ids(self.groups)
self.conflicts_with_groups = (
intern_frozenset_of_ids(self.conflicts_with_groups))
Expand Down Expand Up @@ -887,6 +931,7 @@ def __init__(self,
id=None,
depends_on=None,
depends_on_is_final=None,
dependencies=None,
groups=None,
conflicts_with_groups=None,
no_sync_with=None,
Expand All @@ -903,6 +948,7 @@ def __init__(self,
id=id,
depends_on=depends_on,
depends_on_is_final=depends_on_is_final,
dependencies=dependencies,
groups=groups,
conflicts_with_groups=conflicts_with_groups,
no_sync_with=no_sync_with,
Expand Down Expand Up @@ -1038,6 +1084,7 @@ def __init__(self,
id=None,
depends_on=None,
depends_on_is_final=None,
dependencies=None,
groups=None,
conflicts_with_groups=None,
no_sync_with=None,
Expand All @@ -1051,6 +1098,7 @@ def __init__(self,
id=id,
depends_on=depends_on,
depends_on_is_final=depends_on_is_final,
dependencies=dependencies,
groups=groups,
conflicts_with_groups=conflicts_with_groups,
no_sync_with=no_sync_with,
Expand Down Expand Up @@ -1331,6 +1379,7 @@ def __init__(self,
iname_exprs, code,
read_variables=frozenset(), assignees=tuple(),
id=None, depends_on=None, depends_on_is_final=None,
dependencies=None,
groups=None, conflicts_with_groups=None,
no_sync_with=None,
within_inames_is_final=None, within_inames=None,
Expand All @@ -1350,6 +1399,7 @@ def __init__(self,
id=id,
depends_on=depends_on,
depends_on_is_final=depends_on_is_final,
dependencies=dependencies,
groups=groups, conflicts_with_groups=conflicts_with_groups,
no_sync_with=no_sync_with,
within_inames_is_final=within_inames_is_final,
Expand Down Expand Up @@ -1495,16 +1545,25 @@ class NoOpInstruction(_DataObliviousInstruction):
... nop
"""

def __init__(self, id=None, depends_on=None, depends_on_is_final=None,
groups=None, conflicts_with_groups=None,
def __init__(
self,
id=None,
depends_on=None,
depends_on_is_final=None,
dependencies=None,
groups=None,
conflicts_with_groups=None,
no_sync_with=None,
within_inames_is_final=None, within_inames=None,
within_inames_is_final=None,
within_inames=None,
priority=None,
predicates=None, tags=None):
predicates=None,
tags=None):
super().__init__(
id=id,
depends_on=depends_on,
depends_on_is_final=depends_on_is_final,
dependencies=dependencies,
groups=groups,
conflicts_with_groups=conflicts_with_groups,
no_sync_with=no_sync_with,
Expand Down Expand Up @@ -1554,12 +1613,21 @@ class BarrierInstruction(_DataObliviousInstruction):
fields = _DataObliviousInstruction.fields | {"synchronization_kind",
"mem_kind"}

def __init__(self, id, depends_on=None, depends_on_is_final=None,
groups=None, conflicts_with_groups=None,
def __init__(
self,
id,
depends_on=None,
depends_on_is_final=None,
dependencies=None,
groups=None,
conflicts_with_groups=None,
no_sync_with=None,
within_inames_is_final=None, within_inames=None,
within_inames_is_final=None,
within_inames=None,
priority=None,
predicates=None, tags=None, synchronization_kind="global",
predicates=None,
tags=None,
synchronization_kind="global",
mem_kind="local"):

if predicates:
Expand All @@ -1569,6 +1637,7 @@ def __init__(self, id, depends_on=None, depends_on_is_final=None,
id=id,
depends_on=depends_on,
depends_on_is_final=depends_on_is_final,
dependencies=dependencies,
groups=groups,
conflicts_with_groups=conflicts_with_groups,
no_sync_with=no_sync_with,
Expand Down
Loading