Exemplo n.º 1
0
    def freeze(self: "DaCeStencilObject", *, origin: Dict[str, Tuple[int,
                                                                     ...]],
               domain: Tuple[int, ...]) -> DaCeFrozenStencil:

        key = DaCeStencilObject._get_domain_origin_key(domain, origin)
        if key in self._frozen_cache:
            return self._frozen_cache[key]

        frozen_hash = shash(origin, domain)

        # check if same sdfg already cached on disk
        basename = os.path.splitext(self.SDFG_PATH)[0]
        filename = basename + "_" + str(frozen_hash) + ".sdfg"
        try:
            frozen_sdfg = dace.SDFG.from_file(filename)
        except FileNotFoundError:
            # otherwise, wrap and save sdfg from scratch
            inner_sdfg = self.sdfg()

            frozen_sdfg = self._sdfg_freeze_domain_and_origin(
                inner_sdfg, domain, origin)
            frozen_sdfg.save(filename)

        self._frozen_cache[key] = DaCeFrozenStencil(self, origin, domain,
                                                    frozen_sdfg)
        return self._frozen_cache[key]
Exemplo n.º 2
0
    def is_cache_info_available_and_consistent(
        self, *, validate_hash: bool, catch_exceptions: bool = True
    ) -> bool:
        result = True
        if not self.cache_info_path and catch_exceptions:
            return False
        try:
            cache_info = self.generate_cache_info()
            cache_info_ns = types.SimpleNamespace(**cache_info)
            validate_extra = {
                k: v
                for k, v in self.builder.backend.extra_cache_info.items()
                if k in self.builder.backend.extra_cache_validation_keys
            }
            source = self.builder.module_path.read_text()
            module_shash = gt_utils.shash(source)

            if validate_hash:
                result = (
                    cache_info_ns.backend == self.builder.backend.name
                    and cache_info_ns.stencil_name == self.stencil_id.qualified_name
                    and cache_info_ns.stencil_version == self.stencil_id.version
                    and cache_info_ns.module_shash == module_shash
                )
                if validate_extra:
                    result &= all(
                        [cache_info[key] == validate_extra[key] for key in validate_extra]
                    )
        except Exception as err:
            if not catch_exceptions:
                raise err
            result = False

        return result
Exemplo n.º 3
0
Arquivo: base.py Projeto: twicki/gt4py
    def validate_cache_info(
        cls,
        stencil_id: gt_definitions.StencilID,
        cache_info: Dict[str, Any],
        *,
        validate_hash: bool = True,
    ) -> bool:

        result = True
        try:
            cache_info = types.SimpleNamespace(**cache_info)

            module_file_name = cls.get_stencil_module_path(stencil_id)
            with open(module_file_name, "r") as f:
                source = f.read()
            module_shash = gt_utils.shash(source)

            if validate_hash:
                result = (cache_info.backend == cls.name and
                          cache_info.stencil_name == stencil_id.qualified_name
                          and cache_info.stencil_version == stencil_id.version
                          and cache_info.module_shash == module_shash)

        except Exception:
            result = False

        return result
Exemplo n.º 4
0
 def generate_cache_info(self) -> Dict[str, Any]:
     return {
         "backend": self.builder.backend.name,
         "stencil_name": self.builder.stencil_id.qualified_name,
         "stencil_version": self.builder.stencil_id.version,
         "module_shash": gt_utils.shash(self.builder.stencil_source),
         **self.builder.backend.extra_cache_info,
     }
Exemplo n.º 5
0
    def generate_cache_info(cls, stencil_id, extra_cache_info):
        module_file_name = cls.get_stencil_module_path(stencil_id)
        with open(module_file_name, "r") as f:
            source = f.read()
        cache_info = {
            # "gt4py_version": 0.5,
            "backend": cls.name,
            "stencil_name": stencil_id.qualified_name,
            "stencil_version": stencil_id.version,
            "module_shash": gt_utils.shash(source),
            **extra_cache_info,
        }

        return cache_info
Exemplo n.º 6
0
    def validate_cache_info(cls, stencil_id, cache_info):
        try:
            cache_info = types.SimpleNamespace(**cache_info)

            module_file_name = cls.get_stencil_module_path(stencil_id)
            with open(module_file_name, "r") as f:
                source = f.read()
            module_shash = gt_utils.shash(source)

            result = (cache_info.backend == cls.name
                      and cache_info.stencil_name == stencil_id.qualified_name
                      and cache_info.stencil_version == stencil_id.version
                      and cache_info.module_shash == module_shash)

        except Exception:
            result = False

        return result