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

add TaggedExpression #688

Open
wants to merge 50 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
9233385
add WithTag
matthiasdiener Oct 11, 2022
679d269
Merge branch 'main' into withtag
matthiasdiener Oct 18, 2022
45e14e7
rename to TaggedExpression
matthiasdiener Oct 18, 2022
50adbc4
better tags propagation
matthiasdiener Oct 18, 2022
06ab987
add to memaccess
matthiasdiener Oct 18, 2022
d50f908
Merge branch 'main' into withtag
matthiasdiener Oct 18, 2022
ee395c1
Merge branch 'main' into withtag
matthiasdiener Oct 27, 2022
04d0739
Merge branch 'main' into withtag
matthiasdiener Nov 9, 2022
9ae8936
spelling fixes
matthiasdiener Nov 9, 2022
0bbbaec
provide default value for tags in map_ functions
matthiasdiener Nov 9, 2022
9529588
better doc
matthiasdiener Nov 9, 2022
9e24cd6
attempt to fix doctest
matthiasdiener Nov 9, 2022
e72dec0
add Sync
matthiasdiener Nov 9, 2022
c7f9ad0
Merge branch 'main' into withtag
matthiasdiener Nov 11, 2022
df7ed9b
no default tags arguments
matthiasdiener Nov 11, 2022
857e268
lint fix
matthiasdiener Nov 11, 2022
d5f3f5d
small arg fixes
matthiasdiener Nov 11, 2022
3d7df9f
Add some types to loopy.translation_unit
inducer Nov 28, 2022
6142a3b
Stats: fix tags passing, add types
inducer Nov 28, 2022
b060d55
Merge branch 'main' into withtag
matthiasdiener Nov 4, 2024
cc7efdc
ruff
matthiasdiener Nov 4, 2024
56527b4
misc updates
matthiasdiener Nov 7, 2024
af5d019
Merge branch 'main' into withtag
matthiasdiener Nov 7, 2024
f461722
Merge branch 'main' into withtag
matthiasdiener Nov 7, 2024
3f9df15
fix(?) MemoryAccessCounter
matthiasdiener Nov 8, 2024
2248b0e
fix remaining issues
matthiasdiener Nov 8, 2024
bb758ad
doctest fixes
matthiasdiener Nov 8, 2024
5aabe8f
small doc fix
matthiasdiener Nov 8, 2024
119e789
make {Sync,MemAccess}.__repr__ more consistent, fix doctest errors
matthiasdiener Nov 11, 2024
372e48f
fix docs
matthiasdiener Nov 11, 2024
0ef534e
gitlab->github in CI
matthiasdiener Nov 11, 2024
5e5be1d
mypy fixes
matthiasdiener Nov 11, 2024
b54217d
pylint github
matthiasdiener Nov 11, 2024
a693fb0
fix (?) remaining mypy errors, somewhat sketchy in parts
matthiasdiener Nov 11, 2024
4b5a8f4
Revert "pylint github"
matthiasdiener Nov 11, 2024
1a48a34
minor cleanup
matthiasdiener Nov 11, 2024
dd419b0
revert CI changes
matthiasdiener Nov 12, 2024
ad08e3e
minor
matthiasdiener Nov 12, 2024
123a457
Merge branch 'main' into withtag
matthiasdiener Nov 14, 2024
7b60f42
Merge branch 'main' into withtag
matthiasdiener Nov 20, 2024
da547b6
Merge branch 'main' into withtag
matthiasdiener Jan 10, 2025
c67eea6
ruff
matthiasdiener Jan 10, 2025
9dce573
ExpressionT
matthiasdiener Jan 13, 2025
17ba240
Merge branch 'main' into withtag
matthiasdiener Jan 13, 2025
9f93401
lint
matthiasdiener Jan 13, 2025
c3b4a82
more lint fixes
matthiasdiener Jan 13, 2025
04ae5c0
remove init_arg_names
matthiasdiener Jan 13, 2025
4ca4db4
more typing
matthiasdiener Jan 13, 2025
854b4a2
Merge branch 'main' into withtag
matthiasdiener Jan 22, 2025
59a51c4
Merge branch 'main' into withtag
matthiasdiener Jan 31, 2025
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
85 changes: 46 additions & 39 deletions loopy/statistics.py
Copy link
Owner

Choose a reason for hiding this comment

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

Could you type those newly-added mapper methods? I'm laying the groundwork for that in #897.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done as part of 4ca4db4

Original file line number Diff line number Diff line change
Expand Up @@ -922,19 +922,16 @@ def __init__(self, knl, callables_table, kernel_rec,
def combine(self, values):
return sum(values)

def map_constant(self, expr):
def map_constant(self, expr, *args):
return self.new_zero_poly_map()

map_tagged_variable = map_constant
map_variable = map_constant

def map_tagged_expression(self, expr, *args):
opmap = self.rec(expr.expr)
for op in opmap.count_map:
op.tags = expr.tags
return opmap
return self.rec(expr.expr, expr.tags)

def map_call(self, expr):
def map_call(self, expr, tags):
from loopy.symbolic import ResolvedFunction
assert isinstance(expr.function, ResolvedFunction)
clbl = self.callables_table[expr.function.name]
Expand All @@ -944,37 +941,40 @@ def map_call(self, expr):
return self.new_poly_map(
{Op(dtype=self.type_inf(expr),
name="func:"+clbl.name,
tags=tags,
count_granularity=self.arithmetic_count_granularity,
kernel_name=self.knl.name): self.one}
) + self.rec(expr.parameters)
) + self.rec(expr.parameters, tags)
else:
return super().map_call(expr)
return super().map_call(expr, tags)

def map_subscript(self, expr):
def map_subscript(self, expr, *args):
if self.count_within_subscripts:
return self.rec(expr.index)
return self.rec(expr.index, *args)
else:
return self.new_zero_poly_map()

def map_sub_array_ref(self, expr):
def map_sub_array_ref(self, expr, *args):
# generates an array view, considered free
return self.new_zero_poly_map()

def map_sum(self, expr):
def map_sum(self, expr, tags):
assert expr.children
return self.new_poly_map(
{Op(dtype=self.type_inf(expr),
name="add",
tags=tags,
count_granularity=self.arithmetic_count_granularity,
kernel_name=self.knl.name):
self.zero + (len(expr.children)-1)}
) + sum(self.rec(child) for child in expr.children)
) + sum(self.rec(child, tags) for child in expr.children)

def map_product(self, expr):
def map_product(self, expr, tags):
from pymbolic.primitives import is_zero
assert expr.children
return sum(self.new_poly_map({Op(dtype=self.type_inf(expr),
name="mul",
tags=tags,
count_granularity=(
self.arithmetic_count_granularity),
kernel_name=self.knl.name): self.one})
Expand All @@ -983,97 +983,104 @@ def map_product(self, expr):
if not is_zero(child + 1)) + \
self.new_poly_map({Op(dtype=self.type_inf(expr),
name="mul",
tags=tags,
count_granularity=(
self.arithmetic_count_granularity),
kernel_name=self.knl.name): -self.one})

def map_quotient(self, expr, *args):
def map_quotient(self, expr, tags):
return self.new_poly_map({Op(dtype=self.type_inf(expr),
name="div",
tags=tags,
count_granularity=self.arithmetic_count_granularity,
kernel_name=self.knl.name): self.one}) \
+ self.rec(expr.numerator) \
+ self.rec(expr.denominator)
+ self.rec(expr.numerator, tags) \
+ self.rec(expr.denominator, tags)

map_floor_div = map_quotient
map_remainder = map_quotient

def map_power(self, expr):
def map_power(self, expr, tags):
return self.new_poly_map({Op(dtype=self.type_inf(expr),
name="pow",
tags=tags,
count_granularity=self.arithmetic_count_granularity,
kernel_name=self.knl.name): self.one}) \
+ self.rec(expr.base) \
+ self.rec(expr.exponent)
+ self.rec(expr.base, tags) \
+ self.rec(expr.exponent, tags)

def map_left_shift(self, expr):
def map_left_shift(self, expr, tags):
return self.new_poly_map({Op(dtype=self.type_inf(expr),
name="shift",
tags=tags,
count_granularity=self.arithmetic_count_granularity,
kernel_name=self.knl.name): self.one}) \
+ self.rec(expr.shiftee) \
+ self.rec(expr.shift)
+ self.rec(expr.shiftee, tags) \
+ self.rec(expr.shift, tags)

map_right_shift = map_left_shift

def map_bitwise_not(self, expr):
def map_bitwise_not(self, expr, tags):
return self.new_poly_map({Op(dtype=self.type_inf(expr),
name="bw",
tags=tags,
count_granularity=self.arithmetic_count_granularity,
kernel_name=self.knl.name): self.one}) \
+ self.rec(expr.child)
+ self.rec(expr.child, tags)

def map_bitwise_or(self, expr):
def map_bitwise_or(self, expr, tags):
return self.new_poly_map({Op(dtype=self.type_inf(expr),
name="bw",
tags=tags,
count_granularity=self.arithmetic_count_granularity,
kernel_name=self.knl.name):
self.zero + (len(expr.children)-1)}) \
+ sum(self.rec(child) for child in expr.children)
+ sum(self.rec(child, tags) for child in expr.children)

map_bitwise_xor = map_bitwise_or
map_bitwise_and = map_bitwise_or

def map_if(self, expr):
def map_if(self, expr, *args):
Copy link
Owner

Choose a reason for hiding this comment

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

Why switch to *args here?

Copy link
Collaborator Author

@matthiasdiener matthiasdiener Nov 9, 2022

Choose a reason for hiding this comment

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

In 0bbbaec, I changed all occurrences to tags (with a default argument). Does this look reasonable?

warn_with_kernel(self.knl, "summing_if_branches_ops",
"ExpressionOpCounter counting ops as sum of "
"if-statement branches.")
return self.rec(expr.condition) + self.rec(expr.then) \
+ self.rec(expr.else_)
return self.rec(expr.condition, *args) + self.rec(expr.then, *args) \
+ self.rec(expr.else_, *args)

def map_if_positive(self, expr):
def map_if_positive(self, expr, *args):
warn_with_kernel(self.knl, "summing_ifpos_branches_ops",
"ExpressionOpCounter counting ops as sum of "
"if_pos-statement branches.")
return self.rec(expr.criterion) + self.rec(expr.then) \
+ self.rec(expr.else_)
return self.rec(expr.criterion, *args) + self.rec(expr.then, *args) \
+ self.rec(expr.else_, *args)

def map_min(self, expr):
def map_min(self, expr, tags):
return self.new_poly_map({Op(dtype=self.type_inf(expr),
name="maxmin",
tags=tags,
count_granularity=self.arithmetic_count_granularity,
kernel_name=self.knl.name):
len(expr.children)-1}) \
+ sum(self.rec(child) for child in expr.children)
+ sum(self.rec(child, tags) for child in expr.children)

map_max = map_min

def map_common_subexpression(self, expr):
def map_common_subexpression(self, expr, *args):
raise NotImplementedError("ExpressionOpCounter encountered "
"common_subexpression, "
"map_common_subexpression not implemented.")

def map_substitution(self, expr):
def map_substitution(self, expr, *args):
raise NotImplementedError("ExpressionOpCounter encountered "
"substitution, "
"map_substitution not implemented.")

def map_derivative(self, expr):
def map_derivative(self, expr, *args):
raise NotImplementedError("ExpressionOpCounter encountered "
"derivative, "
"map_derivative not implemented.")

def map_slice(self, expr):
def map_slice(self, expr, *args):
raise NotImplementedError("ExpressionOpCounter encountered slice, "
"map_slice not implemented.")

Expand Down