-
Notifications
You must be signed in to change notification settings - Fork 73
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
matthiasdiener
wants to merge
50
commits into
main
Choose a base branch
from
withtag
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add TaggedExpression #688
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
9233385
add WithTag
matthiasdiener 679d269
Merge branch 'main' into withtag
matthiasdiener 45e14e7
rename to TaggedExpression
matthiasdiener 50adbc4
better tags propagation
matthiasdiener 06ab987
add to memaccess
matthiasdiener d50f908
Merge branch 'main' into withtag
matthiasdiener ee395c1
Merge branch 'main' into withtag
matthiasdiener 04d0739
Merge branch 'main' into withtag
matthiasdiener 9ae8936
spelling fixes
matthiasdiener 0bbbaec
provide default value for tags in map_ functions
matthiasdiener 9529588
better doc
matthiasdiener 9e24cd6
attempt to fix doctest
matthiasdiener e72dec0
add Sync
matthiasdiener c7f9ad0
Merge branch 'main' into withtag
matthiasdiener df7ed9b
no default tags arguments
matthiasdiener 857e268
lint fix
matthiasdiener d5f3f5d
small arg fixes
matthiasdiener 3d7df9f
Add some types to loopy.translation_unit
inducer 6142a3b
Stats: fix tags passing, add types
inducer b060d55
Merge branch 'main' into withtag
matthiasdiener cc7efdc
ruff
matthiasdiener 56527b4
misc updates
matthiasdiener af5d019
Merge branch 'main' into withtag
matthiasdiener f461722
Merge branch 'main' into withtag
matthiasdiener 3f9df15
fix(?) MemoryAccessCounter
matthiasdiener 2248b0e
fix remaining issues
matthiasdiener bb758ad
doctest fixes
matthiasdiener 5aabe8f
small doc fix
matthiasdiener 119e789
make {Sync,MemAccess}.__repr__ more consistent, fix doctest errors
matthiasdiener 372e48f
fix docs
matthiasdiener 0ef534e
gitlab->github in CI
matthiasdiener 5e5be1d
mypy fixes
matthiasdiener b54217d
pylint github
matthiasdiener a693fb0
fix (?) remaining mypy errors, somewhat sketchy in parts
matthiasdiener 4b5a8f4
Revert "pylint github"
matthiasdiener 1a48a34
minor cleanup
matthiasdiener dd419b0
revert CI changes
matthiasdiener ad08e3e
minor
matthiasdiener 123a457
Merge branch 'main' into withtag
matthiasdiener 7b60f42
Merge branch 'main' into withtag
matthiasdiener da547b6
Merge branch 'main' into withtag
matthiasdiener c67eea6
ruff
matthiasdiener 9dce573
ExpressionT
matthiasdiener 17ba240
Merge branch 'main' into withtag
matthiasdiener 9f93401
lint
matthiasdiener c3b4a82
more lint fixes
matthiasdiener 04ae5c0
remove init_arg_names
matthiasdiener 4ca4db4
more typing
matthiasdiener 854b4a2
Merge branch 'main' into withtag
matthiasdiener 59a51c4
Merge branch 'main' into withtag
matthiasdiener File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] | ||
|
@@ -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}) | ||
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why switch to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In 0bbbaec, I changed all occurrences to |
||
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.") | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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