-
Notifications
You must be signed in to change notification settings - Fork 51
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
feat[cartesian] Debug Backend #1884
Open
twicki
wants to merge
22
commits into
GridTools:main
Choose a base branch
from
twicki:debug_backend
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.
+866
−13
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d2ec270
step 1
twicki d693eb2
step2
twicki 1913e38
step3
twicki 6246774
simplify to existing features
twicki 37769bd
missing mod ufunc
twicki 85d73f9
missing omission from perf-backend names
twicki 7bd7a97
Update src/gt4py/cartesian/backend/__init__.py
twicki 2901d4a
reviewer's feedback
twicki 628a5a1
Update src/gt4py/cartesian/gtc/debug/debug_codegen.py
twicki 2e60003
Update src/gt4py/cartesian/gtc/debug/debug_codegen.py
twicki 84b5cc9
reviewer's feedback
twicki 95460ee
Merge branch 'debug_backend' of github.com:twicki/gt4py into debug_ba…
twicki 7d9ac06
feedback v2
twicki 514c270
Merge commit '70569bc5e917bf4000f6543573aadc5d31c86c13' into debug_ba…
twicki 73aa6b5
clean up imports
twicki 64338de
pc hooks
twicki 4c7edff
extract literal precision feature
twicki e596c51
remove literal precision
twicki 12efff9
generalize debuck backend tests
twicki 321831a
discussion roman
twicki 0570c80
add cpu copies to tests
twicki 786bc2e
Merge branch 'main' into debug_backend
twicki 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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# GT4Py - GridTools Framework | ||
# | ||
# Copyright (c) 2014-2024, ETH Zurich | ||
# All rights reserved. | ||
# | ||
# Please, refer to the LICENSE file in the root directory. | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
|
||
from typing import TYPE_CHECKING, Any, ClassVar, Type, Union | ||
|
||
from gt4py import storage | ||
from gt4py.cartesian.backend.base import BaseBackend, CLIBackendMixin, register | ||
from gt4py.cartesian.backend.numpy_backend import ModuleGenerator | ||
from gt4py.cartesian.gtc.debug.debug_codegen import DebugCodeGen | ||
from gt4py.cartesian.gtc.gtir_to_oir import GTIRToOIR | ||
from gt4py.cartesian.gtc.passes.oir_optimizations.horizontal_execution_merging import ( | ||
HorizontalExecutionMerging, | ||
) | ||
from gt4py.cartesian.gtc.passes.oir_optimizations.temporaries import LocalTemporariesToScalars | ||
from gt4py.cartesian.gtc.passes.oir_pipeline import OirPipeline | ||
from gt4py.eve.codegen import format_source | ||
Comment on lines
+12
to
+22
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. See my comments about imports below |
||
|
||
|
||
if TYPE_CHECKING: | ||
from gt4py.cartesian.stencil_object import StencilObject | ||
|
||
|
||
@register | ||
class DebugBackend(BaseBackend, CLIBackendMixin): | ||
"""Debug backend using plain python loops.""" | ||
|
||
name = "debug" | ||
options: ClassVar[dict[str, Any]] = { | ||
"oir_pipeline": {"versioning": True, "type": OirPipeline}, | ||
"ignore_np_errstate": {"versioning": True, "type": bool}, | ||
} | ||
storage_info = storage.layout.NaiveCPULayout | ||
languages = {"computation": "python", "bindings": ["python"]} | ||
MODULE_GENERATOR_CLASS = ModuleGenerator | ||
|
||
def generate_computation(self) -> dict[str, Union[str, dict]]: | ||
romanc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
computation_name = ( | ||
f"{self.builder.caching.module_prefix}" | ||
+ f"computation{self.builder.caching.module_postfix}.py" | ||
) | ||
|
||
oir = GTIRToOIR().visit(self.builder.gtir) | ||
oir = HorizontalExecutionMerging().visit(oir) | ||
oir = LocalTemporariesToScalars().visit(oir) | ||
source_code = DebugCodeGen().visit(oir) | ||
|
||
if self.builder.options.format_source: | ||
source_code = format_source("python", source_code) | ||
|
||
return {computation_name: source_code} | ||
|
||
def generate_bindings(self, language_name: str) -> dict[str, Union[str, dict]]: | ||
super().generate_bindings(language_name) | ||
return {self.builder.module_path.name: self.make_module_source()} | ||
|
||
def generate(self) -> Type["StencilObject"]: | ||
self.check_options(self.builder.options) | ||
src_dir = self.builder.module_path.parent | ||
if not self.builder.options._impl_opts.get("disable-code-generation", False): | ||
src_dir.mkdir(parents=True, exist_ok=True) | ||
self.recursive_write(src_dir, self.generate_computation()) | ||
return self.make_module() |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# GT4Py - GridTools Framework | ||
# | ||
# Copyright (c) 2014-2024, ETH Zurich | ||
# All rights reserved. | ||
# | ||
# Please, refer to the LICENSE file in the root directory. | ||
# SPDX-License-Identifier: BSD-3-Clause |
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.
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.
This function used to be a standalone function. Now it is part of a base class without accessing any property or method of that class. Have you considered leaving it a standalone function? We could keep it in the same file or create
src/gt4py/cartesian/backend/utils.py
and put it there. Another prime candidate to move to a potentialbackend/utils.py
(in a follow-up PR) would begt4py/src/gt4py/cartesian/backend/base.py
Lines 433 to 455 in b6a3162
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.
I think since it is so tied to the backends and this is the only place this is used, adding it to the class gives it a more direct link to where the work is used. I prefer this way to avoid generic
utils
files that have a tendency to grow big. If there are utilities that are used across larger modules, I see value that way.We could make it a
staticmethod
though