You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BaseGTBackend._make_extension_sources in src/gt4py/cartesian/backend/gtc_common.py tries to cache the generated C++ sources in the builder's backend data, but the cache is never actually stored, so it never hits:
def_make_extension_sources(self) ->dict[str, dict[str, str]]:
"""Generate the source for the stencil independently from use case."""if"computation_src"inself.builder.backend_data: # L265returnself.builder.backend_data["computation_src"] # L266
...
self.builder.backend_data["computation_src"] =gt_pyext_sources# L280returngt_pyext_sources
StencilBuilder.backend_data returns a copy of the stored dict (src/gt4py/cartesian/stencil_builder.py, L219-220):
so the assignment at L280 writes into a temporary copy that is immediately discarded, and the lookup at L265 never finds computation_src. The supported way to store backend data is self.builder.with_backend_data({...}), as done e.g. in numpy_backend.py (L82-84) and backend/base.py (L310).
Impact
Effectively none today: the only caller of _make_extension_sources is make_extension (gtc_common.py, L230), which runs once per build, so even a working cache would never be read. The code is therefore dead, but misleading.
Possible fixes
Remove the cache (L265-266 and L280). Simplest, since nothing would read it.
Make it work by storing it with self.builder.with_backend_data({"computation_src": gt_pyext_sources}). Only worth it if _make_extension_sources is expected to be called more than once per build.
Option 1 seems preferable unless there are plans to reuse the generated sources.
Note
This issue was created by a coding agent (Claude) acting on behalf of @egparedes.
cc @FlorianDeconinck @romanc. Found while working on #2927.
Description
BaseGTBackend._make_extension_sourcesinsrc/gt4py/cartesian/backend/gtc_common.pytries to cache the generated C++ sources in the builder's backend data, but the cache is never actually stored, so it never hits:StencilBuilder.backend_datareturns a copy of the stored dict (src/gt4py/cartesian/stencil_builder.py, L219-220):so the assignment at L280 writes into a temporary copy that is immediately discarded, and the lookup at L265 never finds
computation_src. The supported way to store backend data isself.builder.with_backend_data({...}), as done e.g. innumpy_backend.py(L82-84) andbackend/base.py(L310).Impact
Effectively none today: the only caller of
_make_extension_sourcesismake_extension(gtc_common.py, L230), which runs once per build, so even a working cache would never be read. The code is therefore dead, but misleading.Possible fixes
self.builder.with_backend_data({"computation_src": gt_pyext_sources}). Only worth it if_make_extension_sourcesis expected to be called more than once per build.Option 1 seems preferable unless there are plans to reuse the generated sources.