Repository navigation
feat[next]: call-site scan builtin #3065
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
Open
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
a19d90f
feat[next]: call-site scan builtin
havogt 7e73fb9
Merge remote-tracking branch 'upstream/main' into scan-call
havogt 0aa1637
Merge remote-tracking branch 'upstream/main' into scan-call
havogt c4ea9d7
refactor[next]: share scan argument checks and lowering between scan …
havogt 1063ce3
refactor[next]: register the embedded scan builtin from the embedded …
havogt 15844d6
refactor[next]: require axis for scan, lower it through the builtin d…
havogt df49ba4
refactor[next]: carry the scan axis on the GTIR `scan` builtin
havogt a7ddb95
fix[next]: embedded scans take their range per axis from the output d…
havogt edcf7c3
fix[next]: address review of the scan-axis change
havogt 5c9c549
test[next]: cover a scan combined with a field on another vertical di…
havogt 09046ac
test[next]: remove test_scan_in_stencil and its marker
havogt b06bece
fix[next]: include the scan axis in the type of an applied scan
havogt 99a5ce1
Merge remote-tracking branch 'upstream/havogt/scan-axis' into scan-call
havogt 98694ee
test[next]: mark the tuple-domain scan test as using scalars in the d…
havogt 7f3c39e
refactor[next]: one embedded context variable for column ranges
havogt 3f277a2
Merge remote-tracking branch 'upstream/havogt/scan-axis' into scan-call
havogt 591b782
refactor[next]: hold the embedded column ranges as a tuple of named r…
havogt f0dfee8
Merge remote-tracking branch 'upstream/havogt/scan-axis' into scan-call
havogt c8215e5
ci: 12 xdist workers for the internal cuda13 CSCS jobs
havogt ddc4d50
Merge remote-tracking branch 'upstream/main' into gtir-scan-axis
havogt 05d485b
Merge remote-tracking branch 'upstream/havogt/scan-axis' into scan-call
havogt 026b737
test[next]: drop column_axis from tests merged in from main
havogt e38a220
Merge remote-tracking branch 'upstream/havogt/scan-axis' into scan-call
havogt 54b23c5
Merge remote-tracking branch 'upstream/main' into scan-call
havogt 59e1161
refactor[next]: address review on call-site scan
havogt 3f8fa6c
fix[next]: address independent review of call-site scan
havogt 440afca
test[next]: use a bare type constructor in the named-collection scan …
havogt 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 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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,7 @@ | |
| from numpy import float32, float64, int8, int16, int32, int64, uint8, uint16, uint32, uint64 | ||
|
|
||
| from gt4py._core import definitions as core_defs | ||
| from gt4py.next import common, named_collections | ||
| from gt4py.next import common, named_collections, utils | ||
| from gt4py.next.common import Dimension, Field # noqa: F401 [unused-import] for TYPE_BUILTINS | ||
| from gt4py.next.embedded import array_ops, context as embedded_context | ||
| from gt4py.next.iterator import runtime | ||
|
|
@@ -58,6 +58,7 @@ | |
| "where", | ||
| "broadcast", | ||
| "astype", | ||
| "scan", | ||
| "abs", | ||
| "neg", | ||
| "sin", | ||
|
|
@@ -290,6 +291,62 @@ def broadcast( | |
| return field # type: ignore[return-value] # see comment above | ||
|
|
||
|
|
||
| class ScanBuiltinFunction(BuiltInFunction[_R, _P]): | ||
| def __gt_type__(self) -> ts.FunctionType: | ||
| # The arguments are checked against the signature of `scan` in type deduction. | ||
| return ts.FunctionType( | ||
| pos_only_args=[], | ||
| pos_or_kw_args={}, | ||
| kw_only_args={}, | ||
| returns=ts.DeferredType(constraint=None), | ||
| ) | ||
|
|
||
| def __call__( # type: ignore[override] # the implementation is dispatched on the arguments of the scan operator | ||
| self, scan_pass: Callable, /, **scan_kwargs: Any | ||
| ) -> Callable[..., common.Field | Tuple]: | ||
| bound = inspect.signature(self.function).bind(scan_pass, **scan_kwargs) | ||
| bound.apply_defaults() | ||
|
havogt marked this conversation as resolved.
Resolved
|
||
|
|
||
| def scan_operator(*args: Any, **kwargs: Any) -> common.Field | Tuple: | ||
| impl = self.dispatch(*utils.flatten_nested_tuple((*args, *kwargs.values()))) | ||
| if impl is self.function: | ||
| raise NotImplementedError(f"No implementation of 'scan' for arguments {args}.") | ||
| return cast(common.Field | Tuple, impl(*bound.arguments.values(), *args, **kwargs)) | ||
|
|
||
| return scan_operator | ||
|
|
||
|
|
||
| @ScanBuiltinFunction | ||
| def scan( | ||
| scan_pass: Callable, | ||
| /, | ||
| *, | ||
| axis: common.Dimension, | ||
| forward: bool = True, | ||
| init: core_defs.Scalar | Tuple = 0.0, | ||
|
Contributor
Author
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. @tehrengruber Removing the default is in a next PR |
||
| ) -> Callable[..., common.Field | Tuple]: | ||
| """ | ||
| Create a scan operator from a scan pass, to be called inside a field operator. | ||
|
|
||
| Args: | ||
| scan_pass: Field operator `(carry, *args) -> carry` on scalars (or tuples thereof). | ||
| axis: Vertical dimension to scan along. | ||
| forward: Scan direction. | ||
| init: Initial value of the carry, a compile-time constant. | ||
|
|
||
| Examples: | ||
| >>> scan(my_pass, axis=KDim, forward=True, init=0.0)(a) # doctest: +SKIP | ||
| """ | ||
| raise NotImplementedError() | ||
|
|
||
|
|
||
| SCAN_DEFAULTS: Final[dict[str, Any]] = { | ||
| name: param.default | ||
| for name, param in inspect.signature(scan.function).parameters.items() | ||
| if param.default is not inspect.Parameter.empty | ||
| } | ||
|
|
||
|
|
||
| @WhereBuiltinFunction | ||
| def where( | ||
| mask: common.Field, | ||
|
|
@@ -430,6 +487,7 @@ def impl( | |
| "broadcast", | ||
| "where", | ||
| "astype", | ||
| "scan", | ||
| *MATH_BUILTIN_NAMES, | ||
| ] | ||
|
|
||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.