-
Notifications
You must be signed in to change notification settings - Fork 70
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
19
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
19 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 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
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
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 | ||||
---|---|---|---|---|---|---|
|
@@ -114,6 +114,10 @@ | |||||
# {{{ mappers with support for loopy-specific primitives | ||||||
|
||||||
class IdentityMapperMixin: | ||||||
def map_with_tag(self, expr, *args, **kwargs): | ||||||
new_expr = self.rec(expr.expr, *args, **kwargs) | ||||||
return WithTag(expr.tags, new_expr) | ||||||
|
||||||
def map_literal(self, expr, *args, **kwargs): | ||||||
return expr | ||||||
|
||||||
|
@@ -207,6 +211,12 @@ def map_common_subexpression_uncached(self, expr): | |||||
|
||||||
|
||||||
class WalkMapperMixin: | ||||||
def map_with_tag(self, expr, *args, **kwargs): | ||||||
if not self.visit(expr, *args, **kwargs): | ||||||
return | ||||||
|
||||||
self.rec(expr.expr, *args, **kwargs) | ||||||
|
||||||
def map_literal(self, expr, *args, **kwargs): | ||||||
self.visit(expr, *args, **kwargs) | ||||||
|
||||||
|
@@ -273,6 +283,9 @@ class CallbackMapper(IdentityMapperMixin, CallbackMapperBase): | |||||
|
||||||
|
||||||
class CombineMapper(CombineMapperBase): | ||||||
def map_with_tag(self, expr, *args, **kwargs): | ||||||
return self.rec(expr.expr, *args, **kwargs) | ||||||
|
||||||
def map_reduction(self, expr, *args, **kwargs): | ||||||
return self.rec(expr.expr, *args, **kwargs) | ||||||
|
||||||
|
@@ -298,6 +311,10 @@ class ConstantFoldingMapper(ConstantFoldingMapperBase, | |||||
|
||||||
|
||||||
class StringifyMapper(StringifyMapperBase): | ||||||
def map_with_tag(self, expr, *args): | ||||||
from pymbolic.mapper.stringifier import PREC_NONE | ||||||
return f"WithTag({expr.tags}, {self.rec(expr.expr, PREC_NONE)}" | ||||||
|
||||||
def map_literal(self, expr, *args): | ||||||
return expr.s | ||||||
|
||||||
|
@@ -440,6 +457,10 @@ def map_tagged_variable(self, expr, *args, **kwargs): | |||||
def map_loopy_function_identifier(self, expr, *args, **kwargs): | ||||||
return set() | ||||||
|
||||||
def map_with_tag(self, expr, *args, **kwargs): | ||||||
deps = self.rec(expr.expr, *args, **kwargs) | ||||||
return deps | ||||||
|
||||||
def map_sub_array_ref(self, expr, *args, **kwargs): | ||||||
deps = self.rec(expr.subscript, *args, **kwargs) | ||||||
return deps - set(expr.swept_inames) | ||||||
|
@@ -712,6 +733,31 @@ def copy(self, *, name=None, tags=None): | |||||
mapper_method = intern("map_tagged_variable") | ||||||
|
||||||
|
||||||
class WithTag(LoopyExpressionBase): | ||||||
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.
Suggested change
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. Done in 45e14e7 |
||||||
""" | ||||||
Represents a frozenset of tags attached to an :attr:`expr`. | ||||||
""" | ||||||
|
||||||
init_arg_names = ("tags", "expr") | ||||||
|
||||||
def __init__(self, tags, expr): | ||||||
self.tags = tags | ||||||
self.expr = expr | ||||||
|
||||||
def __getinitargs__(self): | ||||||
return (self.tags, self.expr) | ||||||
|
||||||
def get_hash(self): | ||||||
return hash((self.__class__, self.tags, self.expr)) | ||||||
|
||||||
def is_equal(self, other): | ||||||
return (other.__class__ == self.__class__ | ||||||
and other.tags == self.tags | ||||||
and other.expr == self.expr) | ||||||
|
||||||
mapper_method = intern("map_with_tag") | ||||||
|
||||||
|
||||||
class Reduction(LoopyExpressionBase): | ||||||
""" | ||||||
Represents a reduction operation on :attr:`expr` across :attr:`inames`. | ||||||
|
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
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.
Would overwrite tags of subexpressions that already have tags.
self.rec(expr.expr, expr.tags)
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.
Is 50adbc4 what you had in mind?
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.
Yes, generally.