Conversation
7b09146 to
fe827e4
Compare
|
Is this going in the direction you had in mind @inducer ? |
ae1f27a to
e41625f
Compare
e41625f to
9233385
Compare
loopy/statistics.py
Outdated
| opmap = self.rec(expr.expr) | ||
| for op in opmap.count_map: | ||
| op.tags = expr.tags | ||
| return opmap |
There was a problem hiding this comment.
Would overwrite tags of subexpressions that already have tags.
self.rec(expr.expr, expr.tags)
loopy/statistics.py
Outdated
| map_bitwise_and = map_bitwise_or | ||
|
|
||
| def map_if(self, expr): | ||
| def map_if(self, expr, *args): |
There was a problem hiding this comment.
In 0bbbaec, I changed all occurrences to tags (with a default argument). Does this look reasonable?
|
Unsubscribing... @-mention or request review once it's ready for a look or needs attention. |
|
This is ready for a first look @inducer. |
loopy/statistics.py
Outdated
| return sum(values) | ||
|
|
||
| def map_constant(self, expr): | ||
| def map_constant(self, expr, tags=None): |
There was a problem hiding this comment.
Why the pervasive tags=None? The default risks losing the tag as you traverse. IMO, there should not be a default.
There was a problem hiding this comment.
I changed it in df7ed9b to not use a default argument anymore.
loopy/statistics.py
Outdated
|
|
||
| def map_comparison(self, expr): | ||
| return self.rec(expr.left)+self.rec(expr.right) | ||
| def map_comparison(self, expr, *args): |
There was a problem hiding this comment.
Why have *args instead of tags here?
There was a problem hiding this comment.
These are hopefully all fixed in df7ed9b
9b12a27 to
c67eea6
Compare
8dcf1d4 to
c3b4a82
Compare
Co-authored-by: Andreas Klöckner <inform@tiker.net>
|
I think this is ready for another review. |
inducer
left a comment
There was a problem hiding this comment.
Thanks! This is quite close, only a few minor wrinkles to finish up.
| count_granularity=local_mem_count_granularity, | ||
| kernel_name=self.knl.name): self.one}) | ||
|
|
||
| elif (isinstance(array, TemporaryVariable) and ( |
There was a problem hiding this comment.
Should this also apply to ArrayArg? / Where do those get counted if not?
There was a problem hiding this comment.
Doesn't it already apply to ArrayArg (see 2 lines below)?
loopy/statistics.py
Outdated
| @property | ||
| def mtype(self) -> str: | ||
| from warnings import warn | ||
| warn("MemAccess.mtype is deprecated and will stop working in 2024. " |
There was a problem hiding this comment.
Bump deadlines to 2026? (here and elsewhere)
|
|
||
| # {{{ CounterBase | ||
|
|
||
| class CounterBase(CombineMapper): |
loopy/symbolic.py
Outdated
| .. attribute:: tags | ||
|
|
||
| A :class:`frozenset` of subclasses of :class:`pytools.tag.Tag` used to | ||
| provide metadata on this expression. | ||
|
|
||
| .. attribute:: expr | ||
|
|
||
| An expression to which :attr:`tags` are attached. | ||
| """ | ||
|
|
||
| tags: frozenset[Tag] | ||
| expr: Expression |
There was a problem hiding this comment.
Have this use autoattribute, move docstrings after declaration.
|
|
||
| @dataclass(frozen=True, eq=True) | ||
| class MemAccess: | ||
| """A descriptor for a type of memory access. |
There was a problem hiding this comment.
Move to autoattribute and in-line docstrings?
| # {{{ Op descriptor | ||
|
|
||
| class Op(ImmutableRecord): | ||
| class OpType(Enum): |
There was a problem hiding this comment.
Move to autoattribute and in-line docstrings?
There was a problem hiding this comment.
The semantics of tagging in connection with counting need to be explained somewhere in the documentation.
Co-authored-by: Andreas Klöckner <inform@tiker.net>
Co-authored-by: Andreas Klöckner <inform@tiker.net>
|
I can't get this to work with pytato: import numpy as np
import pytato as pt
import loopy as lp
from pytools.tag import Tag
class FooTag(Tag):
pass
a = pt.make_placeholder(name="a", shape=(10, 10), dtype=np.float64)
a2 = a + a
result = pt.make_dict_of_named_arrays({"aout": a2.tagged(FooTag())})
prg = pt.generate_loopy(result)
op_map = lp.get_op_map(prg.program, subgroup_size=32)
print("UNFILTERED", op_map)
print("FILTERED", op_map.filter_by(tags=[frozenset((FooTag(),))]))
print(prg.program)$ python examples/demo.py
/Users/mdiener/Work/emirge/loopy/loopy/statistics.py:1801: LoopyWarning: in kernel _pt_kernel: get_insn_count: when counting instruction aout_store with count_granularity=CountGranularity.SUBGROUP, using upper bound for work-group size (1 work-items) to compute sub-groups per work-group. When multiple device programs present, actual sub-group count may be lower. (add 'insn_count_subgroups_upper_bound' to silenced_warnings kernel attribute to disable)
warn_with_kernel(knl, "insn_count_subgroups_upper_bound",
UNFILTERED Op(np:dtype('float64'), OpType.ADD, CountGranularity.SUBGROUP, "_pt_kernel", frozenset()): { 100 }
FILTERED
---------------------------------------------------------------------------
KERNEL: _pt_kernel
---------------------------------------------------------------------------
ARGUMENTS:
a: type: np:dtype('float64'), shape: (10, 10), dim_tags: (N1:stride:10, N0:stride:1), offset: <class 'loopy.typing.auto'> in aspace: global
aout: type: np:dtype('float64'), shape: (10, 10), dim_tags: (N1:stride:10, N0:stride:1), tags: {FooTag()} out aspace: global
---------------------------------------------------------------------------
DOMAINS:
{ : }
{ [aout_dim0, aout_dim1] : 0 <= aout_dim0 <= 9 and 0 <= aout_dim1 <= 9 }
---------------------------------------------------------------------------
INAME TAGS:
aout_dim0: None
aout_dim1: None
---------------------------------------------------------------------------
INSTRUCTIONS:
for aout_dim0, aout_dim1
aout[aout_dim0, aout_dim1] = a[aout_dim0, aout_dim1] + a[aout_dim0, aout_dim1] {id=aout_store}
end aout_dim0, aout_dim1
---------------------------------------------------------------------------Pytato does not create TaggedExpressions itself, which is likely the reason they don't show up in the Op class. |

TODOs:
Please squash