Skip to content
Snippets Groups Projects
Select Git revision
  • 95907f7b31fd890456a888ec7af0f4699a1fddbe
  • master default protected
  • v2.0-dev protected
  • zikeliml/Task-96-dotExporterForAST
  • zikeliml/124-rework-tutorials
  • fma
  • fhennig/v2.0-deprecations
  • holzer-master-patch-46757
  • 66-absolute-access-is-probably-not-copied-correctly-after-_eval_subs
  • gpu_bufferfield_fix
  • hyteg
  • vectorization_sqrt_fix
  • target_dh_refactoring
  • const_fix
  • improved_comm
  • gpu_liveness_opts
  • release/1.3.7 protected
  • release/1.3.6 protected
  • release/2.0.dev0 protected
  • release/1.3.5 protected
  • release/1.3.4 protected
  • release/1.3.3 protected
  • release/1.3.2 protected
  • release/1.3.1 protected
  • release/1.3 protected
  • release/1.2 protected
  • release/1.1.1 protected
  • release/1.1 protected
  • release/1.0.1 protected
  • release/1.0 protected
  • release/0.4.4 protected
  • last/Kerncraft
  • last/OpenCL
  • last/LLVM
  • release/0.4.3 protected
  • release/0.4.2 protected
36 results

foreign_ast.py

Blame
  • Frederik Hennig's avatar
    Frederik Hennig authored
     - Implement GPU index translation for CUDA target
     - Expose CUDA code generation through `create_kernel`
     - enable CUDA kernel printing
    95907f7b
    History
    foreign_ast.py 1.49 KiB
    from __future__ import annotations
    from typing import Iterable
    from abc import ABC, abstractmethod
    
    from pystencils.backend.ast.astnode import PsAstNode
    
    from ..ast.expressions import PsExpression
    from ..ast.util import failing_cast
    from ...types import PsType
    
    
    class PsForeignExpression(PsExpression, ABC):
        """Base class for foreign expressions.
    
        Foreign expressions are expressions whose properties are not modelled by the pystencils AST,
        and which pystencils therefore does not understand.
    
        There are many situations where non-supported expressions are needed;
        the most common use case is C++ syntax.
        Support for foreign expressions by the code generator is therefore very limited;
        as a rule of thumb, only printing is supported.
        Type checking and most transformations will fail when encountering a `PsForeignExpression`.
        """
    
        __match_args__ = ("children",)
    
        def __init__(self, children: Iterable[PsExpression], dtype: PsType | None = None):
            self._children = list(children)
            super().__init__(dtype)
    
        @abstractmethod
        def get_code(self, children_code: Iterable[str]) -> str:
            """Print this expression, with the given code for each of its children."""
            pass
    
        def get_children(self) -> tuple[PsAstNode, ...]:
            return tuple(self._children)
    
        def set_child(self, idx: int, c: PsAstNode):
            self._children[idx] = failing_cast(PsExpression, c)
    
        def __repr__(self) -> str:
            return f"{type(self)}({self._children})"