def generate(self) -> Type["StencilObject"]: self.check_options(self.builder.options) implementation_ir = self.builder.implementation_ir # Lower HorizontalIf to If LowerHorizontalIfPass.apply(self.builder.implementation_ir) # Generate the Python binary extension (checking if GridTools sources are installed) if not gt_src_manager.has_gt_sources() and not gt_src_manager.install_gt_sources(): raise RuntimeError("Missing GridTools sources.") pyext_module_name: Optional[str] pyext_file_path: Optional[str] if implementation_ir.has_effect: pyext_module_name, pyext_file_path = self.generate_extension() else: # if computation has no effect, there is no need to create an extension pyext_module_name, pyext_file_path = None, None # Generate and return the Python wrapper class return self.make_module( pyext_module_name=pyext_module_name, pyext_file_path=pyext_file_path, )
def generate( cls, stencil_id: gt_definitions.StencilID, definition_ir: gt_ir.StencilDefinition, definition_func: types.FunctionType, options: gt_definitions.BuildOptions, ): # TODO: move this import to the top and find a better way to avoid circular imports from gt4py import gt_src_manager cls._check_options(options) # Generate the Python binary extension (checking if GridTools sources are installed) if not gt_src_manager.has_gt_sources( ) and not gt_src_manager.install_gt_sources(): raise RuntimeError("Missing GridTools sources.") implementation_ir = gt_analysis.transform(definition_ir, options) pyext_module_name, pyext_file_path = cls.generate_extension( stencil_id, definition_ir, options, implementation_ir=implementation_ir) # Generate and return the Python wrapper class return cls._generate_module( stencil_id, definition_ir, definition_func, options, extra_cache_info={"pyext_file_path": pyext_file_path}, implementation_ir=implementation_ir, pyext_module_name=pyext_module_name, pyext_file_path=pyext_file_path, )
def generate(self) -> Type["StencilObject"]: self.check_options(self.builder.options) # Generate the Python binary extension (checking if GridTools sources are installed) if not gt_src_manager.has_gt_sources(2) and not gt_src_manager.install_gt_sources(2): raise RuntimeError("Missing GridTools sources.") pyext_module_name: Optional[str] pyext_file_path: Optional[str] # TODO(havogt) add bypass if computation has no effect pyext_module_name, pyext_file_path = self.generate_extension() # Generate and return the Python wrapper class return self.make_module( pyext_module_name=pyext_module_name, pyext_file_path=pyext_file_path, )
def generate( cls, stencil_id: gt_definitions.StencilID, definition_ir: gt_ir.StencilDefinition, definition_func: types.FunctionType, options: gt_definitions.BuildOptions, **kwargs, ): from gt4py import gt_src_manager cls._check_options(options) # Generate the Python binary extension (checking if GridTools sources are installed) if not gt_src_manager.has_gt_sources() and not gt_src_manager.install_gt_sources(): raise RuntimeError("Missing GridTools sources.") pyext_module_name, pyext_file_path = cls.generate_extension( stencil_id, definition_ir, options, **kwargs ) if not options._impl_opts.get("disable-code-generation", False): # Dawn backends do not use the internal analysis pipeline, so a custom # module_info object should be passed to the module generator generator = cls.MODULE_GENERATOR_CLASS(cls) module_info = generator._generate_module_info(definition_ir, options, cls._field_info) kwargs["pyext_module_name"] = pyext_module_name kwargs["pyext_file_path"] = pyext_file_path module_source = generator( stencil_id, definition_ir, options, module_info=module_info, **kwargs ) file_name = cls.get_stencil_module_path(stencil_id) os.makedirs(os.path.dirname(file_name), exist_ok=True) with open(file_name, "w") as file: file.write(module_source) return cls._load(stencil_id, definition_func)
def generate(cls, stencil_id, definition_ir, definition_func, options): from gt4py import gt_src_manager cls._check_options(options) implementation_ir = gt_analysis.transform(definition_ir, options) # Generate the Python binary extension (checking if GridTools sources are installed) if not gt_src_manager.has_gt_sources() and not gt_src_manager.install_gt_sources(): raise RuntimeError("Missing GridTools sources.") pyext_module_name, pyext_file_path = cls.generate_extension( stencil_id, implementation_ir, options ) # Generate and return the Python wrapper class generator_options = options.as_dict() generator_options["pyext_module_name"] = pyext_module_name generator_options["pyext_file_path"] = pyext_file_path extra_cache_info = {"pyext_file_path": pyext_file_path} return super(BaseGTBackend, cls)._generate_module( stencil_id, implementation_ir, definition_func, generator_options, extra_cache_info )
def generate(self, **kwargs: Any) -> Type["StencilObject"]: self.check_options(self.builder.options) self.sir, self.sir_field_info = SIRConverter.apply( self.builder.definition_ir) # Generate the Python binary extension (checking if GridTools sources are installed) if not gt_src_manager.has_gt_sources( ) and not gt_src_manager.install_gt_sources(): raise RuntimeError("Missing GridTools sources.") pyext_module_name, pyext_file_path = self.generate_extension(**kwargs) # Dawn backends do not use the internal analysis pipeline, so a custom # args_data object should be passed to the module generator args_data = self.make_args_data(self.builder.definition_ir, self.sir_field_info) # Generate and return the Python wrapper class return self.make_module( args_data=args_data, pyext_module_name=pyext_module_name, pyext_file_path=pyext_file_path, )
import pytest import setuptools from gt4py import ( # TODO(havogt) this is a dependency from gtc tests to gt4py, ok? config, gt_src_manager, ) from gt4py.backend import pyext_builder from gtc.cuir import cuir from gtc.cuir.cuir_codegen import CUIRCodegen from .cuir_utils import KernelFactory, ProgramFactory from .utils import match if not gt_src_manager.has_gt_sources( 2) and not gt_src_manager.install_gt_sources(2): raise RuntimeError("Missing GridTools sources.") def build_gridtools_test(tmp_path: Path, code: str): tmp_src = tmp_path / "test.cu" tmp_src.write_text(code) opts = pyext_builder.get_gt_pyext_build_opts(uses_cuda=True) assert isinstance(opts["include_dirs"], list) opts["include_dirs"].append(config.GT2_INCLUDE_PATH) ext_module = setuptools.Extension( "test", [str(tmp_src.absolute())], language="c++", **opts,
# # SPDX-License-Identifier: GPL-3.0-or-later import inspect import os import gt4py import gt4py.utils as gt_utils from gt4py import gt_src_manager from gt4py.backend import pyext_builder GT4PY_INSTALLATION_PATH = os.path.dirname(inspect.getabsfile(gt4py)) EXTERNAL_SRC_PATH = os.path.join(GT4PY_INSTALLATION_PATH, "_external_src") assert gt_src_manager.has_gt_sources() or gt_src_manager.install_gt_sources() def compile_reference(): current_dir = os.path.dirname(__file__) build_opts = pyext_builder.get_gt_pyext_build_opts() build_opts["include_dirs"].append(EXTERNAL_SRC_PATH) build_opts.setdefault("extra_compile_args", []) build_opts["extra_compile_args"].append("-Wno-sign-compare") reference_names = pyext_builder.build_pybind_ext( "reference_cpp_regression", [os.path.join(current_dir, "reference.cpp")], os.path.join(current_dir, "build"), current_dir, verbose=False,
from .gtcpp_utils import ( ArgFactory, FieldDeclFactory, GTAccessorFactory, GTApplyMethodFactory, GTComputationCallFactory, GTFunctorFactory, GTParamListFactory, IfStmtFactory, ProgramFactory, ) from .utils import match if not gt_src_manager.has_gt_sources() and not gt_src_manager.install_gt_sources(): raise RuntimeError("Missing GridTools sources.") def build_gridtools_test(tmp_path: Path, code: str): tmp_src = tmp_path / "test.cpp" tmp_src.write_text(code) ext_module = setuptools.Extension( "test", [str(tmp_src.absolute())], include_dirs=[config.GT2_INCLUDE_PATH, config.build_settings["boost_include_path"]], language="c++", ) args = [ "build_ext",