Skip to content

Conversation

@schnellerhase
Copy link
Contributor

@schnellerhase schnellerhase commented Dec 12, 2025

Centralises common backend logic for reusability in different backends.

  • template_keys: extracts template keys, used for checking all keys matched by input data
  • integral_data: computes unrolled sorted integral data of a FormIR
  • tensor_sizes: computes the sizes of the tensors associated with the kernel invocation of a form or an expression

Consistently names the implementation files in singular (expressions.py -> expression.py, etc.)

All includes in code generation now pass though the module level, i.e. __init__.py of C/ or numba/ - no longer enforcing a given file structure to be present in the backend (that's an implementation detail). This continues the work to define the language backend interface.

"""Generation of MyBackend code."""

class FormatterImpl:
    def __init__(self, dtype: npt.DTypeLike) -> None: ...
    def __call__(self, obj: L.LNode) -> str: ...

class expression: # (or namespace)
    def generator(ir: ExpressionIR, options: dict[str, int | float | npt.DTypeLike]) -> tuple[str, str]: ...

class integral: # (or namespace)
    def generator(ir: IntegralIR, domain: basix.CellType, options: dict[str, int | float | npt.DTypeLike]) -> tuple[str, str]: ...

class form: # (or namespace)
     def generator(ir: FormIR, options: dict[str, int | float | npt.DTypeLike]) -> tuple[str, str]: ...

class file: # (or namespace)
    def generator(options: dict[str, int | float | npt.DTypeLike]) -> tuple[tuple[str, str], tuple[str, str]]: ...

The only thing that needs to be addressed/improved on after this for #805 is the handling of output files, the split into declaration and implementation (or header and source) should be generalised away from the backend.

@coveralls
Copy link

coveralls commented Dec 12, 2025

Coverage Status

coverage: 84.503% (+0.003%) from 84.5%
when pulling b8e7042 on schnellerhase/backend-common
into dde9f73 on main.

@schnellerhase schnellerhase marked this pull request as ready for review December 12, 2025 21:28
Base automatically changed from schnellerhase/dispatch to main December 16, 2025 11:10
@schnellerhase schnellerhase changed the title Centralise common backend routines Centralise common backend routines and finish backend interface Dec 16, 2025
@schnellerhase schnellerhase changed the title Centralise common backend routines and finish backend interface Centralise common backend routines and continue backend interface Dec 16, 2025
@schnellerhase schnellerhase added the enhancement New feature or request label Dec 16, 2025
Copy link
Contributor

@michalhabera michalhabera left a comment

Choose a reason for hiding this comment

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

Moving the language backend independent code looks good, but I am not in favor of flattening the module structure to generator_form, etc. If this is the implementation detail, why not force user to prepare the module structure with classes then?

@schnellerhase
Copy link
Contributor Author

schnellerhase commented Jan 5, 2026

Reverted the flattening of the interface to free functions. Maintains the namespaced {file,expression,integral,form}.generator signatures.

@schnellerhase schnellerhase added this pull request to the merge queue Jan 6, 2026
Merged via the queue into main with commit e85f94d Jan 6, 2026
33 checks passed
@schnellerhase schnellerhase deleted the schnellerhase/backend-common branch January 6, 2026 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants