Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/gt4py/next/otf/compilation/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import dataclasses
import pathlib
import types
from typing import Protocol, TypeVar

import factory
Expand Down Expand Up @@ -42,6 +43,9 @@ def __call__(
) -> stages.BuildSystemProject[SrcL, LS, TgtL]: ...


_MODULES: list[types.ModuleType] = []


@dataclasses.dataclass(frozen=True)
class Compiler(
workflow.ChainableWorkflowMixin[
Expand Down Expand Up @@ -83,11 +87,12 @@ def __call__(
f"On-the-fly compilation unsuccessful for '{inp.program_source.entry_point.name}'."
)

compiled_prog = getattr(
importer.import_from_path(src_dir / new_data.module), new_data.entry_point_name
)
m = importer.import_from_path(src_dir / new_data.module)
# Keep a reference to the module so they are not garbage collected. This avoids a SEGFAULT
# in nanobind when calling the compiled program.
_MODULES.append(m)

return compiled_prog
return getattr(m, new_data.entry_point_name)


class CompilerFactory(factory.Factory):
Expand Down