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

Freeze constant arrays #354

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
14 changes: 10 additions & 4 deletions meshmode/discretization/connection/direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ class _FromGroupPickData(Generic[ArrayT]):
from_element_indices: ArrayT
is_surjective: bool

@keyed_memoize_method(key=lambda actx: type(actx))
def indexed_dof_pick_lists(self, actx):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not completely sure if this is the right object to maintain the memoization dict. (Lmk if you think something's not ideal here)

kaushikcfd marked this conversation as resolved.
Show resolved Hide resolved
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 explain why this is needed? I would have figured that DataWrapper deduplication would take care of this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is computing pt_data[pt_data_0[i, j]] i.e. a constant that should be computed AOT rather than in every compiled_rhs. See all these terms.

assert actx.permits_advanced_indexing
return actx.freeze(
actx.thaw(self.dof_pick_lists)[actx.thaw(self.dof_pick_list_indices)])

# }}}


Expand Down Expand Up @@ -356,7 +362,7 @@ def __init__(self,
# {{{ _resample_matrix

@keyed_memoize_method(key=lambda actx, to_group_index, ibatch_index:
(to_group_index, ibatch_index))
(type(actx), to_group_index, ibatch_index))
def _resample_matrix(self, actx: ArrayContext, to_group_index: int,
ibatch_index: int):
import modepy as mp
Expand Down Expand Up @@ -435,7 +441,8 @@ def _resample_point_pick_indices(self, to_group_index: int, ibatch_index: int,
return result

@keyed_memoize_method(lambda actx, to_group_index, ibatch_index,
tol_multiplier=None: (to_group_index, ibatch_index, tol_multiplier))
tol_multiplier=None: (type(actx), to_group_index,
ibatch_index, tol_multiplier))
def _frozen_resample_point_pick_indices(self, actx: ArrayContext,
to_group_index: int, ibatch_index: int,
tol_multiplier: Optional[float] = None):
Expand Down Expand Up @@ -736,8 +743,7 @@ def group_pick_knl(is_surjective: bool):
grp_ary_contrib = ary[fgpd.from_group_index][
_reshape_and_preserve_tags(
actx, from_element_indices, (-1, 1)),
actx.thaw(fgpd.dof_pick_lists)[
actx.thaw(fgpd.dof_pick_list_indices)]
actx.thaw(fgpd.indexed_dof_pick_lists(actx))
]

if not fgpd.is_surjective:
Expand Down