|
| 1 | +# GT4Py - GridTools Framework |
| 2 | +# |
| 3 | +# Copyright (c) 2014-2023, ETH Zurich |
| 4 | +# All rights reserved. |
| 5 | +# |
| 6 | +# This file is part of the GT4Py project and the GridTools framework. |
| 7 | +# GT4Py is free software: you can redistribute it and/or modify it under |
| 8 | +# the terms of the GNU General Public License as published by the |
| 9 | +# Free Software Foundation, either version 3 of the License, or any later |
| 10 | +# version. See the LICENSE.txt file at the top-level directory of this |
| 11 | +# distribution for a copy of the license or check <https://www.gnu.org/licenses/>. |
| 12 | +# |
| 13 | +# SPDX-License-Identifier: GPL-3.0-or-later |
| 14 | + |
| 15 | +import functools |
| 16 | + |
| 17 | +import factory |
| 18 | + |
| 19 | +import gt4py._core.definitions as core_defs |
| 20 | +from gt4py.next import config |
| 21 | +from gt4py.next.otf import recipes, stages |
| 22 | +from gt4py.next.program_processors.runners.dace_iterator.workflow import ( |
| 23 | + DaCeCompilationStepFactory, |
| 24 | + DaCeTranslationStepFactory, |
| 25 | + convert_args, |
| 26 | +) |
| 27 | +from gt4py.next.program_processors.runners.gtfn import GTFNBackendFactory |
| 28 | + |
| 29 | + |
| 30 | +def _no_bindings(inp: stages.ProgramSource) -> stages.CompilableSource: |
| 31 | + return stages.CompilableSource(program_source=inp, binding_source=None) |
| 32 | + |
| 33 | + |
| 34 | +class DaCeWorkflowFactory(factory.Factory): |
| 35 | + class Meta: |
| 36 | + model = recipes.OTFCompileWorkflow |
| 37 | + |
| 38 | + class Params: |
| 39 | + device_type: core_defs.DeviceType = core_defs.DeviceType.CPU |
| 40 | + cmake_build_type: config.CMakeBuildType = factory.LazyFunction( |
| 41 | + lambda: config.CMAKE_BUILD_TYPE |
| 42 | + ) |
| 43 | + use_field_canonical_representation: bool = False |
| 44 | + |
| 45 | + translation = factory.SubFactory( |
| 46 | + DaCeTranslationStepFactory, |
| 47 | + device_type=factory.SelfAttribute("..device_type"), |
| 48 | + use_field_canonical_representation=factory.SelfAttribute( |
| 49 | + "..use_field_canonical_representation" |
| 50 | + ), |
| 51 | + ) |
| 52 | + bindings = _no_bindings |
| 53 | + compilation = factory.SubFactory( |
| 54 | + DaCeCompilationStepFactory, |
| 55 | + cache_lifetime=factory.LazyFunction(lambda: config.BUILD_CACHE_LIFETIME), |
| 56 | + cmake_build_type=factory.SelfAttribute("..cmake_build_type"), |
| 57 | + ) |
| 58 | + decoration = factory.LazyAttribute( |
| 59 | + lambda o: functools.partial( |
| 60 | + convert_args, |
| 61 | + device=o.device_type, |
| 62 | + use_field_canonical_representation=o.use_field_canonical_representation, |
| 63 | + ) |
| 64 | + ) |
| 65 | + |
| 66 | + |
| 67 | +class DaCeBackendFactory(GTFNBackendFactory): |
| 68 | + class Params: |
| 69 | + otf_workflow = factory.SubFactory( |
| 70 | + DaCeWorkflowFactory, |
| 71 | + device_type=factory.SelfAttribute("..device_type"), |
| 72 | + use_field_canonical_representation=factory.SelfAttribute( |
| 73 | + "..use_field_canonical_representation" |
| 74 | + ), |
| 75 | + ) |
| 76 | + name = factory.LazyAttribute( |
| 77 | + lambda o: f"run_dace_{o.name_device}{o.name_temps}{o.name_cached}{o.name_postfix}" |
| 78 | + ) |
| 79 | + auto_optimize = factory.Trait( |
| 80 | + otf_workflow__translation__auto_optimize=True, |
| 81 | + name_temps="_opt", |
| 82 | + ) |
| 83 | + use_field_canonical_representation: bool = False |
| 84 | + |
| 85 | + |
| 86 | +run_dace_cpu = DaCeBackendFactory(cached=True, auto_optimize=True) |
| 87 | + |
| 88 | +run_dace_gpu = DaCeBackendFactory(gpu=True, cached=True, auto_optimize=True) |
0 commit comments