Remove in-place modification of arrays in preparation for lazy evaluation#180
Closed
thomasgibson wants to merge 17 commits into
Closed
Remove in-place modification of arrays in preparation for lazy evaluation#180thomasgibson wants to merge 17 commits into
thomasgibson wants to merge 17 commits into
Conversation
thomasgibson
commented
May 6, 2021
Comment on lines
+485
to
+502
| # def flatten(ary: Union[DOFArray, np.ndarray]) -> Any: | ||
| # r"""Convert a :class:`DOFArray` into a "flat" array of degrees of freedom, | ||
| # where the resulting type of the array is given by the | ||
| # :attr:`DOFArray.array_context`. | ||
|
|
||
| # Array elements are laid out contiguously, with the element group | ||
| # index varying slowest, element index next, and intra-element DOF | ||
| # index fastest. | ||
|
|
||
| # Vectorizes over object arrays of :class:`DOFArray`\ s. | ||
| # """ | ||
| # if isinstance(ary, np.ndarray): | ||
| # return obj_array_vectorize(flatten, ary) | ||
|
|
||
| # actx = ary.array_context | ||
|
|
||
| # return actx.np.concatenate(actx.np.reshape(grp_ary, (-1,)) | ||
| # for grp_ary in ary) |
Collaborator
Author
There was a problem hiding this comment.
@kaushikcfd Unfortunately, this does not work. Every time an array goes through this, an array with junk is returned. Haven't taken a close look into why, but making a note here.
thomasgibson
commented
May 6, 2021
Comment on lines
+170
to
+214
| kernels = [] # get kernels for each batch; to be fused eventually | ||
| kwargs = {} # kwargs to the fused kernel | ||
| for ibatch, batch in enumerate(cgrp.batches): | ||
| sgrp = self.from_discr.groups[batch.from_group_index] | ||
|
|
||
| knl = lp.rename_argument( | ||
| kproj(), "basis_tabulation", | ||
| f"basis_tabulation_batch{ibatch}" | ||
| ) | ||
| knl = lp.rename_argument(knl, "ary", f"ary_batch{ibatch}") | ||
| knl = lp.rename_argument(knl, "weights", f"weights_batch{ibatch}") | ||
| knl = lp.rename_argument(knl, "from_element_indices", | ||
| f"from_element_indices_{ibatch}") | ||
| knl = lp.rename_argument(knl, "to_element_indices", | ||
| f"to_element_indices_{ibatch}") | ||
| knl = lp.rename_argument(knl, "nelements", | ||
| f"nelements_{ibatch}") | ||
|
|
||
| for iname in knl.all_inames(): | ||
| knl = lp.rename_iname(knl, iname, f"{iname}_batch{ibatch}") | ||
|
|
||
| # Generate the basis tabulation matrix | ||
| tabulations = [] | ||
| for ibasis, basis_fn in enumerate(sgrp.basis_obj().functions): | ||
| basis = actx.from_numpy( | ||
| basis_fn(batch.result_unit_nodes).flatten()) | ||
|
|
||
| # NOTE: batch.*_element_indices are reversed here because | ||
| # they are from the original forward connection, but | ||
| # we are going in reverse here. a bit confusing, but | ||
| # saves on recreating the connection groups and batches. | ||
| actx.call_loopy(kproj(), | ||
| ibasis=ibasis, | ||
| ary=ary[sgrp.index], | ||
| basis=basis, | ||
| weights=weights[igrp, ibatch], | ||
| result=c[igrp], | ||
| from_element_indices=batch.to_element_indices, | ||
| to_element_indices=batch.from_element_indices) | ||
| tabulations.append(basis_fn(batch.result_unit_nodes).flatten()) | ||
| tabulations = actx.from_numpy(np.asarray(tabulations)) | ||
|
|
||
| kwargs[f"basis_tabulation_batch{ibatch}"] = tabulations | ||
| kwargs[f"ary_batch{ibatch}"] = ary[sgrp.index] | ||
| kwargs[f"weights_batch{ibatch}"] = weights[igrp, ibatch] | ||
| kwargs[f"from_element_indices_{ibatch}"] = \ | ||
| batch.from_element_indices | ||
| kwargs[f"to_element_indices_{ibatch}"] = \ | ||
| batch.to_element_indices | ||
|
|
||
| kernels.append(knl) | ||
|
|
||
| fused_knl = lp.fuse_kernels(kernels) | ||
| fused_knl = fused_knl.copy(name="fused_kproj_program") | ||
| fused_knl = lp.add_nosync(fused_knl, | ||
| "global", | ||
| "writes:result", | ||
| "writes:result", | ||
| bidirectional=True, | ||
| force=True) |
Collaborator
Author
There was a problem hiding this comment.
I am unfortunately at a loss for why this fails to work (just segfaults --- tested by running py.test test/test_chained.py -k 'test_reversed_chained_connection). Would appreciate someone with acute loopy-awareness to look at this and spot something "obviously wrong". Cough: @inducer :)
1 task
Merged
Collaborator
Author
|
Closing this PR since the recent updates made it a huge pain to rebase. Replaced with a much cleaner attempt: #192 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
With @kaushikcfd's blessing, I am reviving #58 (which is a pre-requisite for #116). Still a WIP.